- Home /
Is it possible to disable collisions for separate physics scene?
In my game I use separate scene with physics to simulate future Rigid Body state for Game Objects in main scene. It is useful for AI logic & player projectiles shooting predictions. Simulation scene was intended to be very simple, without any collisions processing, just as physics calculator to get future Rigid Body state for each Game Object that needs it. But, unfortunately, I discovered that over 150 steps of simulation per frame causes significant performance problems. FPS decrees up to 5 frames per second even if I simulate future of just one body per frame. So now I try to optimise. I desided to start from disabling collisions.
.
In this question Physics.IgnoreCollision method was adviced to disable collisions for object. But, as I understand, IgnoreCollision won't give any optimization, this is just additional post-collisions filter.
.
So, the question is - is there any way to disable collisions for specified scene at all?
Do you mean to stop all additive scene colliders colliding with other objects in the initial scene? Physics.IgnoreCollision will work but the physics engine is still calculating all the rigidbodies.
I mean disabling any collisions at scene at all, to prevent physics from for$$anonymous$$g, management and updating of any spacial data structures. Signature of Physics.IgnoreCollision(...) sais "ignore collisions just between two objects" that means that ignored by each other colliders still interact with all other possible colliders at scene and, so, needed to be stored in some spacial data structure.
Actually, I created a small test project to investigate performance issues. Initially scene contains one objects that is simulated 250 steps each FixedUpdate. Rigid body is influenced by constant gravitiy force each step and may be pushed by impulse at start or in some times upon simulation steps. Created test scene shows good performance - 70-80 FPS when simulating 250 steps (simulation in game shows 5-10 FPS on same steps count). So, possibly, problem is not related with physics. If so, I'll put here real cause of performance issues as question answer.
To stop all physics and collisions you can use
GetComponent<Rigidbody>().is$$anonymous$$inematic = true
GetComponent<Collider>().enabled = false
Have you checked the profiler to find whats causing the low fps problem?