playMaker

Author Topic: Needed, a " If I already exist, do not activate" action... thingy  (Read 2921 times)

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Needed, a " If I already exist, do not activate" action... thingy
« on: September 02, 2013, 06:48:25 AM »
I have a Game Object that needs to not be destroyed when we load a new scene, this works, (Do not destroy on load) but when I come BACK to that scene (coming from exterior, thru a door, to an interior, then back thru a door to the exterior again) the object, which was first spawned here, reloads again, so now there are 2! If I keep doing this, there will be 1 more every time!

How can I stop this, is there a "if I already exist do not load me" kind of thing?

MArk

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Needed, a " If I already exist, do not activate" action... thingy
« Reply #1 on: September 05, 2013, 03:49:59 AM »
Still wondering how to do this...
 ;)

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: Needed, a " If I already exist, do not activate" action... thingy
« Reply #2 on: September 05, 2013, 11:49:24 AM »
I found some general advice on handling this in Unity:
https://www.google.com/search?q=unity+don't+destroy+on+load+duplicate

One strategy seems to be having a setup scene that loads all persistent objects that you only load once.

Or you could spawn the object from a prefab instead of saving it in the scene.

Or check if there are duplicates. Maybe give it a tag and use Get Tag Count, then Find Game Object to delete duplicates.

There doesn't seem to be one preferred way to do this. It depends on your design...

Hope this helps!

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Needed, a " If I already exist, do not activate" action... thingy
« Reply #3 on: September 06, 2013, 03:53:39 AM »
I found some general advice on handling this in Unity:
https://www.google.com/search?q=unity+don't+destroy+on+load+duplicate


Will read...

Quote
One strategy seems to be having a setup scene that loads all persistent objects that you only load once.


I dont really want to do this, but maybe. I will be implementing a kind of intro scene, so that might be the place to do it (as I write Im am beginning to see the simplicity of this) have to think...

Quote
Or you could spawn the object from a prefab instead of saving it in the scene.

Now this, sounds promising, but Im not really understanding. If the prefab is spawned into a scene, then it will also be spawned on RE-entering that scene?


Quote
Or check if there are duplicates. Maybe give it a tag and use Get Tag Count, then Find Game Object to delete duplicates.

Yes, this also seems do-able, I just havent really used tags much..

Quote
There doesn't seem to be one preferred way to do this. It depends on your design...


Maybe a global variable? And some FSM on the non-destroyed object itself that, before anything else, checks the status of that variable, and if its true, destroys itself?

I really like it when Game Objects handle things on their own, and are not dependant on loads of other things that I might forget.


Quote

Hope this helps!

Yes... very!



MArk