Is it possible to destroy other instances under "onDestroy"?

0 favourites
  • 6 posts
  • Ashley

    Destroying under "onDestroy" seems to do something special. (preview.js, line 2606)

    if (this.isInClearDeathRow)
        obj_set.values_cache.push(inst);[/code:3tn1hjm1]
    (this.isInClearDeathRow will be true)
    But these pending destroyed would not be processed (not be destroyed really) in r197.
    
    Is it possible to destroy other instances under "onDestroy"?
  • I think it changed with the recent destroy objects optimisation, so it may not be cleaned up in the same call (it's difficult to support that without infinite-recursion edge cases), but it is cleaned up at least once a tick, so they should still be destroyed shortly after.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ashley

    My goal is: ObjectB will be destroyed when objectA is destroyed, under "onDestroy"(preview.js, line 2805) in ObjectA.

    [quote:pzkzjfyp]destroy ObjectA -> "onDestroy" in ObjectA -> destroy ObjectB

    In my study, function "ClearDeathRowForType"(preview.js line 2661) should be called twice for these two types of destroyed objects, in a tick or during many ticks.

    But it only had been called once for ObjectA in this case.

    "cnds.OnDestroyed" (preview.js line 2610) of ObjectB had been fired in this case. It might be a solution that hang "onDestroy" function call after "cnds.OnDestroyed" trigger.

  • Bump.

    Ashley

    Would you please check if "ClearDeathRowForType" ran for each object destroyed.

    I found destroy other instances under "onDestroy" would not fire "ClearDeathRowForType".

    Since this behavior did not been used in official plugins, so it is not a obviously bug.

  • As before, destroying objects in "onDestroy" is difficult to support, since it requires adapting to a recursive/iterative process that isn't guaranteed to terminate. I'd suggest instead adding objects to a "to be destroyed" list in "onDestroy", then after the call finishes destroy the objects in the list.

  • Ashley

    Thanks, I had a workaround by overwrite acts.Destroy -

    pluginProto.onCreate = function ()
    {
    	pluginProto.acts.Destroy = function ()
    	{
    		this.runtime.DestroyInstance(this);
    		// destroy other objects
    	};        
    };[/code:241gk0yl]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)