Search Unity

How to get entity from gameobejct that was converted by ConvertToEntity

Discussion in 'Entity Component System' started by ThreeIce, Aug 16, 2019.

  1. ThreeIce

    ThreeIce

    Joined:
    Aug 15, 2019
    Posts:
    8
    I don't find a method or property to get the entity when I'm using ConvertToEntity.
    Is there a way to get the entity? Or I shouldn't get the entity when I'm using ConvertToEntity?
    Thanks.
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    If using convert and inject, you need to write the entity reference into a MonoBehaviour during conversion. Why do you need this?
     
  3. ThreeIce

    ThreeIce

    Joined:
    Aug 15, 2019
    Posts:
    8
    I use GameObject.Instantiate to create gameobject. Then I want to change the value of a componentdata on it. So I need the entity.
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    You can use

    Code (CSharp):
    1. GameObjectConversionUtility.ConvertGameObjectHierarchy
    it returns the entity.
     
  5. ThreeIce

    ThreeIce

    Joined:
    Aug 15, 2019
    Posts:
    8
    Thanks.
    What's the difference between ConvertToEntity and GameObjectConversationUtility.ConvertGameObject?