Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: MlleBun on March 08, 2021, 02:57:07 AM

Title: PlayerPrefs X - Why does a saved Global GameObject resets in LoadLevel
Post by: MlleBun on March 08, 2021, 02:57:07 AM
Hi,

I'm still debugging but I might have a quicker answer from the community ;)

Using Player Prefs X
I'm saving a gameobject by the SaveVariable action when the player is dead. When the player dies, I reload the current scene after a timer. The idea is to save a specific GO on a Global Variable (GameObject) when the death event is triggered and to reuse it when the scene is reloaded
.
Using the asset PlayerPrefsEditor, I can see that the key has been saved. For instance, the value of the key is :
Code: [Select]
{"variableName":"startPoint _PLAYER","objectType":"UnityEngine.GameObject","useVariable":true,"type":3,"floatValue":0.0,"intValue":0,"boolValue":false,"stringValue":"","vector4Value":{"x":0.0,"y":0.0,"z":0.0,"w":0.0},"objectReference":{"instanceID":27526},"arrayValue":{"useVariable":false,"name":"","tooltip":"","showInInspector":false,"networkSync":false,"type":-1,"objectTypeName":"","floatValues":[],"intValues":[],"boolValues":[],"stringValues":[],"vector4Values":[],"objectReferences":[]}}
A couple of breakpoints shows that the GO is saved properly on my Global Variable, but when the level is reloaded, it resets back to None even though I use a LoadVariable action at the start of the level.

Any idea why ?
Many thanks !

Just a precision - I'm using a Global Gameobject because I'm setting its value (onReloadScene) in another FSMs.
Title: Re: PlayerPrefs X - Why does a saved Global GameObject resets in LoadLevel
Post by: djaydino on March 08, 2021, 05:34:54 AM
Hi.
if the game object is from that scene and you reload that scene, the gameobject is removed as well.

if these objects are 'check points' you should get the position of the object and save the vector 3, then you can use the vector 3 to position player.
Title: Re: PlayerPrefs X - Why does a saved Global GameObject resets in LoadLevel
Post by: MlleBun on March 08, 2021, 03:51:37 PM
@djaydino Thanks for guiding me! Your post helped me to re-structure my FSMs.

First, I understood that rather than using PlayerPrefsX' Save/Load Variable, it was better for my game to use the simple PlayerPrefs Get/Set actions and for that, I decided to use Get/Set string. The StartingPoint is in fact a position, but I decided to find this vector by getting and saving it's gameObject's name (Get string and save/load it as a key). After a bunch of getting and setting the string and FindGameobject action by name, it works perfect for what I'm doing. I'll clean/optimise this during refacto.

Could you tell me what you meant by "checkpoints" ? Are those actions or real checkpoints (english-speaking) ?
Title: Re: PlayerPrefs X - Why does a saved Global GameObject resets in LoadLevel
Post by: djaydino on March 08, 2021, 04:39:17 PM
hi.
I was just guessing what you where saving the object for :)

Btw if you don't need to save this when quitting the game, you can also make a Game object and then add a fsm and add a singleton (Ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181))action and a Don't Destroy on load

Then set the gameobject on a global variable.
Now you can add For example a fsm called 'Data'
on that fsm you can set a string variable where you can 'get/set' the value by using Get/Set Fsm String.