- Home /
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?
Thanks!
Answer by GameVortex · Oct 30, 2014 at 08:04 AM
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.
Your answer
Follow this Question
Related Questions
Scriptable object saves but what about objects it references? 0 Answers
Saving UnityEngine.Object into ScriptableObject 1 Answer
Accessing the Variable of an Inherited Scriptable Object 1 Answer
Having a reference to only one variable. 2 Answers
Load ScriptableObject / asset file and save as object to list 1 Answer