Search Unity

Unity Unity.Physics 0.4.1 steps onto the stage!

Discussion in 'DOTS Physics' started by CookieSalad, Jun 18, 2020.

  1. CookieSalad

    CookieSalad

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    24
    Hey everyone! We’ve got a new Unity.Physics version with all kinds of new goodies: Unity.Physics 0.4.0-preview.5 is now live. As usual, grab it from the package manager. For this release, we bumped up the minimum editor version to 2019.4.0f1-LTS so it’ll be necessary to update that first. Here are some highlights from the release:
    • NOTE: This update required making some changes to the authoring data layout for physics material settings. This change affects both PhysicsShapeAuthoring components and PhysicsMaterialTemplate assets. To ensure all your prefabs and scenes are upgraded correctly, back-up your project and then run the data upgrade tool immediately after updating Unity Physics. You can access this tool in the main menu under Window -> DOTS -> Physics -> Upgrade Data
    • Added new settings for improved Solver Stability. Discussion thread here.
    • Added Data Flow Graph nodes for querying objects in a collision world
    • Changed various pair interfaces to direct accessors (ex. EntityPair is now EntityA and EntityB)
    • New APIs and data protocol for joints to permit modifying constraints at run-time without using unsafe code. See the new Modify Joints scene in the sample project for example usage.
    • Various new components and utility methods to simplify common operations, such as applying explosion forces (1c. Conversion samples), matching kinematic bodies to direct/animation input (5d. Kinematic Motion sample) and temporarily changing a dynamic body’s kinematic state (5a. Change Motion Type sample)
    • New AddInputDependency() and GetOutputDependency() methods on core physics systems to provide proper control over custom system scheduling
    • Added support for multiple PhysicsShapeAuthoring components on a single GameObject to create a compound collider
    • Reworked collision and trigger event samples with all-new DynamicBuffer-based approach for more robust stateful event handling.
    • API compatibility with upcoming Entities 0.12.0. Unity Physics should be ready to use as-is once it is released!
    • Bug fixes!
    • General performance improvements!
    For more detailed changes, check out the change log here.

    The Physics Samples project have some new and reworked demo scenes, particularly in regards to updated Trigger and Collision event functionalities.

    Havok.Physics 0.3.0-preview.2 that is compatible with the new Unity.Physics release is also out now!

    This is a pretty big Unity.Physics release with lots of changes. We have taken care to minimize API breakages and avoid behavior changes, but please report all issues you discover using the Bug Reporter or commenting in this thread!
     
    jashan, GliderGuy, Tsequier and 7 others like this.
  2. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,147
    Nice looking list :D
    I'm guessing this is still finding it's way to us as latest one we see is 0.2.2-preview atm (https://packages.unity.com/com.havok.physics)

    Any ETA for updated Physics Samples on the ECS Sample repo? :)
     
  3. CookieSalad

    CookieSalad

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    24
    That's right, Havok is still on its way, but should be out later today. Updated Physics Samples should also be available later today, once we get Havok out.

    Update: Both Havok and the updated Samples project are now live!
     
    Last edited: Jun 18, 2020
    rz_0lento likes this.
  4. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,739
    Very nice update

    Data Flow Graph is kind of a big mystery to me right now. Where can we learn more about it (and what it does)? I vaguely know that DOTS animation makes use of it, but that's all I know
     
    Last edited: Jun 19, 2020
    lclemens and florianhanke like this.
  5. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,147
    I see Havok Physics 0.3.0-preview.1 and ECS Sample repo physics updates are live now :)
     
  6. Adam-Mechtley

    Adam-Mechtley

    Unity Technologies

    Joined:
    Feb 5, 2007
    Posts:
    290
    You can find its (limited) documentation here, but it actually has some quite good samples that you can import using Package Manager when it is in your project.

    The features we added for this release are some basic groundwork needed for using physics from within an animation graph. For example, if you sample an animation at a specific time, you can then do a spatial query based on the target pose immediately from within the graph, apply IK correction, and finally write that pose out to kinematic rigid bodies via the new PhysicsVelocity.CalculateVelocityToTarget() method.
     
    Rellfy, lclemens, steveeHavok and 3 others like this.
  7. lclemens

    lclemens

    Joined:
    Feb 15, 2020
    Posts:
    321
    Oooooooo.... ApplyExplosionForce().... this makes me very happy :).
     
    Nothke and steveeHavok like this.
  8. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    227
    Any new info about motor forces in joints?
     
  9. Adam-Mechtley

    Adam-Mechtley

    Unity Technologies

    Joined:
    Feb 5, 2007
    Posts:
    290
    It's actively being worked on, but didn't make it in time for this release
     
    Extrys and CookieSalad like this.
  10. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    227
    Good to know thanks!
     
  11. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,311
    DFG is still marked as highly experimental and DOTS animation is still experimental and not compatible with the most recent DFG versions. I haven't installed 4.0 yet is DFG a hard dependency? If so that's sort of a problem for people using animation.
     
  12. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,311
    Ah I see animation has a new release now which is compatible.
     
  13. Adam-Mechtley

    Adam-Mechtley

    Unity Technologies

    Joined:
    Feb 5, 2007
    Posts:
    290
    No it is a soft dependency. Basically if you have DFG present in your project with some supported version or greater, then these nodes exist.
     
  14. Dapeos

    Dapeos

    Joined:
    Jun 27, 2013
    Posts:
    20
    Hi,
    I just updated my project with the latest packages.

    I was creating a Physics Joint and then assigning it to a Joint Entity which was working great.
    Code (CSharp):
    1. BlobAssetReference<JointData> jointData = JointData.Create(new BodyFrame(bodyAFromJoint), new BodyFrame(bodyBFromJoint), constraints);
    2.  
    3.             var componentData = new PhysicsJoint
    4.             {
    5.                 JointData = jointData,
    6.                 EntityA = wheelAuthoring.wheelColliderEntity,
    7.                 EntityB = vehicleEntity,
    8.                 EnableCollision = 0
    9.             };
    But since this is now deprecated I looked into the examples of how to do this now. The examples show using:
    Code (CSharp):
    1. conversionSystem.World.GetOrCreateSystem<EndJointConversionSystem>().CreateJointEntity(
    2.                 this,
    3.                 GetConstrainedBodyPair(conversionSystem),
    4.                 PhysicsJoint.CreateBallAndSocket(PositionLocal, PositionInConnectedEntity)
    5.             );
    Basically how do I do this without using CreateJointEntity which requires an authoring component which I currently do not have.
    I tried adding the PhysicsConstrainedBodyPair and PhysicsJoint components to the Joint Entity but it did not work.

    Thanks,
    Marc
     
  15. Dapeos

    Dapeos

    Joined:
    Jun 27, 2013
    Posts:
    20
    Solution to my problem was to add the constraints to the FixedList128 using Add().

    var constraints = new FixedList128<Constraint>();
    constraints.Add(c1);
    constraints.Add(c2);
    Instead of:
    constraints[0] = c1;
    constraints[1] = c2;

    Thanks,
    Marc
     
    Adam-Mechtley and steveeHavok like this.
  16. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    672
    I just noticed these two things but whats the reasoning behind ComponentTypeHandle and BufferTypeHandle in the BackwardCompatibilityExtensions file?

    Also with some of the stateful event buffers introduced such as StatefulCollisionEvent, will these eventually be rolled into the physics package itself or stay contained to the samples? Likewise for the CharacterController components and systems.
     
  17. Adam-Mechtley

    Adam-Mechtley

    Unity Technologies

    Joined:
    Feb 5, 2007
    Posts:
    290
    These are just shims for API forward compatibility with an upcoming version of entities (which I believe is actually available now). It ensures there will be no compiler warnings about obsolete API usage.

    The plan is to iterate on this sort of functionality in the samples and gather feedback, and then later bring the functionality into the package proper.
     
    thelebaron likes this.
  18. CookieSalad

    CookieSalad

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    24
    Hey all!

    We’ve just released a fresh new patch release for Unity Physics - 0.4.1-preview. This release contains bugfixes and a couple of small features.

    Havok Physics has been updated as well, however it should go live tomorrow. Note for anyone using an older version of HP with the newer version of Unity Physics: joints will not work correctly due to changed memory layout in that system.

    We have also updated the Physics Sample project with new scenes for you guys to experiment with! It'll be out later today.

    Please let us know if you discover any new issues relating to this release.

    Have a nice week!
     
    Zeffi, steveeHavok, rz_0lento and 2 others like this.
  19. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    672
    just a note, seems like the manifest points to a local file ("com.unity.physics": "file:../../com.unity.physics",) instead of
    "com.unity.physics": "0.4.1-preview",
     
    petarmHavok likes this.
  20. CookieSalad

    CookieSalad

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    24
    Good catch! Thanks!

    This should be fixed now.
     
  21. ryanslikesocool

    ryanslikesocool

    Joined:
    Jul 31, 2016
    Posts:
    45
    Physics feels much slower with the latest Entities update. Is this because of the new changes with Entities 0.13.0? Or is it something to do with the issues I'm experiencing with Burst on macOS 11?

    EDIT: Seems it's an issue with macOS 11 and Burst. More info here
     
    Last edited: Aug 3, 2020
  22. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,295
    So that would be DynamicBufferTriggerEventAuthoring, right? I have noticed that all the examples use those stateful trigger events and was wondering if for the general case (when porting an existing game to DOTS / DOTS Physics), you'd recommend using that instead of directly handling the events?

    Would you maybe even include this into the core Unity Physics package?

    And as a "feature request" for the Unity Physics examples: What would be the best way to call back into the MonoBehaviour world from those events? I have noticed that TriggerVolumeChangeMaterialAuthoring is run with WithoutBurst(), so would it be possible to pass in a reference to e.g. a score manager in that case, which is then called from the ForEach-loop?
     
  23. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    We might include these in the package, but they will always be optional in the simulation because of its stateful nature. Having them on means people need to take care of them when doing rollback.

    Not sure what exactly you want to do, but you can do a foreach on events exposed on the Simulation:
    foreach (var event in Simulation.CollisionEvents) or foreach (var event in Simulation.TriggerEvents).

    These are not stateful, but they have this nice feature of iterating through them outside of a job.

    Alternatively, you can copy them over to whatever format suits you, and use them from a mono behavior anywhere you wish. They are single threaded by nature and are easy to copy over.
     
    jashan likes this.
  24. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,295
    Thank you! That sounds awesome!

    So I could basically use ITriggerEventsJob to do any DOTS-based stuff (in my case, this will probably mean creating new entities for effects), and iterate over Simulation.TriggerEvents in a regular MonoBehaviour.Update(), to do handle any non-jobified logic (that isn't particularly performance critical), right?

    EntityA and EntityB are still "non-deterministic" in the sense that I cannot rely on any specific entity being in A or B, and that won't change, right? I've tried different things like setting Collision Response to "None", or removing Collides With on one of the entities but that seems to always result in no trigger events being fired at all. So the pattern there is first finding out which one is which, and then moving on from there, I guess.
     
  25. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Yes, that is correct. Also you can iterate using foreach in DOTS as well (for example in a system) if that's what you prefer. So you can do any of the approaches in DOTS, and iteration in mono behavior.

    There is some determinism in what is A and what is B - if one is dynamic and one is kinematic/static, B will always be the kinematic/static one. Otherwise, A is the one with smaller rigid body index.
     
  26. goncalo-vasconcelos

    goncalo-vasconcelos

    Joined:
    May 24, 2017
    Posts:
    4
    Does this also hold for Havok Physics?
     
  27. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Yes, it's the same. Just keep in mind that rigid body index in Unity Physics is not the same as Havok's internal rigid body index. But the dynamic - kinematic/static thing stands.
     
  28. atmikes1234

    atmikes1234

    Joined:
    Apr 21, 2019
    Posts:
    6
    Hi, I'm trying to connect two objects with a joint, but couldn't figure out how to do that yet. I want to do that on runtime and by script. I tried it with GameObjectConversionSystem as shown in the examples and that worked fine, but now i want to do that without a GameObject.

    Here is what i have so far:


    Code (CSharp):
    1. var bodyPair = new PhysicsConstrainedBodyPair(entitySword, playerEntity, true);
    2.       BuildPhysicsWorld bpw = defaultWorld.GetOrCreateSystem<BuildPhysicsWorld>();
    3.       bpw.EntityManager.AddComponentData(entitySword, bodyPair);
    4.       bpw.EntityManager.AddComponentData(entitySword, new PhysicsJoint()
    5.       {
    6.         JointType = JointType.Hinge,
    7.         BodyAFromJoint = frame1,
    8.         BodyBFromJoint = frame2,
    9.       });
    Enabling collision true/false is working fine, and the components are showing up on my entity, but it seems there is no joint between the two objects.

    I guess there is still something missing, or am I on the completely wrong path here?
     
  29. Adam-Mechtley

    Adam-Mechtley

    Unity Technologies

    Joined:
    Feb 5, 2007
    Posts:
    290
    Hi! You need to specify constraints on the PhysicsJoint, either via the SetConstraints() method or one of the various factory methods.
     
    atmikes1234 likes this.
  30. atmikes1234

    atmikes1234

    Joined:
    Apr 21, 2019
    Posts:
    6
    Yes that helped a lot! Thank you very much!
     
  31. StickyMitchel

    StickyMitchel

    Joined:
    Sep 2, 2019
    Posts:
    13
    I noticed in the 0.4.1-preview version that the PhysicsShape on ShapeType Mesh does not account for submeshes anymore. Downgrading to 0.4.0-preview.5 made sure the submeshes got included. This is a bug or did I forget an upgrade step?
     
  32. Adam-Mechtley

    Adam-Mechtley

    Unity Technologies

    Joined:
    Feb 5, 2007
    Posts:
    290
    It's a bug, and on our list to fix in the next release (should be within two weeks)
     
unityunity