IgnoreLayerCollision not disabling collisions

I’ve been trying to use IgnoreLayerCollision to disable collisions between two different sets of objects within my game but run into a problem where it simply doesn’t disable the physics with hit response and detection still occurring.

        Debug.Log(LayerMask.NameToLayer("projectiles")); // prints 9
        Debug.Log(LayerMask.NameToLayer("Avoid projectiles")); // prints 10
  
        Physics.IgnoreLayerCollision(9, 10, true);
        Physics.IgnoreLayerCollision(10, 9, true);

        Physics.IgnoreLayerCollision(9, 9, true);
        Physics.IgnoreLayerCollision(10, 10, true);

I have tested to make sure i have the correct layers and additionally checked with the Physics defaults and which is set up as expected.
70610-k4c558z-1.png

The objects are all on the right layer as i expect so not totally sure what is going wrong. I am working within a 2D world set up if that affects this.

Thanks in advance

Yeah, I've posted to the forums as well but as yet crickets. I might have to pay for real support or something :). If you're interested in an alternative hacky way of trying to get timing to do with the start of the frame, rather than the end, see my exchange with Owen-Reynolds above. Might be able to use FixedUpdate to get close enough.

1 Answer

1

You use Physic2D for 2D physics. Physics is for 3D physics i.e. Physics2D.IgnoreLayerCollision.

I also presume the collision matrix above is from the 2D physics settings and not the 3D ones.

as i understand things, FixedUpdate() is likely not what you want. it's promise is that in one second it will be called N times, but those N times might be all bunched up together. ie, it's not guaranteed to be called regularly at 1/Nth of a second. did you see the ["VSync Count" option in Quality Settings][1] ? [1]: https://docs.unity3d.com/Manual/class-QualitySettings.html

Elenzil - that is correct. But provided you set the fixedupdate interval to be less than the expected frame duration (16.67 ms on a 60 hz monitor), it is guaranteed (well, as much as anything in Unity is guaranteed) to be the first thing that runs in a given frame. So it should have a very small latency from the start or finish of the monitor's vertical blank period (not actually sure which, the manual isn't clear on this). See the diagram at the bottom of the page in Leuthil's OP.