hi, so im following a tutorial which was originally written for unity but im doing it in godot. it is working well so far and im already quite far in. however i’ve stumbled upon a section where the author has decided to implement an update() method in the enemy script, and then in the main game script, there is an array of enemies, and in the Update() method of that script, it iterates over the enemies array and calls update() on each one.
my question is what is more idiomatic to godot and better for performance? im not the most tech savvy person so i dont know how to benchmark this, but my assumption is that since _process() is a built-in Godot function, having that going is going to be faster than calling a custom function (i write in gdscript by the way, and from what i understand from the docs, calling custom functions in gdscript is a lot slower than calling built-in engine functions). also it seems simpler to just have every enemy have its own _process() thing going on, making for less code to take care of in separate scripts
From everything I’ve seen so far, using _process seems to be the idiomatic way of doing it in Godot. I’m pretty new to Godot myself, so can’t comment on the performance implications, but given it appears to be the recommended way I’d assume that factors in performance etc
it depends on what else the enemies are doing. If all enemies are to be updated in every frame, then them having a _process() method would be the way to go. If it’s a turn-based game with the enemies deciding on their actions once per turn, then working with groups, signals, or indirect calls over an array seems most efficient.
thank you for your responses. i think i have a clearer picture now. to be fair, i am deviating a bit from the tutorial i am following. the author follows a very OOP-heavy style, using factories and the like, which i personally like to avoid, and i think for that reason he has to write a bunch of extra code that doesnt make sense as a godot user. i know godot fairly OO oriented as well but i dont think factories are used much? i dont know, id have to take a look at more recent godot tutorials if i can find some
i tried to do it his way but i found issues with the way iterating over arrays in gdcript works a bit differently from how it works in c# i guess. i can muck around with it and somehow get it to work but it is a lot more code, more complicated and a more error prone too. while following the idiomatic godot way of just using groups is a lot simpler