Scriptable object keeps referencing the objects?

When the serialized object has the following info inside of it:

public class myClass : ScriptableObject{
    SomeClass sC = new SomeClass ();

when we save it as an asset, then retrieve it via AssetDatabase.LoadAssetAtPath, will the variable sC still reference the old object or will it be initialized to reference a new one?


That depends on if the class SomeClass is serializable or not. If the class is a type of MonoBehaviour attached to a GameObject in the scene you will loose the reference once it is saved to file. If the class is another ScriptableObject then that one must also be saved to file to keep the reference (You should also use AssetDatabase.AddObjectToAsset to make it part of the same file).

But if it is just a normal class not inheriting from ScriptableObject or Monobehaviour (which seems likely because you are using NEW on it) then as long as the class has the attribute [System.Serializable] it will be saved with the file. You also need to make the variable sC public or add the attribute [SerializeField] to it.