Will the line if(raycastHit.collider.tag == "Pickup")
cause heap allocation? Is it building up garbage?
I read in some thread where someone said it does, while PirateNinja said it doesn’t. Something in my code is allocating heap memory according to the internal profiler. The complete code is
if(direction == Globals.North) {
if(Physics.Raycast(transform.position, direction, out colliderHit, 0.5f)) {
if(colliderHit.collider.tag == "Pickup") {
Move();
} else if(passObstacle) {
MoveOverObstacle();
} else if(colliderHit.collider.tag == "Water" walkOnwater) {
MoveOverObstacle();
}
} else {
Move();
}
}
(Yes, the code will be revised and cleaned up soon)
If I spam the button when there is no collider in the way the heap doesn’t move. When there is something in the way it begins too move though, so there is something going on in the code posted.
Oh, and the functions Move and MoveOverObstacle do the same thing (pretty much) and since no heap allocation takes place when moving around those aren’t taking part if the evilness.
I tried a
private const string pickup == "Pickup";
and used that instead of the string in the if-statement. Heap allocation still happenend.