Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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:
    330
    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:
    128
    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:
    195
    BigRookGames likes this.
  4. yifanchu183

    yifanchu183

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