Hey,
I noticed considerable performance drop on mobiles for rather simple setup - 100k cubes in freefall. Just PhysicsBody, no colliders, nothing fancy. Profiler shows that a lot is going on - CreateRigidBodies, CreateMotions, Broadphase, BoundingVolumeHierarchy, RecordDynamicBodyIntegrity etc.
Is it working as intended? With no colliders involved what’s going on with those bounding boxes calculations? I’d expect a much much simpler and faster routine for a mere gravity movement.
On a side note, while exploring the issue I’ve also reproduced a completely opposite bug when simulation just aborts when entities are stripped of colliders (Case 1287541).
Adding a physics body is enough to get a full simulation. Not adding a collider just means you’ll get a “default” one - unit sphere. In your case, if you don’t want physics at a particular point, I’d say move the bodies on your own (in parallel, in a job) and add the PhysicsExclude component to all of them. When you want to have them collide, just remove this component.
Also, the integrity checks can be disabled in an actual game, they are there to help you catch stuff you shouldn’t be doing.
Whoa! Ok, thanks for the clarification!
1 Like
Looks like I spoke too soon. Not adding the collider is actually fine, it will result in null collider and empty AABB. Effectively, you’ll get movement, but no collisions. So that’s expected I assume. Other than the integrity jobs, the rest is fine, we still need create jobs to create runtime data for physics. Also, broadphase doesn’t know there’s no colliders in the scene, it needs to build the tree and while iterating it realizes that there are no colliders.
Makes sense, though I’d expect it to be blazing fast - building up a tree of just one node )
So I ran a custom freefall system test and surprisingly there’s no performance gain at all versus default physics with no colliders.
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup)), UpdateAfter(typeof(ExportPhysicsWorld))]
public class sy_CustomFreefall : SystemBase
{
float timestep;
protected override void OnCreate()
{
base.OnCreate();
var fsss = World.GetOrCreateSystem<FixedStepSimulationSystemGroup>();
timestep = fsss.Timestep;
}
protected override void OnUpdate()
{
var _timestep = timestep;
Entities
.WithName("CustomFreefall")
.WithAll<sc_CustomFreefall>()
.WithBurst()
.ForEach(
(
ref Translation trs,
ref Rotation rt,
ref PhysicsVelocity pv,
in PhysicsGravityFactor pgf
) =>
{
pv.Linear += new float3(0, -9.81f, 0) * _timestep * pgf.Value;
trs.Value += pv.Linear * _timestep;
rt.Value = math.mul(rt.Value, quaternion.Euler(pv.Angular * _timestep));
}
)
.ScheduleParallel();
}
}
That’s kinda strange…
What physics does is - creates the world, quickly builds empty broadphase, no contacts, integrates. I would expect your system to be faster, since it only integrates. If you have a profile capture we can discuss.