- Home /
Unity.Physics Pure ECS/DOTS Implementation Causes Transforms.Translation to error into NaN
Trying out the new ECS and Physics system and I seem to run into an error, or bug of some sort.
Using this page as a guide Introduction to Unity Physics I tried to take a simple moving cube and have them collide with each other.
However, for some reason even though the Component Data is the same with these cubes, and a GameObject to entity conversion they do not appear in the scene. Digging further I found the cause to be that the Translation component's value is NAN. To be more accurate the Translation goes from the value I set, to float3.zero, to NaN.
Here is my implementation: ```
EntityManager eM = World.Active.EntityManager;
EntityArchetype Test = eM.CreateArchetype(
typeof(RenderMesh),
typeof(LocalToWorld),
typeof(Translation),
typeof(Rotation),
typeof(Unity.Physics.PhysicsCollider),
typeof(Unity.Physics.PhysicsDamping),
typeof(Unity.Physics.PhysicsVelocity),
typeof(Unity.Physics.PhysicsMass)
);
NativeArray<Entity> EA = new NativeArray<Entity>(1, Allocator.Temp);
eM.CreateEntity(Test, EA);
for(int i = 0; i < EA.Length; i++) {
Entity e = EA[i];
eM.SetComponentData(e, new Unity.Physics.PhysicsCollider { Value = Unity.Physics.BoxCollider.Create(new Unity.Physics.BoxGeometry() { Center = float3.zero, Orientation = quaternion.identity, Size = new float3(1, 1, 1) }, Unity.Physics.CollisionFilter.Default)});
eM.SetComponentData(e, Unity.Physics.PhysicsMass.CreateDynamic(new Unity.Physics.MassProperties(), 10));
eM.SetComponentData(e, new Unity.Physics.PhysicsVelocity() { Linear = new float3(0.1f, 0.1f, 0.1f), Angular = new float3(0.1f, 0.1f, 0.1f) });
eM.SetComponentData(e, new Unity.Physics.PhysicsDamping() { Linear = 0.01f, Angular = 0.05f });
eM.SetSharedComponentData(e, new RenderMesh {
mesh = Mesh,
material = Material
});
}
EA.Dispose();```
I'm not sure what went wrong here, as this seems to work according to the Unity Manual.
For the love of god do this:
some code
here's some more
sorry didn't know that was the way to format it just used the code button on the text editor here, and it's already annoying and hard to format already just to get it into the code block in the first place weird spacing required for some reason.
I've had a similar problem described here: https://forum.unity.com/threads/entity-disappearing-yet-another-difference-between-rigidbody-and-dots.815640/
No solution unfortunately.
Any luck with finding an answer? I'm having the same problem. Even tried to copy all the data from a converted object and still nothing. It seems that the PhysicsVelocity is what messes up everything. If I only add the PhysicsCollider, Physics$$anonymous$$ass, PhysicsDamping, the entity still gets rendered, but as soon as I add PhysicsVelocity, all the position data goes to NaN.
Answer by smirk · Apr 24, 2020 at 04:30 PM
BlobAssetReference<Unity.Physics.Collider> spCollider =
Unity.Physics.SphereCollider.Create(new SphereGeometry{Center = 0, Radius = 1});
Unity.Physics.Collider* colliderPtr =
Unity.Physics.Collider*)spCollider.GetUnsafePtr();
entityManager.AddComponentData<PhysicsMass>(
entity,
PhysicsMass.CreateDynamic(colliderPtr->MassProperties, 4)
);
entityManager.AddComponentData<PhysicsCollider>(
entity, new PhysicsCollider{Value = spCollider}
);
I had the same problem and could only fix it using unsafe pointers. Here is the source where I found that example: Creating bodies from scratch But I am not sure if this is a real fix since you will need to enable unsafe mode in player settings.
Answer by Berzerkeer · May 20, 2020 at 11:10 AM
Facing the same issue and the solution won't work for me. Funny thing is that just by adding the PhysicsVelocity component the entity goes straight to NaN hell with all its translation, rotation and LocalToWorld values.
Your answer
Follow this Question
Related Questions
Changing mesh collider's mesh cause objects go into mesh. 1 Answer
How can I do collision detection using Unity Physics (preview) in DOTS workflow? 0 Answers
Rigidbodies won't collide if mass difference is too high 0 Answers
How do I solve the Box Collider (3D) Edge / Corner Collisions problem? 5 Answers
Rigidbody is behaving abnormally when transformed manually 0 Answers