- Home /
OnTriggerEnter called much less often after a player respawn?
First an overview of what components I have:
A script attached to every "Tile" that updates the Player class with a reference to itself and it's position OnTriggerEnter(). With Debug.Log() I see this occur very frequently, multiple times per second.
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag.Equals("Player"))
{
player.currentSubtile = this.gameObject.GetComponent<Subtile>();
player.CenterToSubtile(transform.position);
}
}
The "stuff" the player does with these subtile references is not relevant to my issue. The issue occurs when I respawn the player. The respawn function below receives/parses the position (sent as a hashTable), resets the appropriate boolean flags (I've triple checked every boolean flag), sets the player's position to the respawn point, and clears the movement vector responsible for player movement:
public void PlayerRespawn(NotificationCenter.Notification notf)
{
animator.SetBool("Dead", false);
_playerProperties.aliveP = true;
timer = 1.0f;
Transform spawn;
if (notf != null) {
spawn = (Transform)notf.data[0];
transform.position = spawn.position;
_movementProperties.movementVector = Vector3.zero;
_movementProperties.landed = false;
lerpingToSubtile = false;
movingLeftRight = false;
subtileCenterNeeded = true;
}
}
Now, oddly enough, after a respawn occurs the Debug.Log() of the subtile code posts logs MUCH less frequently, maybe 1 log every 2-3 seconds (down from several every second). It appears as though the OnTriggerEnter collision is being detected less for whatever reason. This obviously causes bugs with the "stuff" that the player class does with the subtile references mentioned above - not having a reference to the "latest" subtile messes up all the things.
I'm really scratching my head on this. It's almost as if setting the player's transform.position to the spawn point's messes with the player gameObject's colliders, which in turn leads to less collisions being detected. Thing is, I have the Scene view open on the other monitor coupled with the Inspector - I've confirmed that no player collider parameters whatsoever (size, position, isTrigger, etc.) are altered on respawn, which would have been super weird anyways since I haven't written any collider altering code anywhere.
Has anyone ran into a similar issue? Where all of a sudden collisions/triggers are just being detected less often, seemingly out of the blue? After a respawn or not?