Is there a way to edit an uninstantiated object?
I need to be able to summon an exact copy of a set of objects (grouped by a common parent), but quickly adjust them so they can serve their purpose before they get any chance to interact with the world or run Start() in any of the scripts the original objects have.
So, basically, now it looks kinda like this (the code is run in a script attached to one of those objects):
transform copiedParent = Instantiate(commonParent,position,rotation);
foreach (Transform Child in copiedParent)
{
//destroy some children of Child
//destroy colliders and old scripts of Child
//add a script to Child
//only now should the child actually come to life
}
The ideal scenario would be to have a virtual, nonexistent copy of the original common parent (like... creating a short-lived prefab at runtime?), adjust it and then instantiate it, but I don't think it's possible.
Another possibility would be to stop Start() from running in any of the scripts on my copied objects until their adjustment is finished. Colliders being destroyed too late should not be that big of a problem.
Disable them as soon as you instantiate them, edit them and re-enable when ready? Or use a pooling system and have them in your scene all the time if that suits your project structure.
Disabling them won't prevent any scripts already attached to them from running Start(). But I'd love it if you elaborated on the polling system idea.
Just did a quick test, you can also disable the instantiated object before the instantiation. And the new object comes up disabled. Try disabling your commonParent, instantiating from it and then re-enabling the commonParent all in a single frame. That shouldn't be noticeable.
Answer by SarperS · Aug 07, 2016 at 11:13 PM
Actually it does?
private void Start() {
Debug.Log("Testing if Start is called on the instantiated and disabled object", this);
var testObj = Instantiate(gameObject, Vector3.zero, Quaternion.identity) as GameObject;
testObj.SetActive(false);
}
Wow, it indeed does work. I just hope it's consistent and works 100% of the time. Well, tests will tell.
So simple, yet great. Thanks.
Sure, no problem, please mark it as answered
Your answer

Follow this Question
Related Questions
instantiating problem??? 2 Answers
SPACE SHOOTER SHOOTING SHOTS TUTORIAL HELP (UNITY 5 C#) 3 Answers
How to getcomponent on an object instantiated through PUN 0 Answers
Prefab Scripts Not Working After First Spawn? 2 Answers
How can I stop 3 scripts from running when a certain game object appears? 0 Answers