Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: nFighter on February 24, 2020, 09:55:46 PM

Title: "Destroy object" too slow
Post by: nFighter on February 24, 2020, 09:55:46 PM
I have two states. In the first state I "Destroy object" (the children object) in the second state I check "Game Object Has Children". And seems like I check for children faster than children really can be destroyed, so I have the response "true". But if I wait for let's say .5 seconds and then check if children exist - I got the correct answer "false".

Is it how Unity suppose to work or something goes wrong?

I tested with "Next Frame" event and it doesn't help. I believe that using "wait 0.5 sec" is the worst solution ever so what should I actually do?
Title: Re: "Destroy object" too slow
Post by: jeanfabre on February 25, 2020, 02:15:39 AM
Hi,

 yes, objects are truly destroyed at the end of the frame, next frame should work actually

https://docs.unity3d.com/ScriptReference/Object.Destroy.html

Quote
Actual object destruction is always delayed until after the current Update loop, but is always done before rendering.

Please, debug your logic once again with the next frame, if that still doesn't work, let me know.

Bye,

 Jean
Title: Re: "Destroy object" too slow
Post by: nFighter on February 25, 2020, 03:41:08 PM
Please, debug your logic once again with the next frame, if that still doesn't work, let me know.

Checked once again, Next Frame didn't help. It just stuck on "NoCharacters?" state if I didn't use wait before.
(https://i.imgur.com/o16N6XH.png)
Title: Re: "Destroy object" too slow
Post by: GonerGames on February 25, 2020, 11:07:15 PM
Couple of options would be:
1. Break apart your destroy object and next frame event into 2 seperate states. This way the destroy object will complete in one state, move to the next state then wait for next frame and finally move to "NoCharacters?" state.

2. Leave all on one state, remove the next frame event. Use a IsGameObject Null check every frame to check if CharacterGO is now null. If true goto "NoCharacters?" state.

Either way this should remove the need for the wait timer.
Title: Re: "Destroy object" too slow
Post by: nFighter on February 26, 2020, 03:29:21 PM
Couple of options would be:
1. Break apart your destroy object and next frame event into 2 seperate states. This way the destroy object will complete in one state, move to the next state then wait for next frame and finally move to "NoCharacters?" state.
Actually, I did it this way from the very beginning. It doesn't work (I believe because of the same reason as Next Frame didn't help)


2. Leave all on one state, remove the next frame event. Use a IsGameObject Null check every frame to check if CharacterGO is now null. If true goto "NoCharacters?" state.
Well, this looks like a good move! Thanks, i'm gonna try!