This is really two questions in one, but very closely related.
I’ve been combing the Unity docs and various sites trying to find a method of running a script at design time either when the user adds a prefab into the scene or duplicates an existing prefab in the scene. I only need the script to run when the object comes into existence in the scene, not when it is loaded or instantiated by loading the scene or running the game.
The best I’ve come up with so far is to do something like the following:
[ExecuteInEditMode]
public class CreationResponder : MonoBehaviour
{
public string creationGuid;
void Awake()
{
// If a GUID hasn't been assigned in the editor yet, generate a unique
// identifier for this object to be stored in the central system.
if (Application.isEditor && creationGuid == string.Empty)
{
creationGuid = Guid.NewGuid().ToString();
}
}
}
I would love to hear that I missed something easy.