Search Unity

Unity.Physics 0.3.2 joins into the scene!

Discussion in 'Physics for ECS' started by CookieSalad, Mar 11, 2020.

  1. CookieSalad

    CookieSalad

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    24
    Hey everyone! Hope this day finds you well!

    Here’s a little something to spice up your week: Unity.Physics 0.3.0-preview.1 is now available to download via the Package Manager! Here are some of the key features you can expect to find in this release:
    • Authoring support for Legacy Joints. Old-school gameobject based joints will now be automatically converted to Unity.Physics based joints when a ConvertToEntity component is attached, or if they’re placed in a subscene.
    • The Physics Simulation can now be optionally stepped with in a single threaded mode or immediately. This is much more performant for simple simulations where job management costs more than the simulation step itself. See the '6. Use Cases/ImmediateMode' sample for example changes.
    • New Collider Shape re-sizing handles. These will allow one to resize the collision shapes directly in the scene view, if that’s your cup of tea.
    • Dependencies have been updated. Unity.Physics now has explicit dependencies for Burst, Collections, Jobs and Mathematics, in addition to Entities.
    • Bug fixes!
    • Performance improvements!
    For a more detailed list of changes, check out the change log.

    The Physics Sample has some changes as well, including fixes for a few issues, as well as updated dependencies (LWRP, Input System, DOTS Editor, Hybrid Renderer).

    As usual, the features introduced in this release are experimental, so please report any issues you find using the Unity Bug Reporter, or in this thread.
     
    Orimay, AntonioModer, Zoey_O and 7 others like this.
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Not sure about what I think of static bodies being forced to participate in the transform system, if how I read the changelog is accurate. Even when the bug is fixed. We have static only collision worlds with 400k+ colliders. Bugs aside are we going to take a performance hit when rebuilding for this use case?
     
  3. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    • If a static body does not have Parent component, then it is presumed to be in world space, and Translation/Rotation are read directly as before. This is how things have been up to this point, and it is the preferred, optimal approach.
    • If a static body does have a Parent component, then we decompose world space position/orientation for the RigidBody representation from the entity's LocalToWorld component. The perf hit here comes from a) data bandwidth to build rigid body positions/orientations (since we are reading in 64 bytes per body, rather than just the 28 bytes per body in the former case) and b) doing the calculation. The bug in the TRSToLocalToParent system only applies to this latter case, as it was basically always touching LocalToParent with read/write permissions, whether or not anything changed, which meant LocalToWorld was always being rebuilt even if nothing changed.
     
    impulse_ctrl likes this.
  4. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Cant wait to try this!

    Does this include the collector refactor? Can't find it in notes
     
  5. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    That will be coming next release
     
    PhilSA likes this.
  6. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Is there some other plan for joints coming up later or why there isn't any authoring components for them in Unity Physics? I know there are some in the physics samples but they are in additional scripts there.

    To be able to even use the legacy joint conversion, you'd need to setup all physics using old style components, meaning no physics body components but rather old rigidbody etc which I guess it expected as it's legacy joint conversion, but I'm now wondering what's coming up that will not be for "legacy" setup :)

    Btw when will those updated physics samples go live? The sample repo hasn't been updated for this package yet :)
     
  7. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    166
    Any ETA about to public EulerAngles and PhysicsShapeExtensions?
    I don't use GameObjectConversion, but I need the two file to update my hybrid systems to the new version per time.
     
  8. CookieSalad

    CookieSalad

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    24
    The updated Samples should go live some time today, hopefully. Thanks for pointing it out!
     
    rz_0lento likes this.
  9. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    Yes, a new authoring component is being worked on that will be part of the package proper. The current plan is for it to work much like the new shape component (e.g., one component with some common preset types, as well as a fully custom configuration). We need to settle a couple points in the run-time though to validate how the authoring data should look. We just need to give it the right design time because it is a lot of work to make changes to authoring data after the fact.

    It is true a legacy joint needs a legacy Rigidbody, but you can also put a PhysicsBodyAuthoring component on the GameObject. In this case, the conversion system will ignore the data on the Rigidbody and just use things defined on PhysicsBodyAuthoring.
     
    rz_0lento likes this.
  10. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    There are no specific plans for either of these types different from anything else. But it would be very helpful if you can provide some clearer information about what you are doing that you need these types to be public.
     
  11. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    166
    I want two method like this:
    Code (CSharp):
    1. public static BlobAssetReference<Unity.Physics.Collider> Convert(
    2.             this UnityEngine.Collider collider,
    3.             Unity.Physics.Material material,
    4.             CollisionFilter collisionFilter,
    5.             float convexRadius,
    6.             bool isBaked);
    7.  
    8. public static BlobAssetReference<Unity.Physics.Collider> Convert(this PhysicsShapeAuthoring shape, int groupIndex, bool isBaked);
     
  12. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    Can you give me some more context what the use cases for these methods are? In what ways do the built-in conversion systems not meet your needs?

    In the latter signature I can see for example you want to assign a groupIndex, which we have no built-in workflow for yet, but in that case I would recommend a system that just runs after the built-ins and modifies the component data. For example:

    Code (CSharp):
    1. using Unity.Collections;
    2. using Unity.Entities;
    3. using Unity.Mathematics;
    4. using Unity.Physics;
    5. using Unity.Physics.Authoring;
    6. using UnityEngine;
    7.  
    8. // add this component to a hierarchy root to make all converted bodies ignore each other
    9. [DisallowMultipleComponent]
    10. class IgnoreBodiesAuthoring : MonoBehaviour
    11. {
    12.  
    13. }
    14.  
    15. [UpdateAfter(typeof(LegacyRigidbodyConversionSystem))]
    16. unsafe class ConvertIgnoreBodies : GameObjectConversionSystem
    17. {
    18.     EntityQuery m_IgnoreBodiesQuery;
    19.  
    20.     protected override void OnCreate()
    21.     {
    22.         base.OnCreate();
    23.         m_IgnoreBodiesQuery = GetEntityQuery(ComponentType.ReadOnly<IgnoreBodiesAuthoring>());
    24.     }
    25.  
    26.     protected override void OnUpdate()
    27.     {
    28.         if (m_IgnoreBodiesQuery.CalculateEntityCount() == 0)
    29.             return;
    30.  
    31.         using (var entities = m_IgnoreBodiesQuery.ToEntityArray(Allocator.Persistent))
    32.         {
    33.             for (var i = 0; i < entities.Length; ++i)
    34.             {
    35.                 var ignore = EntityManager.GetComponentObject<IgnoreBodiesAuthoring>(entities[i]);
    36.                 var groupIndex = -1 * math.abs(ignore.GetHashCode());
    37.  
    38.                 foreach (var body in ignore.GetComponentsInChildren<PhysicsBodyAuthoring>())
    39.                 {
    40.                     var bodyEntity = GetPrimaryEntity(body);
    41.  
    42.                     if (!DstEntityManager.HasComponent<PhysicsCollider>(bodyEntity))
    43.                         continue;
    44.  
    45.                     var collider = DstEntityManager.GetComponentData<PhysicsCollider>(bodyEntity);
    46.                     var filter = collider.ColliderPtr->Filter;
    47.                     filter.GroupIndex = groupIndex;
    48.                     collider.ColliderPtr->Filter = filter;
    49.                 }
    50.             }
    51.         }
    52.     }
    53. }
     
  13. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    166
    I don't use the built-in conversion systems,I have a custom conversion workflow seem as GameObjectEntity(For using UnityEngine.Animator, ParticleSystem and so on).So I need to convert UnityEngine.Collider and PhysicsShapeAuthoring to BlobAssetReference<Unity.Physics.Collider> in runtime.
    And sometime I don't want to bake the collider such as lockstep server and client, it maybe induces flopping errors.
    This is my code to use the two method:
    Code (CSharp):
    1.  
    2.         private bool __Build()
    3.         {
    4.             if (__physicsColliders == null || __physicsColliders.length < 1)
    5.             {
    6.                 bool isBaked = (_flag & Flag.Baked) == Flag.Baked;
    7.                 var colliderBlobInstances = new NativeList<CompoundCollider.ColliderBlobInstance>(Allocator.Temp);
    8.  
    9.                 Transform transform = base.transform;
    10.  
    11.                 __colliders = new List<UnityEngine.Collider>();
    12.                 transform.GetComponentsInChildren<UnityEngine.Collider>(__colliders.Add, typeof(PhysicsShapeComponent), true);
    13.  
    14.                 CollisionFilter collisionFilter = default;
    15.                 collisionFilter.CollidesWith = collidesWith;
    16.                 collisionFilter.BelongsTo = (uint)(int)_belongsTo;
    17.                 collisionFilter.GroupIndex = _groupIndex;
    18.  
    19.                 Unity.Physics.Material material;
    20.                 material.Flags = 0;
    21.                 material.FrictionCombinePolicy = Unity.Physics.Material.CombinePolicy.Minimum;
    22.                 material.RestitutionCombinePolicy = Unity.Physics.Material.CombinePolicy.Minimum;
    23.                 material.CustomTags = 0;
    24.                 material.Friction = 0.0f;
    25.                 material.Restitution = 0.0f;
    26.                 __colliders.Convert(
    27.                     colliderBlobInstances.Add,
    28.                     transform,
    29.                     material,
    30.                     collisionFilter,
    31.                     0.0f,
    32.                     isBaked
    33. #if UNITY_EDITOR
    34.                 , false
    35. #endif
    36.                 );
    37.  
    38.                 int index = 0;
    39.                 foreach (var collider in __colliders)
    40.                 {
    41.                     if (collider.isTrigger)
    42.                     {
    43.                         if (__triggerIndices == null)
    44.                             __triggerIndices = new List<int>();
    45.  
    46.                         __triggerIndices.Add(index);
    47.                     }
    48.  
    49.                     //Destroy(collider);
    50.  
    51.                     ++index;
    52.                 }
    53.  
    54.                 __shapes = new List<PhysicsShapeAuthoring>();
    55.                 transform.GetComponentsInChildren<PhysicsShapeAuthoring>(__shapes.Add, typeof(PhysicsShapeComponent), true);
    56.  
    57.                 __shapes.Convert(
    58.                    colliderBlobInstances.Add,
    59.                    transform,
    60.                    _groupIndex,
    61.                    isBaked
    62. #if UNITY_EDITOR
    63.                 , false
    64. #endif
    65.                 );
    66.  
    67.  
    68.                 foreach (var shape in __shapes)
    69.                 {
    70.                     if (shape.IsTrigger)
    71.                     {
    72.                         if (__triggerIndices == null)
    73.                             __triggerIndices = new List<int>();
    74.  
    75.                         __triggerIndices.Add(index);
    76.                     }
    77.  
    78.                     //Destroy(shape);
    79.  
    80.                     ++index;
    81.                 }
    82.  
    83.                 __physicsColliders = PhysicsColliders.Create(colliderBlobInstances, true);
    84.  
    85. #if UNITY_EDITOR
    86.                 __physicsColliders.name = transform.root.name;
    87. #endif
    88.  
    89.                 colliderBlobInstances.Dispose();
    90.  
    91.                 return true;
    92.             }
    93.  
    94.             return false;
    95.         }
    96.  
     
  14. bgmulti15a

    bgmulti15a

    Joined:
    Feb 9, 2017
    Posts:
    25
    Just installed this preview, first time using ECS but there's already this weird thing happening.
    I created two cubes, with one sitting on the other, both dynamics. They are positioned over a third cube without Physics Body (it's static). When I hit play, the cube on top starts to slowly slide of the other like on ice, even if there are no external forces applied.
    Sliding doesn't happen between dynamic and static, only between dynamics objects.
    I tried to set friction in Physics Shape to 1 but nothing changed.
     
  15. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    you'll want to use Havok for this type of scenario. Stable stacks of rigidbodies are not a good match for "Unity Physics" package because it's a stateless physics engine (which has its own advantages; most notably it allows for easy and low-bandwidth networked physics)
     
    Last edited: Mar 12, 2020
  16. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    Can you please provide some more information? Though it's not the recommended workflow, the built-in conversion systems can work at run-time now. Basically: Why do you need to have your own custom run-time conversion instead of using the ones we provide?

    I think I also need some more information to understand the problem here. What exactly do you mean by "bake the collider"? What in the built-in approach is not compatible with a lockstep networking model?

    Thanks!
     
  17. Oh-Carson

    Oh-Carson

    Joined:
    Apr 20, 2014
    Posts:
    4
    Unless I'm missing something, this currently conflicts with Entities 0.7.0, so, 0.6.0 is the current supported version which is a shame, is this due to change any time soon?
     
  18. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Can you elaborate, @Oh-Carson? You mean it depends on older entities? That doesn't automatically mean it's not compatible with newer one. I'm running latest entities + physics package here without package conflicts
     
  19. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    166
    1.I have some custom worlds and need to set physics systems to my custom system group in FixedUpdate,like this:
    upload_2020-3-13_10-11-35.png
    My many systems can't and no need to run in default world,so I set DefaultGameObjectInjectionWorld to empty:
    Code (CSharp):
    1. #if !GAME_RESOURCE_EDIT
    2. public class GameBootStrap : ICustomBootstrap
    3. {
    4.     public bool Initialize(string defaultWorldName)
    5.     {
    6.         var world = new World(defaultWorldName);
    7.         World.DefaultGameObjectInjectionWorld = world;
    8.  
    9.         return true;
    10.     }
    11. }
    12. #endif
    2.I have multiple worlds and need to set a entity to a specify world,but current version built-in conversion systems can't do this well(maybe it's my misunderstand), so I custom conversion systems seem as GameObjectEntity,like this:
    upload_2020-3-13_10-31-32.png
    3.I believe unity can improve these issues in the future. but it's so long for my game.I think the two method can give me more possibility.

    This is my current Implementation:
    Code (CSharp):
    1. public static BlobAssetReference<Unity.Physics.Collider> Convert(this PhysicsShapeAuthoring shape, int groupIndex, bool isBaked)
    2.         {
    3.             quaternion rotation;
    4.             var transform = shape.transform;
    5.             var localToWorld = transform.localToWorldMatrix;
    6.             var shapeToWorld = shape.GetShapeToWorldMatrix();
    7.             var blob = BlobAssetReference<Unity.Physics.Collider>.Null;
    8.             switch (shape.ShapeType)
    9.             {
    10.                 case ShapeType.Box:
    11.                     var boxGeometry = shape.GetBoxProperties();
    12.                     if (isBaked)
    13.                     {
    14.                         var orientation = EulerAngles.Default;
    15.                         orientation.SetValue(boxGeometry.Orientation);
    16.                         boxGeometry = boxGeometry.BakeToBodySpace(localToWorld, shapeToWorld, orientation);
    17.                     }
    18.  
    19.                     blob = Unity.Physics.BoxCollider.Create(
    20.                         boxGeometry,
    21.                         GetFilter(shape, groupIndex),
    22.                         GetMaterial(shape));
    23.                     break;
    24.                 case ShapeType.Capsule:
    25.                     var capsuleGeometryAuthoring = shape.GetCapsuleProperties();
    26.                     if (isBaked)
    27.                         capsuleGeometryAuthoring = capsuleGeometryAuthoring.BakeToBodySpace(localToWorld, shapeToWorld);
    28.  
    29.                     blob = Unity.Physics.CapsuleCollider.Create(
    30.                         capsuleGeometryAuthoring.Get(),
    31.                         GetFilter(shape, groupIndex),
    32.                         GetMaterial(shape));
    33.                     break;
    34.                 case ShapeType.Sphere:
    35.                     var sphereGeometry = shape.GetSphereProperties(out rotation);
    36.                     if (isBaked)
    37.                     {
    38.                         var orientation = EulerAngles.Default;
    39.                         orientation.SetValue(rotation);
    40.                         sphereGeometry = sphereGeometry.BakeToBodySpace(localToWorld, shapeToWorld, ref orientation);
    41.                     }
    42.  
    43.                     blob = Unity.Physics.SphereCollider.Create(
    44.                         sphereGeometry,
    45.                         GetFilter(shape, groupIndex),
    46.                         GetMaterial(shape));
    47.                     break;
    48.                 case ShapeType.Cylinder:
    49.                     var cylinderGeometry = shape.GetCylinderProperties();
    50.                     if (isBaked)
    51.                     {
    52.                         var orientation = EulerAngles.Default;
    53.                         orientation.SetValue(cylinderGeometry.Orientation);
    54.                         cylinderGeometry = cylinderGeometry.BakeToBodySpace(localToWorld, shapeToWorld, orientation);
    55.                     }
    56.  
    57.                     blob = CylinderCollider.Create(
    58.                         cylinderGeometry,
    59.                         GetFilter(shape, groupIndex),
    60.                         GetMaterial(shape));
    61.                     break;
    62.                 case ShapeType.Plane:
    63.                     float3 v0, v1, v2, v3;
    64.                     shape.GetPlaneProperties(out var center, out var size, out rotation);
    65.                     {
    66.                         var orientation = EulerAngles.Default;
    67.                         orientation.SetValue(rotation);
    68.                         if (isBaked)
    69.                         {
    70.                             PhysicsShapeExtensions.BakeToBodySpace(
    71.                                 center,
    72.                                 size,
    73.                                 orientation,
    74.                                 localToWorld,
    75.                                 shapeToWorld,
    76.                                 out v0,
    77.                                 out v1,
    78.                                 out v2,
    79.                                 out v3);
    80.                         }
    81.                         else
    82.                         {
    83.                             PhysicsShapeExtensions.CalculatePlanePoints(
    84.                                 center,
    85.                                 size,
    86.                                 orientation,
    87.                                 out v0,
    88.                                 out v1,
    89.                                 out v2,
    90.                                 out v3);
    91.                         }
    92.                     }
    93.  
    94.                     blob = PolygonCollider.CreateQuad(
    95.                         v0,
    96.                         v1,
    97.                         v2,
    98.                         v3,
    99.                         GetFilter(shape, groupIndex),
    100.                         GetMaterial(shape));
    101.                     break;
    102.                 case ShapeType.ConvexHull:
    103.  
    104.                     using (var pointCloud = new NativeList<float3>(65535, Allocator.Temp))
    105.                     {
    106.                         shape.GetConvexHullProperties(pointCloud);
    107.                         if (isBaked)
    108.                             shape.BakePoints(pointCloud);
    109.  
    110.                         ConvexCollider.Create(
    111.                             pointCloud,
    112.                             shape.ConvexHullGenerationParameters,
    113.                             GetFilter(shape, groupIndex),
    114.                             GetMaterial(shape));
    115.                     }
    116.                     break;
    117.                 case ShapeType.Mesh:
    118.                     const int defaultVertexCount = 2048;
    119.                     using (var pointCloud = new NativeList<float3>(defaultVertexCount, Allocator.Temp))
    120.                     using (var triangles = new NativeList<int3>(defaultVertexCount - 2, Allocator.Temp))
    121.                     {
    122.                         shape.GetMeshProperties(pointCloud, triangles);
    123.                         if (isBaked)
    124.                             shape.BakePoints(pointCloud);
    125.  
    126.                         blob = Unity.Physics.MeshCollider.Create(
    127.                             pointCloud,
    128.                             triangles,
    129.                             GetFilter(shape, groupIndex),
    130.                             GetMaterial(shape));
    131.                     }
    132.                     break;
    133.                 default:
    134.                     break;
    135.             }
    136.             return blob;
    137.         }
    Bake collider need the transform.localToWorldMatrix,sometime my game have the same collider but in different hierarchy between server and client.
    it give me two different colliders even if i make sure they have the same transform in world space.
     
  20. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    Just upgraded, it seems like running collision event jobs before spawning any physics objects results in errors. If you add the code below to an empty project I get

    CollisionEventJob.EventReader.m_InputVelocities has not been assigned


    After spawning a unit the errors stop. Is this a bug or should I prevent this somehow?

    Code (CSharp):
    1. [UpdateAfter(typeof(StepPhysicsWorld))]
    2. public class CollisionEventSystem : JobComponentSystem
    3. {
    4.     protected override JobHandle OnUpdate(JobHandle inputDeps)
    5.     {
    6.         var step = World.GetExistingSystem<StepPhysicsWorld>();
    7.         var build = World.GetExistingSystem<BuildPhysicsWorld>();
    8.  
    9.         return new CollisionEventJob
    10.             {
    11.             }
    12.             .Schedule(step.Simulation, ref build.PhysicsWorld, inputDeps);
    13.     }
    14.  
    15.     struct CollisionEventJob : ICollisionEventsJob
    16.     {
    17.         public void Execute(CollisionEvent c)
    18.         {
    19.         }
    20.     }
    21. }
     
    Adam-Mechtley likes this.
  21. Oh-Carson

    Oh-Carson

    Joined:
    Apr 20, 2014
    Posts:
    4
    It turned out I needed to update collections manually? From 0.5.2 to 0.6.0 so yeah my bad.
     
  22. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    I think I'm still not clear. If you use GameObjectConversionUtility.ConvertGameObjectHierarchy() to convert via built-in conversion systems, you can pass it a GameObjectConversionSettings object, where you can specify a destination World. Does that not work for you?
     
  23. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    Thanks for reporting! Looks like a bug on our end (event streams are never allocated if NumDynamicBodies == 0). Someone will take a look early next week.
     
  24. kro11

    kro11

    Joined:
    Sep 23, 2019
    Posts:
    105
    When will it be possible to track multiple overlapping triggers at the same time? (Example 2d1 still gives an error when 2+ triggers try to access the same object).
     
  25. Sima_Havok

    Sima_Havok

    Joined:
    Dec 16, 2019
    Posts:
    52
  26. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Can you elaborate a bit more on this? How can we reproduce the issue in the 2d1 example?
     
  27. kro11

    kro11

    Joined:
    Sep 23, 2019
    Posts:
    105
    I think this issue already described in comments:
    TriggerVolumeBehaviour.cs - Lines 80-83

    In the example itself, it will be difficult to reproduce this problem, since you cannot move multiple triggers at the same time. But I used this example for enemies and projectiles. When 2+ projectiles (spread attack) try to access the same body, then errors appear.
     
    petarmHavok likes this.
  28. CookieSalad

    CookieSalad

    Unity Technologies

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

    We’ve just released a small patch release for Unity Physics - 0.3.1-preview. The primary change is the removal of TransformNewHits() from the ICollector interface. Review the changelog for an upgrade guide. Burst was also updated to avoid a regression introduced in 0.3.0-preview.1

    Havok Physics for Unity has also been updated alongside this Unity Physics release.

    An updated version of the Physics Samples is also out. We have removed LWRP package dependency to reduce the complexity of the package.

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

    Have a nice weekend!
     
  29. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    When are we going to get the samples updated to use the new SystemBase class? The samples are still using the old classes that are going to be deprecated
     
    Orimay and steveeHavok like this.
  30. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    That's in review now.
     
  31. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    Thanks, are you aware you can not currently mark the PhysicsWorld readonly using lambda job syntax?

    Entities.WithReadOnly(PhysicsWorld)


    gives

     
  32. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Bas-Smit likes this.
  33. andreicfsteaua

    andreicfsteaua

    Joined:
    Nov 18, 2019
    Posts:
    36
    Are you going to make physics compatible with parenting? Everything is a mess with parented objects and it would be a shame to have to undo parenting to make physics work
     
    florianhanke likes this.
  34. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    I made a simple parenting system. It only allows one parent (no grandparents or beyond).

    Code (CSharp):
    1.  
    2. public class PhysicsParentingSystem : SystemBase
    3. {
    4.     private EntityCommandBufferSystem endFrame;
    5.  
    6.     protected override void OnUpdate()
    7.     {
    8.         var ecb = endFrame.CreateCommandBuffer().ToConcurrent();
    9.  
    10.         var translationFromEntity = GetComponentDataFromEntity<Translation>(true);
    11.         var rotationFromEntity = GetComponentDataFromEntity<Rotation>(true);
    12.         var scaleFromEntity = GetComponentDataFromEntity<Scale>(true);
    13.  
    14.         Entities
    15.             .WithReadOnly(translationFromEntity)
    16.             .WithReadOnly(rotationFromEntity)
    17.             .WithReadOnly(scaleFromEntity)
    18.             .ForEach(
    19.                 (
    20.                     Entity entity,
    21.                     int entityInQueryIndex,
    22.                     in PhysicsParentingComponent parentingData
    23.                 ) =>
    24.                 {
    25.                     var parentEntity = parentingData.parentEntity;
    26.                     var parentPosition = translationFromEntity[parentEntity].Value;
    27.                     var parentRotation = rotationFromEntity[parentEntity].Value;
    28.  
    29.                     var parentScale =
    30.                         scaleFromEntity.Exists(parentEntity)
    31.                         ? scaleFromEntity[parentEntity].Value
    32.                         : new float3(1,1,1);
    33.  
    34.  
    35.                     var newTranslation = parentingData.localPosition + parentPosition;
    36.                     var newRotation = math.mul(parentingData.localRotation, parentRotation);
    37.                     var newTransform = new LocalToWorld
    38.                     {
    39.                         Value = float4x4.TRS(
    40.                             newTranslation,
    41.                             newRotation,
    42.                             parentingData.localScale * parentScale
    43.                         )
    44.                     };
    45.  
    46.                     ecb.SetComponent(entityInQueryIndex, entity, newTransform);
    47.                     ecb.SetComponent(entityInQueryIndex, entity, new Translation
    48.                     {
    49.                         Value = newTranslation
    50.                     });
    51.                     ecb.SetComponent(entityInQueryIndex, entity, new Rotation
    52.                     {
    53.                         Value = newRotation
    54.                     });
    55.                 }
    56.             ).ScheduleParallel();
    57.  
    58.         endFrame.AddJobHandleForProducer(Dependency);
    59.     }
    60.  
    61.     protected override void OnCreate()
    62.     {
    63.         endFrame = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
    64.     }
    65. }
    66.  
    Code (CSharp):
    1. using UnityEngine;
    2. using Unity.Entities;
    3.  
    4. [RequiresEntityConversion]
    5. public class PhysicsParentingAuthoring : MonoBehaviour, IConvertGameObjectToEntity
    6. {
    7.     [SerializeField]
    8.     private GameObject parentGameObject;
    9.  
    10.     public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    11.     {
    12.         var parentTransform = parentGameObject.transform;
    13.  
    14.         // find locals
    15.         var localPosition = transform.localPosition;
    16.         var localRotation = transform.localRotation;
    17.         var localScale = transform.localScale;
    18.  
    19.         dstManager.AddComponentData(entity, new PhysicsParentingComponent
    20.         {
    21.             parentEntity = conversionSystem.GetPrimaryEntity(parentTransform),
    22.             localScale = localScale,
    23.             localRotation = localRotation,
    24.             localPosition = localPosition
    25.         });
    26.     }
    27. }
    28.  
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Transforms;
    3. using Unity.Mathematics;
    4.  
    5. public struct PhysicsParentingComponent : IComponentData
    6. {
    7.     public Entity parentEntity;
    8.     public float3 localPosition;
    9.     public quaternion localRotation;
    10.     public float3 localScale;
    11. }
    12.  
     
  35. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    We'll improve documentation around this, but the main reason we un-parent dynamic bodies is for performance. Physics simulates in world space, and reverse calculating local-space transformations for everything after the fact requires a lot of random access to walk through a hierarchy, for no clear benefit.

    That said, while we're not clear on what use there is in retaining a bunch of local space transformations, there are use cases we know about that could benefit from scaffolds (e.g., teleport a group of rigid bodies to some location in the scene after instantiating them or just to reposition them). We'd love to have more information on your use cases in this thread I started regarding the transform systems in general.
     
  36. Aokkii

    Aokkii

    Joined:
    Nov 3, 2013
    Posts:
    118
    i don't know if this is the right thread to ask for a feature , but here it goes.

    Unity needs built in Dynamic bones support, I tried to use spring joints(built-in physics) to make hair physics, and:

    -only worked if the hair bones are not children of the model.
    -the joints settings are difficult to set up
    -they stretch to much,
    -the physics go nuts and the hair has erratic movement.

    maybe cuz joints are not designed to be use for hair physics.

    so thats why i ask for dynamic bones support:oops:. either built in physics or Dots physics.
     
  37. gamayun

    gamayun

    Joined:
    Nov 20, 2012
    Posts:
    34
    Hi All,

    I'm trying to code a system to handle collisions. I do not convert from gameobject to entities because I just want to code ECS right away.

    For now I made a collection of cubes linked by joints. It works. But when I want to manage the collisions (for example to break some joints) I wrote a system to process TriggerEvents and of course my colliders are created using Unity.Physics.Material.MaterialFlags.EnableCollisionEvents in the material.
    But nothing happens.
    Someone suggested I use old GameObject with physicsShapes and set the isTrigger On, but I do really want to do it by code.
    My question is, is it possible and I probably wrongly coded it, or is it just not possible right now?
    Cheers
    Thierry
     
  38. Bas-Smit

    Bas-Smit

    Joined:
    Dec 23, 2012
    Posts:
    274
    use GameObject with physicsShapes and entity inspector to see what you need to create from code. That said gameobjects are the recommended way of representing your authoring environment
     
  39. gamayun

    gamayun

    Joined:
    Nov 20, 2012
    Posts:
    34
    HI @Bas-Smit Thanks for your help. I was going to give up doing it by code and implement GameObjects like you said. But then I spotted my bug, I was thinking CollisionEvent although I implemented TriggerEvent. So I'm trying to implement a system to catch those.... although I still have other bugs but I am investigating those. Thank you anyway for your help.
    And by the way if anyone has a source code of a script implementing ICollisionEventsJob I'd be very grateful to see it!
    Cheers
    Thierry
     
  40. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    gamayun likes this.
  41. gamayun

    gamayun

    Joined:
    Nov 20, 2012
    Posts:
    34
    petarmHavok likes this.
  42. surits14

    surits14

    Joined:
    Jan 22, 2018
    Posts:
    22
    Unity Physics 0.3.1 and entities 0.8.0 not compatible. A lot of errors occur. When can we expect support for entities 0.8.0?
    Has anyone already made any workaround to solve those errors? please let us know. Thank you.
     
    Last edited: Apr 4, 2020
    wilmer_lin likes this.
  43. Sima_Havok

    Sima_Havok

    Joined:
    Dec 16, 2019
    Posts:
    52
    surits14 likes this.
  44. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    There are still a lot of things that are internal that shouldn't be.

    Case in point we have our own navigation system based on recastnavigation that uses Unity.Physics geometry. We use geometry collectors basically a lot of the same logic that the physics debug stuff uses. Why Unity thinks end users don't have a need to create their own tooling around a lot of the internal data is beyond me. I mean we have hit this issue left and right since Unity.Physics released. It's really annoying.
     
    elZach likes this.
  45. surits14

    surits14

    Joined:
    Jan 22, 2018
    Posts:
    22
    thank you.
     
  46. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Also I think this has come up before, but we need a way to filter viewing colliders by type for the debug display. Terrains will just freeze the editor up basically. It's simple enough to do I've been adding it myself on each new version.
     
  47. CookieSalad

    CookieSalad

    Unity Technologies

    Joined:
    Dec 29, 2014
    Posts:
    24
    Hey! Hope everyone's staying safe!

    We’ve just released another small patch release for Unity Physics - 0.3.2-preview. Havok Physics has been updated as well. This release contains mainly small fixes for various issues as well as a bump in version dependencies for Entities and friends.

    An updated version of the Physics Samples will also be out tomorrow. One of the changes there is the removal of the DOTS Editor dependency. We may reintroduce it at a later date.

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

    Have a nice weekend!
     
  48. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    486
    Any ETA when new version will arrive?
     
  49. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    No specific ETA yet. Sometime in June at the latest. Is there something specific you are missing/needing?
     
  50. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    345
    Personally im waiting for Joint Motors
     
    Adam-Mechtley likes this.