- Home /
Instantiate with name that can be used in Awake
I need my instantiated object name to be known to the prefab Awake script. Is there any way to do this. Instantiate does not have a name parameter and using Start is too late since Start runs the next frame.
I think there's some confusion here. Awake not having a parameter doesn't really make sense / matter as you aren't calling that manually anyway and Unity call it with the name you wanted even if it did.
It sounds like your problem is:
1 -- You create something at runtime (your "instantiated object")
2 -- You have a prefab that will be instantiated later which does something in its Awake call relevant to the object from --1--
3 -- You aren't sure how to tell the object from --2-- about the object from --1--
Is this about right and Is there a reason you can't defer this until after its Awake call?
Answer by prof · Nov 19, 2019 at 07:30 PM
Not sure what you are trying to do, but you can set name for new instance like this
var go = Instantiate(prefab);
go.name = "NewName";
Can you explain what are you trying to do? If you need to initilize something, you can do this
go.GetComponent<SomeScript>.InitializeStuff();