Can I use PrefabUtility.InstantiatePrefab inside OnValidate method in Editor-mode?

Although it works I’m getting the following warning in the console:
SendMessage cannot be called during Awake, CheckConsistency, or OnValidate

What is it warning about?

@Develax
OnValidate is really only intended for you to check that properties on your object are correctly set up. You can check that references to other objects are OK but you should not access other objects as they might not have had Awake called.

And you should never create new objects or destroy objects in OnValidate. You can instead set a flag that something need to be done and do it in Start or the first Update.

2 Likes