Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Scriptable Object won't save values unless selected in Inspector

Discussion in 'Scripting' started by lack_05, Dec 22, 2019.

  1. lack_05

    lack_05

    Joined:
    Feb 20, 2019
    Posts:
    20
    I'm making an RPG. When a player starts a battle I use a scriptable object to save their position on the over world. I hold the value and when the scene transfers back to the over world it moves the player to the position stored in the object. However it won't hold the position unless I have it selected in the inspector.
    I've confirmed it works so is there anyway for me to get it to successfully hold it's position without selecting it in the inspector?
     
  2. Madgvox

    Madgvox

    Joined:
    Apr 13, 2014
    Posts:
    1,317
    Don't use ScriptableObjects like that to save state. You are overwriting an editor asset in the assets folder, not creating persistent save data. This technique will not work in a build. I would suggest you save your world position in a Serializable class using JsonUtility to a file in Application.persistentDataPath.