- Home /
Is using "OnValidate" the proper way to set references to serialized fields on prefabs?
I'd like to know if writing simple OnValidate()
methods in MonoBehaviour
scripts is the proper way to set up references to serialized fields on something like a prefab.
For example, if I have several serialized fields on a UI prefab, I need to remember to drag references to each field in the inspector before my script can work properly. Obviously it's not difficult to set this up manually, but having to remember all of the references a prefab needs can be annoying. I'm trying to find a better way to have this process be more automated, and I was hoping someone here could give me some advice. As far as I'm aware, one does not want to set up references to serialized fields in Awake()
because it may be slow or unreliable ( Awake()
should be used for syncing up components that exist on the same game object), so it's preferable to use the drag-and-drop method in the inspector.
Is there a way that prefabs can set themselves up in a scene by automatically searching for game objects/components that they can use as references before entering play mode?
Your answer
Follow this Question
Related Questions
Why does the prefabOverride not work on fields marked as SerializeField? 0 Answers
How can I tell what prefabs a child object (script) is in? 2 Answers
Delete prefab in resource folder 0 Answers
Shadows (pro) disappear on Unity restart 0 Answers
Ellen suddenly becoming visible after jumping (3d GameKit) 0 Answers