playMaker

Author Topic: Opposite to "don't destroy on load"? [SOLVED]  (Read 5749 times)

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Opposite to "don't destroy on load"? [SOLVED]
« on: December 12, 2017, 06:23:55 AM »
Hi,

I have a question regarding "Don't destroy on load". If I'm gonna load the same scene as as the one that is active (Like restart level). There are some elements that I want to keep, for instance my Score Board that keeps track of the score.

An issue here is that when I reload the scene my game creates a new score board because there is a FSM that "checks for connected players and create a score board".

Is there like a "Do not create on load" or something? Of should I create a fsm that checks if there already is a scoreboard in the reload and then do not create one if one already exists? 

bye,
Christian
« Last Edit: December 20, 2017, 04:45:03 PM by djaydino »

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: Opposite to "don't destroy on load"?
« Reply #1 on: December 12, 2017, 06:30:20 AM »
Search the ecosystem for the "Singleton" action/manager, i believe this is what you're after.

There should also be some topics on this matter i believe.
« Last Edit: December 12, 2017, 07:12:12 AM by LordHorusNL »

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Opposite to "don't destroy on load"?
« Reply #2 on: December 13, 2017, 02:03:29 AM »
Thanks for this LordHorusNL.
Available for Playmaker work

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Opposite to "don't destroy on load"?
« Reply #3 on: December 13, 2017, 04:19:27 AM »
Thanks for this LordHorusNL.

I get the feeling that you are the creator of this manager? Is there anywhere I can read on more how this thing works?

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Opposite to "don't destroy on load"?
« Reply #4 on: December 13, 2017, 07:29:17 AM »
Okey, I've been googling like a madman now and try to read on how the Singleton work.

I think that I got the basic concept now, and it seems to be pretty straight forward but for some reason I can't get my head around how to use it in practise.

So in my scene, there is a canvas with a scoreboard-panel on it from the start. These are not created through FSM but are on the scene from the very beginning.

The scoreboard checks for players that are online and just list them in the score board, pretty simple.

How when all players are dead there is an option to "Play another round?" and then there is a RPC all that restarts the scene for everyone.

Now I would like the scoreboard to stay intact and not be created again in the load. How should I go to make this happen?

If I only use the "don't destroy on load" the first scoreboard carries over to the next round but there one that is in the scene from the beginning creates again.

I guess that I should use the singleton manager in some way, but I can't really understand how.

Please help!

Bye,
Christian

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: Opposite to "don't destroy on load"?
« Reply #5 on: December 13, 2017, 09:52:23 AM »

I get the feeling that you are the creator of this manager? Is there anywhere I can read on more how this thing works?

No not the author, that would be jeanfabre i believe.

I have never used the singleton manager myself, however what i understand is that you need a singleton manager (with a unique reference name) and a don't destroy on load in a Fsm on your scoreboard in every scene.

Offcourse the singleton reference name has to be the same on both scoreboards!

This way if the scoreboard already exists, the scoreboard in the new level gets destroyed and the old one stays in use.

Then you'll have to figure out how to communicate with the old scoreboard in the new level, you would probably want to do this with global events.

I believe that should work, but somebody else would have to confirm this.
« Last Edit: December 13, 2017, 09:55:16 AM by LordHorusNL »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Opposite to "don't destroy on load"?
« Reply #6 on: December 13, 2017, 12:41:44 PM »
Hi.
To communicate would be similar to a prefab, maybe this video can help :


Always try to avoid using globals :)

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Opposite to "don't destroy on load"?
« Reply #7 on: December 14, 2017, 08:54:01 AM »
Hi.
To communicate would be similar to a prefab, maybe this video can help :


Always try to avoid using globals :)

Hi!

Hmm... to be honest, that video did not help me much. I had a hard time following what he was doing, and why. But it was a interesting video that I think I should check again regarding prefabs that have to communicate with scene objects.

However, I still do not know how to use the Singleton manager. There seems to be impossible to get any documentation or explaining on how to use it properly.

I will look into this more tonight and try some different solutions. But do you know if it is possible for my score manager to be in the scene from the start? Or do I need to created is when the player is instantiated? 

