Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Convert And Inject GameObject doesn't convert childs

Discussion in 'Data Oriented Technology Stack' started by ExtrysGO, Mar 5, 2020.

  1. ExtrysGO

    ExtrysGO

    Joined:
    Oct 25, 2017
    Posts:
    144
    Convert And Inject Game Object doesnt convert childs right now
    but when you use "Convert And Destroy" all the hyerarchy is converted,
    it should be the same behaviour for "Convert And Inject GameObject"
     
    Xisor, kro11 and Enzi like this.
  2. Xisor

    Xisor

    Joined:
    Jan 30, 2016
    Posts:
    6
    Because of the
    ``` Library/PackageCache/com.unity.entities@0.8.0-preview.8/Unity.Entities.Hybrid/ConvertToEntity.cs ```
    Code (CSharp):
    1. void ConvertToEntitySystem::Convert()
    2. {
    3.     ...
    4.     var remove = parent != null && parent.GetComponentInParent<ConvertToEntity>() != null;
    5.     ....
    6. }
    children entity is removed from the original list, I assume its done because the parent should handle the hierarchy conversion.

    But then when traversing parent hierarchy
    Code (CSharp):
    1.         static void AddRecurse(EntityManager manager, Transform transform, HashSet<Transform> toBeDetached, List<Transform> toBeInjected)
    2.         {
    3.             ...
    4.  
    5.             if (IsConvertAndInject(transform.gameObject))
    6.             {
    7.                 toBeDetached.Add(transform);
    8.                 toBeInjected.Add(transform);
    9.             }
    10.             else // << Why is it under else branch? Looks like a bug, causing inconsistent behaviour
    11.             {
    12.                 foreach (Transform child in transform)
    13.                     AddRecurse(manager, child, toBeDetached, toBeInjected);
    14.             }
    15.         }
    it just skips the hierarchy if the mode is `ConvertAndInjectGameObject`, which looks like a bug. I fixed it locally adding hierarchy unconditionally, however its not a proper fix, because adding a `ConvertToEntity` component to children with Inject mode would also break the hierarchy in the end, causing children to be detached from parents. To fix this you also need to filter them from `toBeDetached` hashSet. Or you can just hack it the same way I did, remember to not use `ConvertToEntity` components in your children and wait for a proper fix.
     
    Last edited: Apr 4, 2020
    ExtrysGO and starikcetin like this.
  3. ExtrysGO

    ExtrysGO

    Joined:
    Oct 25, 2017
    Posts:
    144
    That has more sense now then!
    If it is intentional and not a bug then its good

    thanks a lot for your response
     
  4. Xisor

    Xisor

    Joined:
    Jan 30, 2016
    Posts:
    6
    I think intent was to convert hierarchies with a single parent conversion policy I guess, but implementation of this intent is wrong.
    You can hack it locally changing `Library/PackageCache/com.unity.entities@0.8.0-preview.8/Unity.Entities.Hybrid/ConvertToEntity.cs` to
    Code (CSharp):
    1.         static void AddRecurse(EntityManager manager, Transform transform, HashSet<Transform> toBeDetached, List<Transform> toBeInjected)
    2.         {
    3.             ...
    4.             if (IsConvertAndInject(transform.gameObject))
    5.             {
    6.                 toBeDetached.Add(transform);
    7.                 toBeInjected.Add(transform);
    8.             }
    9.             // << Just remove the else branch
    10.            
    11.                 foreach (Transform child in transform)
    12.                     AddRecurse(manager, child, toBeDetached, toBeInjected);
    13.            
    14.         }
    and that would allow you to convert Injected hierarchies
     
unityunity