OnColliisonExit not being called at all?

public class AllCollisionScript : MonoBehaviour 
{	
	public AllSpawnScript ss;

	void OnCollisionEnter(Collision other)
	{
		if (other.collider.tag == "Platform")
		{
			Destroy(gameObject);
			ss.SpawnSinglePlatform();
			Debug.Log("Platform Collision detected");
			AllSpawnScript.platI += 0.8f;
		}
		if (other.collider.tag == "PlatformEnd")
		{
			Destroy(other.gameObject);
			ss.SpawnSinglePlatform();
			Debug.Log("Platform reached END");
			AllSpawnScript.platI += 0.8f;
		}
		if (other.collider.tag == "Player")
		{
			Debug.Log("isKinematic was turned on.");
			this.gameObject.rigidbody.isKinematic = true;
			AllSpawnScript.PlayerOBJChild.parent = AllSpawnScript.PlatformOBJChild;
		}
		
		else
		{	
			return;
		}
	}
	void OnCollisionExit(Collision other)
		{
			if (gameObject.collider.tag == "Player")
			{
				Debug.Log("Exited collision");
			}	
		}
}

Currently, this is my collision script. IT SHOULD unparent the PlayerOBJChild but since that wasn’t working I thought I had it coded wrong or something. Then I tried the Debug thing and realized that it wasn’t even being called at all!

So what is the problem? Does OnCollisionExit even work?

Why are you checking the tag of the collision’s object in OnCollisionEnter and the tag of the object the script is attached to in OnCollisionExit? Shouldn’t they be consistent? Also, when you want to see if something is called, you should put the log statement right at the beginning. If you put it in a conditional, it could be getting called but the conditional is registering as false. Finally, yes, OnCollisionExit works. That would be a pretty big issue if it just didn’t work.

I did smack in inside the OnCollisionExit.

	void OnCollisionExit(Collision other)
		{
			Debug.Log("No Collision Detected");
		}

Wasn’t being called from there.

No the player object will be on and off the platform. If he’s on it he moves along with it.

Well, if OnCollisionEnter is being called but OnCollisionExit isn’t being called, something you are doing in OnCollisionEnter is screwing things up. In these cases, I usually start by commenting all of the code in OnCollisionEnter out. If it works then, I slowly put chunks back in until it breaks. Also, it would help to know the tag of “other” in this scenario, so that I know which path the code is taking in the OnCollisionEnter.

Other is the Platform itself. It checks in 3 cases, if it collides with self,player, and the END.

I’ll try that out. Is there anything that could cause the OnCollisionExit to no trigger?

It’s Kinematic…

I don’t know what your scenario in your scene is but try this: put this code in your script ( call it in update or fixedupdate) and see if it helps

void SlightMovement(){
		
		float x = Random.Range(-0.001f, 0.001f);
		float z = Random.Range(-0.001f, 0.001f);
		
		transform.position = new Vector3(transform.position.x + x, transform.position.y, transform.position.z +z);
}

i have had situations when there’s 2 objects, one (o1) is detecting the other (o2). If o1 is still and o2 comes into collision, everything is fine but if o1 comes near o2 then o1’s detection does not recognize o2.

Well I got it to detect the collision, had the Kinematic turned on…

If “other” is the platform, won’t the first IF statement be taken? In that case, the script destroys gameObject, which is the object it is attached to, along with itself. Am I missing something crucial here? Because it seems to me all this script does it destroy itself and its owner when it touches anything tagged “Platform.” How can it ever get sent OnCollisionExit if OnCollisionEnter destroys it? I’m confused. :face_with_spiral_eyes:

No you got it, now every time it’s destroyed a new one spawns in a place relative to the last platform spawned. Or will once I get to it :P.

And not really, it will only destroy the current object with the tag “Platform” not all.

It wasn’t sending to OnCollisionExit because I turned the Kinimatics on. Which removes all collision include the Enter ones. So it basically ended up eating itself.

In the end I just parented to another sphere object instead. That way the player can still move freely, doesn’t send the platforms flying like crazy apes, and the player doesn’t get destroyed when the parented platform is destroyed. Also that removed the On/Off parent thing I would have had to do.

All right. As long as it’s solved, and I don’t have to go crazy trying to figure that all out right now. :stuck_out_tongue: