Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Moving a converted parent entity along with physics enabled children

Discussion in 'Physics for ECS' started by BigRookGames, Oct 27, 2021.

  1. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    328
    I am trying to store an entity prefab that contains multiple children which all take part in the physics simulation (each have Physics Body Authoring and Physics Shape Authoring components) and then instantiate an entity and move the prefab with its children to a specific position.
    When this is normally done, the children are created as separate entities and so moving the instantiated parent object does not move the children.
    I only need the prefab with children to move initially when instantiated. Is there any way to do this and get the parent and all children to move without saving a reference to each of the child objects and moving each one individually?
    For example, with game object instantiation you can define the location when instantiated, but with components, I am not sure if that functionality exists.
    How would this be done? Do I need to add the physics component after creating the entity and moving it to the spawn location?
     
  2. WildMaN

    WildMaN

    Joined:
    Jan 24, 2013
    Posts:
    105
    I had the same task and ended up doing it manually - children are disabled and on prefab instantiation their positions are updated according to the parent's.
     
  3. NT_Ninetails

    NT_Ninetails

    Joined:
    Jan 21, 2018
    Posts:
    190
    BigRookGames likes this.
  4. yifanchu183

    yifanchu183

    Joined:
    Jul 4, 2019
    Posts:
    32
    Is there any more convenient way