Is it correct to use ScriptableObject to save an object's state for use in multiple Scenes?

I writing one facebook multiplayer game. When a user starts a game, application records users data. If app change scene I want to have some data (ID, Name, …) recorded in Login Scene.

I have this script - ScriptableObject:

namespace Assets.Scripts
{
    [CreateAssetMenu(menuName = "Player/State")]
    public class PlayerState : ScriptableObject
    {
        // Properties ...
        // [SerializedField] ....
    }
}

When I create asset of this script, I can call it from all scenes.

Is there are a better way to acomplish this?

ScriptableObjects are really for predefined data. You don’t want to use them this way, even if you can.

Check out some tutorials on GameManagers and singletons and keeping things around for longer than one frame. Here’s what I always reach for when doing singletons:

Some super-simple Singleton examples to take and modify:

Simple Unity3D Singleton (no predefined data):

Unity3D Singleton with Prefab used for predefined data:

These are pure-code solutions, do not put anything into any scene, just access it via .Instance!

1 Like

Why not use simply PlayerPrefs here?

These persists if the game ends.

Alternative you could use a static class or static variables to store player data across several scenes:
https://learn.unity.com/tutorial/statics-l#5c8920e7edbc2a0d28f4833c

But these are lost if the game ends.