#Unexpected OnColliderEnter Behavior

1 messages · Page 1 of 1 (latest)

noble stag
#

Hi! I'm having trouble getting OnColliderEnter to trigger when I want it to, and I can't tell why! Here is the code:

void OnCollisionEnter(Collision collision)
    {
        Debug.Log("ANT COLLISION: " + ToString() + " collides with a " + collision.gameObject.name);
        
        Location location;
        LocationType locationType = LocationType.None;
        if (collision.gameObject.TryGetComponent(out location))
        {
            locationType = location.LocationType;
        }

        _pheromoneMachine.CurrentPheromone.OnCollision(collision.gameObject);
    
        if (locationType == LocationType.Colony)
        {
            Colony.Memory.UpdateColonyMemory(Memory);
            Memory.UpdateAntMemory(Colony.Memory);
            
            Debug.Log("ANT MEMORY: " + ToString() + " updates Colony and own memory: ");

            if (Caste.HasNewSequence(_timeOfLastPheromoneChange))
            {
                _pheromoneMachine.SetPheromoneSequence(Caste.PheromoneSequence);
                _timeOfLastPheromoneChange = Time.time;
            }
        }
    }
#

And the problem here is that the first debug string is not getting output even though I am watching teh ant collide with an object. And I see correct output elsewhere. Why would this function only be called sometimes and not others?

#

In my debug I do see: ScoutAnt3 collides with a Colony sometimes, but I don't see it every time this happens.

#

Changed my Ant rigidbody to "Continuous" and it works