Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: nFighter on April 14, 2018, 03:36:54 AM

Title: using OnDestroy() from PlayMaker
Post by: nFighter on April 14, 2018, 03:36:54 AM
Is there a way to run some actions/events when the object going to be destroyed?
Similar to the OnDestroy() that can be used from the C#?


I write a Script that send event to fsm
void OnDestroy() { fsm.SendEvent("Die"); }
but unfortunately it does not work. I can send event onUpdate, for example, but can't see a result OnDestroy  :(
Title: Re: using OnDestroy() from PlayMaker
Post by: djaydino on April 14, 2018, 03:08:56 PM
How are the objects destoyed?

with playmaker actions or from other scripts?

if playmaker you could intead of destroying.
send an event (set a global transition for it so it can be called anytime)  do what you need to do then destroy self.

if from script you could prevent destroy and send an event from the script to the fsm and do the same as above.
Title: Re: using OnDestroy() from PlayMaker
Post by: nFighter on April 14, 2018, 04:58:15 PM
It could be destroyed from different scripts, and I actually don't know what scripts exactly and how they working. I'm trying to hook in the complex working system with some playmaker tweaks. I don't have access to the script that actually send destroy event, but I have an object that must be destroyed and I want to make some actions on his death.

For now the only working way for me - checking every frame is object exist or not. Not the optimal way, to be honest  :-[
Title: Re: using OnDestroy() from PlayMaker
Post by: nFighter on April 14, 2018, 05:00:29 PM
Is it some technical restriction with Playmaker to handle a OnDestoy() event?
I found some topics where people discuss it but don't see any simple solution
Title: Re: using OnDestroy() from PlayMaker
Post by: Alex Chouls on April 14, 2018, 09:41:42 PM
There’s no technical restriction, it just hasn’t been exposed to actions yet. I’ll add it in the next update...
Title: Re: using OnDestroy() from PlayMaker
Post by: nFighter on April 14, 2018, 09:50:36 PM
Great to know! Thank you  ;D
Title: Re: using OnDestroy() from PlayMaker
Post by: Alex Chouls on April 15, 2018, 05:53:49 PM
Quick question: Do you specifically need OnDestroy or would an OnDisable event suffice? OnDisable is also called when an object is destroyed. So wondering if it's useful to add both OnDisable and OnDestroy events, or if OnDisable is enough...
Title: Re: using OnDestroy() from PlayMaker
Post by: nFighter on April 15, 2018, 06:28:57 PM
If I understand right, I'll be fine with anything that will help me to catch the dying object. I think that OnDisable is even better  ;D