- Home /
Duplicating Component with Some Scene References in Serialized Scriptable Object Class Reference
I using custom ScriptableObject class as variable inside my MonoBehaviour script to keep some references from scene (I need serialaztion etc.) I add Light component to my GameObject and add it to ScriptableObject variable in my MonoBehaviour. When I duplicate GameObject with attached my MonoBehaviour, new GameObject's scriptable object's Light variable is referencing to Light from previous GameObject instead of duplicated one. Is there some smart way to make components in scriptable object assign new references when Object is duplicated?
I was checking if defining public Light variable just inside MonoBehaviour or defining it in List is duplicating references correctly and it does.
Probably in duplicated object there are the same ScriptableObjects like in first GameObject, they probably not duplicating too.
Simply use OnEnable to make the gameobject call a function on your script object to set all gameobject-specific variables. I'm surprised the script object is even cloned, so check that it actually is, and that both gameobjects do not simply share a reference to it.
Your answer
Follow this Question
Related Questions
Scriptable Object references if not saved in AssetDatabase? 1 Answer
Drag and drop reference not working? 1 Answer
ScriptableObject reference resetted after a method is finished. 2 Answers
Add lines to a script from another script 0 Answers
Referencing a class defined within a ScriptableObject 0 Answers