playMaker

Author Topic: Quick question - Is there an Event for 'OnEnable' of a GameObject?  (Read 39 times)

Kathar

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Just a quicky, I was wondering if there was some kind of event that gets triggered when a GameObject is enabled/disabled? I realise there's the Reset on Disable checkbox, but unfortunately I don't want the entire script to reset as I set up some variables in the FSM on its first load. These values are constantly changing also, so I can't allow it to set these variables each time it activates - I want the script to retain the original values, and I don't really want the variables to be Global. I just want to trigger an event within the FSM every time the GameObject is 'activated' again.

I have got this working by having a second FSM which is set to Reset on Disable, and basically sends an event to the first FSM each time it's activated, but it feels a bit messy, just wondered if there was a nicer/cleaner way? Thanks for any help!

LordHorusNL

  • Full Member
  • ***
  • Posts: 103
    • View Profile
Re: Quick question - Is there an Event for 'OnEnable' of a GameObject?
« Reply #1 on: January 20, 2018, 07:24:46 AM »
You could set all the variables you want when the FSM is first loaded and just bypass that state on any other reset/enable.

Thats what i do with all my FSM's

Something like this



And just keep reset on disable checked.

There is no event that gets triggered on enable/disable but you could just use the above and move right into what you want your FSM to do.

Hope that helps

Kathar

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Quick question - Is there an Event for 'OnEnable' of a GameObject?
« Reply #2 on: January 20, 2018, 04:38:13 PM »
You could set all the variables you want when the FSM is first loaded and just bypass that state on any other reset/enable.

Thats what i do with all my FSM's

Something like this



And just keep reset on disable checked.

There is no event that gets triggered on enable/disable but you could just use the above and move right into what you want your FSM to do.

Hope that helps
That's fantastic, thanks mate! I just assumed all vars were reset as well when reset on disable was checked - that's really useful to know, will definitely be using your method now, so much cleaner, thanks again!

LordHorusNL

  • Full Member
  • ***
  • Posts: 103
    • View Profile
Re: Quick question - Is there an Event for 'OnEnable' of a GameObject?
« Reply #3 on: January 20, 2018, 04:53:32 PM »
Nope variables will never change even with reset on disable checked, unless you change them yourself!

Reset on disable simply means that when unchecked and the FSM is reset it will stay on the same state and not begin again from the "START" state.

Glad to help.

Kathar

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Nope variables will never change even with reset on disable checked, unless you change them yourself!

Reset on disable simply means that when unchecked and the FSM is reset it will stay on the same state and not begin again from the "START" state.

Glad to help.

Really good to know, this has opened up so many cool ideas for me, thanks again mate!