My objects I want to save are simple prefabs (just a single object no children).
So take a Rusty Pipe (weapon), I want to save the active or deactive state of it. I also use Easy Pooling so I just send it back to the pool manager and it deactivates it. OnDisable I save the state and that works, yay I can change scenes and no more duplicates.
NOW the issue is, when I drop the object from inventory, it spawns a new one from a resources prefab(pool manager uses it) and this is always the same GUID but I have multiple pipes throughout the level so each one would end with the same if I picked it up and dropped it (at start they are all different). I attempted to generate a new GUID and I think I succeeded in that but not sure if it will always create a new one each time the scene loads or not since I am having issues loading the saved transform.position.
Also not sure why but the save transform always sets it to 0,0,0 onEnable even though it is not.
This screen shot is taken the moment I hit DROP from my inventory and the new clone is created.
(Also not sure but it does not show that object is active, just the transform since there is a new GUID on the clone one)
So in essence, I want to save each objects on/off state and position/rotation for scene changing
Do not laugh at my code! haha, it is not my strong suit but I am trying!
Code: Select all
public string guid = Guid.NewGuid().ToString();
static bool isApplicationQuitting = false;
private static bool uidIssued;
void Awake()
{
if (!uidIssued)
{
guid = Guid.NewGuid().ToString();
uidIssued = true;
}
gameObject.SetActive(ES3.Load<bool>(guid, enabled));
ES3.Load<Vector3>(guid, transform.localPosition);
}
void OnDisable()
{
if (gameObject.scene.isLoaded && !isApplicationQuitting)
ES3.Save<bool>(guid, false);
}
void OnEnable()
{
if (gameObject.scene.isLoaded && !isApplicationQuitting)
{
ES3.Save<bool>(guid, true);
ES3.Save<Vector3>(guid, transform.localPosition);
}
}
void OnApplicationQuit()
{
isApplicationQuitting = true;
}