Using custom physics engine - Is there a better way than setting localPosition

I am using my own Physics system as I needed a double precision physics, but I’m having performance issues with the way Unity deals with it.

It seams like the process is very slow when I have around 6000 objects within a parent object and I move Only the parent object.

I have no rigidbody in the scene.

When I want to move an object using my physics engine, I set the object’s localPosition in FixedUpdate().

In the profiler I see that the most CPU is on Transform.INTERNAL_set_localPosition()
and it’s number of calls match the total number of child objects plus the parent object.
And it becomes worst as I have more child objects in the object.
Remember I am not moving the child objects here, only the parent, and it does that.

Looks like Unity calculates everything as absolute and when setting an object’s position, all it’s children are also “moved” even though their localPosition has not changed ?

Is there a way to optimize this ?

Also, I tried with and without the “Static” checkbox for all objects… doesn’t make any difference.
What is the difference with or without Static in my case ?

Thank you.

Yeah, Unity has to update all of the transforms when you move the parent. At some point you’re going to need the positions of the child objects so that calculation is inevitable.

However, its much faster if you add a rigid body to the parent (set it to kinematic, as you’ll be controlling the movement with your own phsyics). Then use the rigidbody.MovePosition and rigidbody.MoveRotation to move it about.

Assuming you’re only using the child objects for rendering you could avoid the cost completely by getting rid of them and rendering the meshes manually using Graphics.DrawMesh.