Thanks a bunch for your time and help!

LordHorusNL

  • Beta Group
  • Full Member
  • *
  • Posts: 226
Re: Opposite to "don't destroy on load"?
« Reply #8 on: December 14, 2017, 09:08:38 AM »
If you're gonna need the scoreboard in every scene it's best to make it a prefab i'd think, however i cant say if it matters when using this action.

So lets say you make it a prefab! what i've understood from reading the topics is that you just put a Fsm on the scoreboard prefab with a singleton manager action with the name of "ScoreBoard" and right after that a "Dont Destroy On Load" action.

So now both scoreboards in both levels have the same reference, so when the new level loads the scoreboard from the old level should remain active and the one in the newly loaded level should be destroyed.

If that does not work, maybe jeanfabre can enlighten us, i'd like to know myself.


Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Opposite to "don't destroy on load"?
« Reply #9 on: December 16, 2017, 07:10:42 AM »
If you're gonna need the scoreboard in every scene it's best to make it a prefab i'd think, however i cant say if it matters when using this action.

So lets say you make it a prefab! what i've understood from reading the topics is that you just put a Fsm on the scoreboard prefab with a singleton manager action with the name of "ScoreBoard" and right after that a "Dont Destroy On Load" action.

So now both scoreboards in both levels have the same reference, so when the new level loads the scoreboard from the old level should remain active and the one in the newly loaded level should be destroyed.

If that does not work, maybe jeanfabre can enlighten us, i'd like to know myself.

Alright I tried that one. That was my though as well, but I can't get it to work. Another thing is that every time the scoreboard gets activated (some checks at the scoreboard) it get's destroyed. It's like Unity treat active game object and create object the same in this instance.

Is there a way to tag Jean so he can see this thread?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Opposite to "don't destroy on load"?
« Reply #10 on: December 18, 2017, 02:13:38 AM »
Hi,

 ok, I'll come up with a sample showing singleton usage across scenes. Please ping me end of this week if I haven't published it yet :)

Bye,

 Jean

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Opposite to "don't destroy on load"?
« Reply #11 on: December 18, 2017, 05:12:35 AM »
Hi,

 ok, I'll come up with a sample showing singleton usage across scenes. Please ping me end of this week if I haven't published it yet :)

Bye,

 Jean

Sure, Where are you gonna publish it? Like, where should I look for it?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Opposite to "don't destroy on load"?
« Reply #12 on: December 18, 2017, 05:15:05 AM »
Hi.
Jeans samples are usually available on the Ecosystem,
but he will probably also post here when he made the sample :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Opposite to "don't destroy on load"?
« Reply #13 on: December 20, 2017, 02:30:15 AM »
Hi,

 ok, I understand where is the problem as I am going through your thread.

 if you disable the singleton GameObject, that is a problem indeed, because when you run the Fsm Again the singleton action will kick in and destroy itself because it thinks that singleton reference is already up.

the solution is very simple:

1: on your fsm with the singleton action, move to an empty state on finish.
2: uncheck that fsm "Reset on Disable"

now the fsm responsible for enforcing the singleton, only go through the state with the singletonManager once, you can disable and enable, that fsm is not going to restart.

 Let me know if this is ok as a solution for you.

bye,

 Jean

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: Opposite to "don't destroy on load"?
« Reply #14 on: December 20, 2017, 08:34:31 AM »
Hi,

 ok, I understand where is the problem as I am going through your thread.

 if you disable the singleton GameObject, that is a problem indeed, because when you run the Fsm Again the singleton action will kick in and destroy itself because it thinks that singleton reference is already up.

the solution is very simple:

1: on your fsm with the singleton action, move to an empty state on finish.
2: uncheck that fsm "Reset on Disable"

now the fsm responsible for enforcing the singleton, only go through the state with the singletonManager once, you can disable and enable, that fsm is not going to restart.

 Let me know if this is ok as a solution for you.

bye,

 Jean

Hi Jean!

Yes this was the issue. When I activated the gameobject it got deleted. I did as you said above and it worked like a charm. Thanks for the help!