Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: misterjuly on July 28, 2021, 11:50:15 AM

Title: How to have a game object destroyed when I reload a scene
Post by: misterjuly on July 28, 2021, 11:50:15 AM
Hello,

I have a collectible you collect in scene 1 (it does disappear when I collect it). You then go through a door to scene 2. You then do something and go back to scene 1. However, the already collected collectible reappears even though I told it to destroy it once the player came in contact with it. How do I get the game to remember I have already collected it even when switching scenes? Thanks!
Title: Re: How to have a game object destroyed when I reload a scene
Post by: Fat Pug Studio on July 28, 2021, 12:11:03 PM
How are you loading scenes, additively or as a single scene?
Title: Re: How to have a game object destroyed when I reload a scene
Post by: misterjuly on July 28, 2021, 12:14:29 PM
Im not entirely sure what you mean. I use the load level action to load the level if that helps... I think there is only one scene loaded at a time. Hopefully that gives you more info on how to help me. Thanks!
Title: Re: How to have a game object destroyed when I reload a scene
Post by: Fat Pug Studio on July 28, 2021, 01:18:36 PM
When you are loading a new scene non-additively, the old scene is not being kept in memory, it's destroyed. If you load a new scene additively, old scene remains in memory. Of course, if you're not managing it properly, you'll fill up the memory and cause a crash.

So, either loading scenes additively with smart memory management (depends entirely on the game) or loading them single (but destroying the old scene) and using save system (player prefs, easy save, smooth save, whatevever) to store data what has been collected or not.

No third option i'm afraid.
Title: Re: How to have a game object destroyed when I reload a scene
Post by: misterjuly on July 28, 2021, 09:19:47 PM
So I have smooth save and I want to have the game remember that I collected the object without loading multiple scenes. Do I have the game object as a variable (if so how do I do that). Thanks!
Title: Re: How to have a game object destroyed when I reload a scene
Post by: Fat Pug Studio on July 29, 2021, 08:07:05 AM
I never used smooth save, but i suppose it works the same as playerprefs in that regard. Let's say you have a coin as a pickup. You set a prefs key for it, for example "Coin1PickedUp". It would be a bool, with a default value false. When you pick it up, you will write the value true to that prefs. Mext time you load a scene, before it's created, the coin will get the prefs and bool test it, if it's true, it will get destroyed (or not spawned if you use a spawner for it) if it's false, it will be created or it's renderer enabled or howevwr you want to organize it, but for performance i propose creating spawners instead of coins that will spawn the coins or not depending on the prefs.

If your game starts anew when you quit, reset thise prefs to default before quitting.
Title: Re: How to have a game object destroyed when I reload a scene
Post by: misterjuly on July 30, 2021, 08:12:46 PM
I think I figured it out. Thanks SO MUCH for your help!
Title: Re: How to have a game object destroyed when I reload a scene
Post by: Fat Pug Studio on August 02, 2021, 01:40:40 PM
Glad to help, shout if you get stuck somewhere, it can be a bit complicated sometimes.