playMaker

Author Topic: PlayerPrefs X - Why does a saved Global GameObject resets in LoadLevel  (Read 107 times)

MlleBun

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
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.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 6003
    • View Profile
    • jinxtergames
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.

MlleBun

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
@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) ?
« Last Edit: March 08, 2021, 03:57:51 PM by MlleBun »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 6003
    • View Profile
    • jinxtergames
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)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.