Search Unity

Resolved When I use the ECS system, I encountered a problem that is how to convert from gameobject to Entity?

Discussion in 'Physics for ECS' started by Bob_work, Apr 23, 2021.

  1. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    113
    If I use GameObject I can write like this :
    GameObject gameObject = hitinfo.collider.gameObject;

    //after some operation ......

    then I can write this to get parent object from the "GameObject", i.e. :
    MyObject = gameObject.GetComponentInParent<MyBehaviour>();

    Now I wanna use ECS, so how can I solve this dependency relationships? If ECS has no dependency like original, how can I get my target object from ECS?

    Unity official please answer me, thanks a lot.

    by the way, how to use Raycast(), ScreenPointToRay(), etc, still like original? But they are contain many GameObjects ! How the ECS solve these problems?
    Thanks.
     
  2. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    113
    this example is: fire hit object A (tire),then get object A,and show object A was been hit and show hit effect,then get the parent of object A (tire) which is a Car was broken. I wanna achieve this effect in ECS. So please help me. thanks
     
  3. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    113
    Nobody knows?
     
  4. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    867
  5. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    113
    Thank you for reply.

    What I actually mean is that: I will use at least functions like Raycast() in my game. First of all, it's the parameter "Vector3", ECS recommends using "flaot3" in order to support the new Math library. So when I call the Raycast() function, is the parameter type "Vector3" or "float3"? Is there any ECS version Raycast() function that supports ECS?

    To go a step further, I can write a program like "Physics.Raycast(...)" in order to check whether the target is hit. The important point here is that I can get "hitInfo.collider" from "out RaycastHit hitInfo". And I can get the GameObject it belongs to this collider, then I can do any operations on the hit target object. And all of this is built on the basis of GameObject !

    The key is that I know that ECS is data-oriented, not object-oriented, so ECS does not support GameObject. So how can I use ECS to achieve the functions I described above? Which is I can get the target Entity in the same way. And modify my original program least, but not change my original program's architecture!!!

    I am not very familiar with DOTS, I just know Entity, Job System, Burst Compiler, and some data type changes and the new "Math" library replaces "Mathf". But in the actual project migration process, this problem was encountered at the very beginning. If this similar problem is not solved, I think most of the traditional unity games cannot be migrated to DOTS.

    So Unity official please answer my question. Thanks a lot.
     
    Last edited: Apr 25, 2021
  6. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    867
    yes float3 do something like

    Code (CSharp):
    1.                             RaycastInput raycast = new RaycastInput
    2.                             {
    3.                                 Start = myGuyVis.top,
    4.                                 End = (myGuyVis.top + ((testVisPoints[counter] - myGuyVis.top) * 1.1F)),
    5.                                 Filter = filter1,
    6.                             };
    7.  
    8.                             NativeList<RaycastHit> allHits = new NativeList<RaycastHit>(Allocator.Temp);
    9.  
    10.                             //raycast all because we do not want vehs to block los
    11.                             if (physicsWorld.CastRay(raycast, ref allHits))
     
  7. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    113
    Please tell me, where can I get the complete DOTS reference materials? I only learned some DOTS in a few videos before, but that didn't solve the problems. Thank you very much!
     
  8. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    867
  9. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    113
  10. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    113
    In fact, not only the raycast function (e.g. ConfigurableJoint:Joint:Component, and how solve ConfigurableJoint.Vector3 targetPosition), but all the functions related to GameObject(and Vector3 ...), the Unity official should provide a set of solutions to enable these very useful functions to be implemented in ECS (return Entity). At least the "Unity DOCUMENTATION" must have these contents, and I can't find it now. If anyone knows where can find it, please let me know, thank you!
     
    Last edited: Apr 25, 2021
  11. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    113
    I found some example about ECS physics, like this conversionSystem.World.GetOrCreateSystem<EndJointConversionSystem>().CreateJointEntity( ......
    But unfortunately, I can't find any docs about "GetOrCreateSystem<>" and "CreateJointEntity" etc.
    Is that Untiy doesn't provide documentation for these very new APIs, yet?
    I just wanna know how to change my trandional Joint GameObject code into Entity ECS code?! And how to use these entities like original?
     
  12. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
  13. Bob_work

    Bob_work

    Joined:
    May 5, 2020
    Posts:
    113