Unity is autoadding orphaned GameObjects to script's parent,Script is automatically adding GameObjects to parent transform
Got an odd issue:
Whenever I create a GameObject anywhere in my code, and don't set a parent by the time MonoBehavior:Start() returns, Unity automatically adds the orphaned GameObject to the GameObject the script is assigned to.
How can I prevent Unity from autoadding orphaned GameObjects?,Got an odd issue:
Whenever I create a game object anywhere in any of my files, if it's not added to a parent object, when the MonoBehavior::Start() function returns, the orphaned GameObjects automatically get added to the object the script is tied to.
How do I keep Unity from automatically adding orphaned GameObjects?
How are you adding the gameobjects? If you are using Instantiate, after setting the object to instantiate, you can set an additional parameter of the transform you would like the object to be a child of. 'GameObject myNewObject = Instantiate(objectPrefab, transformOfDesiredParent)' this will instantiate the object as a child of whatever transform you put after the object to be instantiated.
I'm calling the constructor for my runtime built objects (not using prefabs). Also tried with GameObject.CreatePrimative, same issue.
I'm not asking how to add GameObjects to a parent, I'm asking how to keep Unity from auto-adding orphaned objects to the script's parent object.
Your answer
Follow this Question
Related Questions
How to disable a script in another without Public GameObject? 0 Answers
Get and Set only work on public variable? 1 Answer
Can't Add Script "The script needs to derive from MonoBehaviour!" 1 Answer
gameObject.SetActive (false); not working 2 Answers
How to instantiate a game object every time when space key is pressed 2 Answers