optimize windows HUD

ZeltaZelta Posts: 122Member
edited December 2020 in GUI

Hello, im learning gdscript, need some noobie help...

i got many HUD labels (food, resources, etc.) with a simple script for that window labels follow the mouse movement. The main content of the labels is in main scene. But every one of that labels have a script:

Extends Sprite
#food info i.e
func _physics_process(_delta):
position = get_global_mouse_position()

the problem is, every day i got more and more of this little scripts and it's uncomfortable having so many because sometimes I go crazy looking for one.
on the other hand, I don't know how it can affect optimization, would it be better to unify all of them in a single script?

how could I do that?


  • BimbamBimbam Posts: 99Member
    edited December 2020

    would it be better to unify all of them in a single script?

    Absolutely yes. In my experience and I think somewhere in the docs it mentions that every _process/_physics_process has some overhead such that duplicating nods with scripts per node is generally a bad idea.

    I trade off a certain amount of performance for my own coding sanity (ie. in a perfect world, I think you would have a single node/script that calls _process/_physics_process and nothing else, but this would be the horrors to work with).
    So instead I have holder nodes that iterates children to run functions per child, which generally results in a performance boost that scales the more identical child nodes you have, eg:

    ...ignore the fact the children have their own scripts, I ripped their _process functions out but I'm still in the process of optimising (there shouldn't really be ANY area nodes in this scene, but I usually prototype the ugly way then optimise after)

    The phys_timer is more to spread the load across multiple frames. Not ideal for time sensitive UI stuff as it would cause some slight stutter, so ignore that bit.

  • ZeltaZelta Posts: 122Member

    @Bimbam ok i will try unify them, ty

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file