- Home /
GameObjects in a list variable don't show up correct in the hierarchy
For background i am making a space imperium game with planets and fleets. I have a GameObject Fleet that has a FleetScript.boo component. This FleetScript.boo has a
[SerializeField] fleetNumber as int
[SerializeField] startFleetShips as (GameObject) = array(GameObject, fleetNumber)
that i am forced to use since lists don't show up in the inspector and i want to add ships to my GameObjects fleets before game start. So to this startFleetShips array in the inspector i add lightAttackShipPreFabs.
In the Start() function i convert the startFleetShips to a List so i can add and remove ships and use more functions. But when i create GameObjects with the code
fleetShips = [Instantiate(item) for item in startFleetShips ]
these gameObjects appears in the Hierarchy as independent GameObjects instead of children to the Fleet GameObject.
When i do fleet combat it all works, when i destroy a ship the correct ship gameobject dissapears. But it is just that the ship GameObject don't appear visual in the Hierarchy under the Fleet Gameobject which i think it should. And this is a problem becouse it gets visual messy if the ship GameObjects can't stay under their Fleet GameObject in the Hierarchy. With lots of fleets i am gonna have the Hierarchy spammed with ship GameObjects.
Any ideas?
Answer by Waz · Jun 28, 2011 at 01:14 PM
The hierarchy is determined by the parent
of the GameObject's transform
, nothing more. If you want them in a particular structure in the hierarchy, set their parent
accordingly:
ship.transform.parent = fleet.transform
or however that is said in boo.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
C# GameObject Lists 2 Answers
Advice a setup for a character built at runtime 0 Answers
How to add and remove objects from a list when they get destroyed and instantiated 0 Answers
Hierarchy in game view? 0 Answers