Search Unity

Proper way to add entities to LinkedEntityGroup without disrupting normal conversion?

Discussion in 'Entity Component System' started by Bivens32, Sep 29, 2020.

  1. Bivens32

    Bivens32

    Joined:
    Jul 8, 2013
    Posts:
    36
    I have ability data stored in ScriptableObjects. The ability data is converted to entities and I wish to add them to the LinkedEntityGroup buffer without messing up the standard child game objects already being added to it. This seems to work but I'm not sure if it is done correctly.
    Code (CSharp):
    1.  
    2. conversionSystem.DeclareLinkedEntityGroup(this.gameObject);
    3.  
    4. // I would rather use dstManager.GetBuffer here but the buffer is null at this point
    5. // and throws an error
    6. var linkedEntityGroup = dstManager.AddBuffer<LinkedEntityGroup>(entity);
    7. var transforms = transform.GetComponentsInChildren<Transform>();
    8. for (int i = 0; i < transforms.Length; i++)
    9. {
    10.     Entity childEntity = conversionSystem.GetPrimaryEntity(transforms[i].gameObject);
    11.     linkedEntityGroup.Add(childEntity);
    12. }
    13.  
    14. // Adding my ability entities here
    15. for (int i = 0; i < tempAbilityList.Count; i++)
    16.     linkedEntityGroup.Add(tempAbilityList[i].abilityInstance);
    17.  
     
    Last edited: Sep 29, 2020
  2. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    linkedEntityGroup[0] needs to be the Main Entity itself.
    var transforms = transform.GetComponentsInChildren<Transform>();
    should have done that the correct way.
     
  3. Bivens32

    Bivens32

    Joined:
    Jul 8, 2013
    Posts:
    36
    Okay cool. It seems to be working fine now. I just didn't know if that would mess up whichever system normally creates the LinkedEntityGroup.