playMaker

Author Topic: Preventing Duplicating when using "Dont Destroy on Load"  (Read 1801 times)

Mayhem

  • Full Member
  • ***
  • Posts: 171
    • View Profile
Preventing Duplicating when using "Dont Destroy on Load"
« on: April 17, 2013, 03:01:36 PM »
Hey there.

So, here's the setup:

In the first Scene/Level 1 i created an empty GameObject with an FSM, lets call it "Manager".

1. The FSM hat so far only the START-State with only one action: "Dont Destroy on Load"

2. In the Scene is a Trigger-Cube which loads Scene 2/Level 2

3. In Level 2 there is also a Trigger-Cube which loads Scene 1/ Level One again.

So, when i start the game this happens in the Hierarchy:

- first i am in Level 1 moving to the Trigger, it loads Level 2
-> the Manager isn't destroyed! It's there in Level 2.
- now, when i move to the Trigger-Cube of Level 2 which will load Level 1 again this happens: I have two Manager-Gameobjects!

If I go again to the Trigger-Cube which will load Level 2, i have still these two Objects, back to Level 1, there are three "Manager"-Objects now and so on.

How could i prevent that? I just want to have only ONE Manager there.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15459
  • Official Playmaker Support
    • View Profile
Re: Preventing Duplicating when using "Dont Destroy on Load"
« Reply #1 on: April 18, 2013, 02:02:25 AM »
Hi,

 you check on START and maintain a global variable bool like "Manager mounted" and you set it to true if it's false, or destroy yourself is true.

bye,

 Jean