Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Shimimple |
Context:
I’m writing a pathfinding algorithm (based on Navigation2D) that allows enemies chasing the player to find a staircase to go up if the player is at a different depth than them (I have a pseudo-3D depths system in my top-down game that behaves basically identically to how it does in Zelda Link to the Past). I have no troubles with my code, moreso curiosity for how one of my scripts will impact performance at lower-levels of code. I have a large Area2D that is instantiated for each enemy that, when the enemy detects that the player is at a different depth level than them, activates, and then gives the enemies’ pathfinding a new target: the first staircase that is picked up by their Area2D.
Actual Problem:
How would the following code impact performance?
func _on_SearchingArea_body_entered(body):
if body.is_in_group(“stairs”):
#rest of code
Would it try to scan every collidable object in the level (that’s roughly the size of the Area2D), or would it skip checking things that aren’t stairs, thus not lagging the game on lower-end machines?
I really haven’t learned much of Godot’s efficiency patterns and what goes on behind-the-scenes, so possibly a quick explanation of how Godot utilises the observer pattern would be what I need.