Search Unity

Hybrid ECS DataProxies not updating

Discussion in 'Entity Component System' started by FrankvHoof, Apr 2, 2019.

  1. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    I have a system set up which checks if objects are in view of the camera.
    This writes data to a IsVisible-Component (IComponentData with a ComponentDataWrapper-class for Hybrid).
    However, my ComponentDataWrapper-class (yes, I'm on a somewhat older version of ECS) does not get updated until I actually select the GameObject in the hierarchy.
    Do I need another system to update my DataWrapper-Instances?
    If so, how would I go about doing that?

    Edit:
    World.Active.GetOrCreateManager<EntityManager>().GetComponentData<IsVisible>(GetComponent<GameObjectEntity>().Entity).Value does actually seem to give the proper value..
    So it's just the proxy.
     
    Last edited: Apr 2, 2019
    TakuanDaikon likes this.
  2. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    Bump, still looking for anyone who can help me find an answer to this, as GetComponentData is VERY slow (nearly 1 ms for about 80 entities)
     
  3. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    Having just updated all of my packages to the latest versions, I can confirm this still happens on the latest versions..
    For some reason the "IsVisibleComponent"-Value (the actual IComponentData) does not Update (as far as the dataproxy is concerned) unless I select the GameObject in the Hierarchy.

    Visual:
    (Green Line is forward of Camera, Spheres are the Objects that are supposed to turn on (switch state, not enable/disable) when viewed)
    Enabling
    https://gyazo.com/f997d16bd4644449d25427b10441c597
    Disabling
    https://gyazo.com/69f8c9b8aa3a47d4618c47b596ffc0f0

    Using:
    Unity 2018.3.6f1
    Packages:
    - Burst 1.0.0-preview.9
    - Collections 0.0.9-preview.12
    - Entities 0.0.12-preview.24-timestampfix
    - Hybrid Renderer 0.0.1-preview.4
    - Jobs 0.0.7-preview.6
    - Mathematics 1.0.0-preview.1
     
    TakuanDaikon likes this.
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    It's not latest. Latest it's 0.0.12 - preview.29. Don't believe package manager about 0.0.12-preview.24-timestampfix.
     
  5. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    I remember this issue from months ago but very old now.
    There's no point using old packages as stuff changes constantly and things get fixed/deprecated.
    I think wrapper and GameObjectEntity are going.
     
  6. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    Preview.24 is the highest version that shows up on Unity 2018.3 (I think the higher ones depend on Unity 2019)

    Wrapper is already gone (renamed to ComponentDataProxy).
    GameObjectEntity is the basis for the Hybrid system, so I don't think that'll be getting removed anytime soon.
     
  7. elcionap

    elcionap

    Joined:
    Jan 11, 2016
    Posts:
    138
    Yes, any update beyond preview-24 requires Unity 2019.1.

    It wasn't deprecated (yet?) but is discouraged:
    https://forum.unity.com/threads/new-subscene-converttoentity-workflows.638785/

    []'s
     
  8. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Yeah sorry, I meant proxy which is the same thing. It was just a rename of wrapper.
    I think even GameObjectEntity is going too because it conflicts with new 'Convert To Entity' component.
    There's new IConvertGameObjectToEntity but I'm still a bit confused on it all as there doesn't seem to be any new hybrid components using it like 'Copy Transform To Game Object'.
     
  9. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    yeah that just converts gameobjects to entities.. Basically ripping out any form of Hybrid, and moving to Pure..
    Still doesn't help me with the proxy not updating :(
    For some reason it does update if it's selected in the hierarchy (and showing values in the inspector), so it is able to update it, but doesn't do it by default?
     
  10. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Oh I missed this line :)

     
  11. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    I'm not sure this is true. I can still access my SpriteRenderer on a 'Convert To Entity' GameObject from a ComponentSystem.
    That's why I'm not sure what's happening with GameObjectEntity. It's only there to work with ComponentDataProxy and as Joachim himself has said, quoted above by elcionap, they want people to stop using that completely.
     
  12. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    So then how would one get Entity-Data in a Monobehaviour-Context?
    Especially with GetComponentData being as slow as it is..
     
  13. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    That's a good question and I don't know.
    How do you get Translation/Rotation/LocalToWorld components on a GOE when their proxy's are deprecated?
    Hopefully someone smarter can clarify.
     
  14. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    That's kinda why I'm here :p
     
  15. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    lol, I'm just here to add to the confusion. :D
     
  16. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Don't know why I didn't think of this sooner, you can just replicate your own GameObjectEntity.

    Code (CSharp):
    1. public class GameObjectEntity : MonoBehaviour, IConvertGameObjectToEntity
    2. {
    3.     public Entity Entity;
    4.  
    5.     public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    6.     {
    7.         this.Entity = entity;
    8.     }
    9. }
     
  17. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    857
    I was experiencing this earlier and 5argon's reply sums it up
    https://forum.unity.com/threads/am-i-misunderstanding-hybrid.595924/#post-3990079

    I would just make a ComponentSystem to communicate the data from entity to gameobject
     
  18. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    Creating an extra ComponentSystem to get the data out seems a bit overkill to me; I'm only using the entities here to check if my GameObject is in view of a camera (Camera.WorldToViewPortPoint is quite heavy, so I parallelize it for the roughly 80 'chambers' around the player), and thus running a job without any entities would probably perform better..

    Looking at the thread you linked, and @5argon 's reply, could you tell me where I could find OnBeforeSerialize() so I can try calling it manually?

    Edit: Fixed broken Quote-tag
     
  19. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    857
    I never tried that route personally, I just made a system to handle bridging the data
     
  20. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    All the code for this is in ComponentDataProxy and ComponentDataProxyBase in ../Unity.Entities.Hybrid/Components folder.
     
  21. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    It looks like OnBeforeSerialize (in ComponentDataProxyBase) just calls UpdateSerializedData (internal in ComponentDataProxy), which calls EntityManager.GetComponentData().
    So I'm guessing that even I were to be able to get to it (which I'm not, by default), it probably won't be any faster than just straight up calling EntityManager.GetComponentData from my MonoBehaviour
     
  22. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Are you trying to modify components via the proxy?
    The only way to modify components from MonoBehaviours is via the EntityManager just like you were doing in your first post.
    The proxies are just there to add components to the Entity via the Editor/GameObject. It's a one way thing and you don't interact with the Entity via the proxy after that. Not through code anyway.
    I'm pretty sure all the synching in ComponentDataProxy/Base is just so the values get updated in the Inspector for display purposes and to allow you to change them manually in Play mode.
     
  23. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    I'm trying to get the value FROM the Entity INTO my MonoBehaviour (for further processing).
    See above (Enabling / Disabling): When my Sphere (Chamber)-Entity is in view of the Camera, the MonoBehaviour switches state, and starts animating/enabling/etc.