Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Can GameObject physics interact with Entity physics?

Discussion in 'Physics' started by Conspiracy, Jan 6, 2020.

  1. Conspiracy

    Conspiracy

    Joined:
    Oct 22, 2016
    Posts:
    40
    I'm very new to this DOTS thing and when I watch talks about it, the developer that's talking always says something about still having gameobjects whilst at the same time implementing entities.

    they say the player can still be a gameObject but if that's so how is the player able to interact with the entities?

    I know there's a convert to entity script but that still means I have to write code for the player as if it was an entity and not a gameObject which will still take a long time. As far as I know, entities and gameObjects don't even use the same physics engine. Entity uses Unity.Physics whilst gameObjects uses UnityEngine so I dont even know how those two things can work together.

    anyway, please help cause I am very frustrated and my head hurts.
     
  2. tgienger

    tgienger

    Joined:
    Jul 18, 2013
    Posts:
    45
    I've just started learning this as well and I'm not 100% sure this is correct, but I believe there are a couple options. First we start with the conversion by injecting the game object.
    upload_2020-1-23_13-53-23.png

    This allows us to have the game object and the entity in the world at the same time. This is currently necessary if we want a skinned mesh renderer and animations, and other game object world "things" that are currently not dots friendly.

    Then you could run all physics in the DOTS world and update the game objects position, velocity, etc based on the information determined through the dots physics. This would drive your animations and whatever else you need.

    Another option would be to run your normal physics on the character and use dots jobs to run collision detection against entities. You would provide the transform position of your character to the entity world along with other relevant information like height, radius, etc and check if you are colliding with an entity and perform the necessary action.

    I'm hoping someone with more knowledge pokes holes in my ideas though :)
     
    Edy likes this.
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,544
    I think your terminology is probably not helping you and if the way you describe it is your mental model then I would suggest a higher level view of it all which I'll quickly go over below. Sorry if you know this stuff but others may find it useful who are confused.

    Ignoring DOTS and the Entity world for a moment; In Unity "classic" there are two physics systems, one for 2D (Box2D) and one for 3D (PhysX) and neither of them can "interact". Their components come in the form of MonoBehaviours you add to a GameObject. Neither of these physics system know anything about DOTS, Entities etc, they don't even know about each other.

    With DOTS, there's a new DOTS-centric 3D physics system implemented and it only knows about itself and doesn't interact with classic 2D (Box2D) or 3D (physx) physics but that should be expected; it's a different system. That physics system has its own design components which are MonoBehaviour authoring scripts that allow you to author your bodies, colliders, joints etc. These are dedicated to that physics system.

    To aid transition, and probably where you're getting confused, it also supports hybrid GameObject conversion where it can look at the "classic" 3D physics (physx) MonoBehaviour components, or more specifically, their configuration i.e. the size of a sphere, the set-up of a Rigidbody and will convert that configuration to the equivalent for DOTS 3D physics. All it's doing is converting the configuration to a new one and it's a one-way street. There's no bi-directional interaction or anything like that. It's really nothing more than a stepping stone when you're used to working in the "classic" system and need to use the DOTS one.

    These physics system don't interact and you should not try to run both simultaneously unless you are prepared to take the performance hit of running two systems and you are happy that whatever you do on each will be isolated from each other.

    As said in the previous post, if you wanted to do this, then any interaction would be via your own data i.e. perform a query on one or read some results and then perform some update or action on the other.

    This year there'll also be a 2D DOTS physics so that'll mean 2D/3D in classic Unity and 2D/3D in DOTS Unity.
     
    Last edited: Jan 24, 2020
    Alex_Galvez, EZaca, fashrista and 9 others like this.
  4. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    The Physx in 2019.3.0f3 & 5 is driving me nuts. I can get maybe 10 or 20 rigidbodies with attached particle systems made active and then crashes to desktop...every..single...time. Stopped me dead in my tracks for ten days now. Then last night the rigidbodies would be like 15,000 units away from the activation position one frame later and running up scores as though they collided with the avatar..like 6 or 8 collisions for every emitted object I couldn't see anywhere but the Hierarchy. So I was thinking of using DOTS for physics but the vehicle is so delicately balanced I fear I cannot write the same code for the "feel" of the stick to the walls skid-drifting gyrocycle which using a PID controller took about two weeks to balance..AGAIN..after Unity's Physx upgrade totally broke the previous version. I would love DOTS to work with the seven levels and 200+ prefabs already made.. But only use it for the emitted rigidbodies and somehow tag all the other environment props so that DOTS knows about them. Since it is in edutainment game about subatomic physics taking place in environments like cyclotrons and tokamaks and particle accelerator tunnels it would seem DOTS is the way to go for the subatomic part..protons, neutrons, electrons etc..as I am limited with physx to the dozens before slowdown or crashes and DOTS seems like you can have thousands.

    @MelvMay ...You alluded to DOTS understanding Physx objects by having a component such as a rigidbody or collider on them. Do I have to script this or is that a part of the package I have to init. I tried playing wth a github sample last night and it came in with no lighting or totally borked lighting and like 15fps. Not encouraging..but then i see real world devs convert their game with huge mobs and inventories moving around seamlessly. Tempting..but I have dug myself into many a hole thinking this Unity tech is awesome and then the project dying by a thousand cuts.

    What is the exact process to convert environments..most just MeshCollider colliders and a bunch of triggers..and can I just keep my other stuff intact like the audio system and portal door opener-closer type scripts?
     
    EZaca likes this.
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,544
    It's known as GameObject conversion and it's beyond what I can describe here. A recent presentation by Unity that goes over how it works can be found here. Hope it helps.
     
    Edy likes this.