Amazing diagram attached 
Scenerio:
Two GameObjects are on top of each other. Object1 was moving then stops when its center matches the center of Object2. OnCollision2D and OnTrigger2D never occurred because a variable switch is in play that was set to false preventing it. Once Object1 is lined up with Object2 the variable switch is set to true.
Question:
Now that collisions are again possible between the two objects, will code in OnCollision2D or OnTrigger2D be triggered or has the collision state been skipped and everything is in the OnCollisionStay2D\OnTriggerStay2D state?
Sounds like whatever âa variable switch is in playâ means might affect your answer.
Let us know!
âa variable switch is in playâ = a script on object1 has code saying when its center is equal to the center of object2 set the variable to true allowing collisions between the two objects to occur again.
Maybe I say it this way:
- Object1 has a script that only allows onCollisionEnter2D code to execute if bool isCentered == true
- bool isCentered is set to false at Start()
- Object1 collides with Object2 but nothing happens because isCentered == false
- Once the centers of the two objects align, isCentered is set to true
Iâm wondering if the code in OnCollisionEnter2D will now execute? My thought is it would never execute because the two objects seem like they would be in the OnCollisionStay2D state of collision detection.
Maybe I ask it this way:
Does OnCollisionEnter2D code execute when two colliders touch edges or can it execute if one appears inside of the other without ever touching edges?
When you say this, is it your variable? If so, you know when it will be checked and you know what it will affect because it is your code.
If instead you mean that you are manipulating the physics layer interactive matrix (or individual object layer numbers directly) in order to enable or inhibit the physics system from considering the layers for interaction, and then you change that WHILE they are colliding, I am not sure the documentation specifies what happens, at least based on my reading of the docs.
unity physics interaction matrix
As above but also âŚ
A âvariableâ wonât change what can and does contact and subsequent reporting of collisions so thatâs incorrect or youâre not describing what youâre doing correctly.
Itâs unclear if youâre talking about the callbacks happening or your code running in those callbacks. Thereâs a huge difference. If itâs your code running in them then thatâs entirely your logic so it makes it extra confusing on why youâre asking here as we have no knowledge of it. Youâre not showing any C# code for instance.
You need to be more clear rather than using high-level vague descriptions. If you donât know how to describe stuff then at least provide some script to demonstrate what you mean.
Please use code-tags .