0 votes

I have a function where I create a RectTexture and set its texture and scale like this:

func create_hover_preview(item):
    hover_preview = TextureRect.new()
    add_child(hover_preview)

    yield(get_tree(),"idle_frame")
    hover_preview.texture = item.texture
    hover_preview.rect_scale = Vector2(2,2)

The texture is applied to the node even without the yield but the node is never scaled
but something like this works:

func create_hover_preview(inv_grid:Object, idx:int, item:Item):
    hover_preview = TextureRect.new()
    add_child(hover_preview)

    hover_preview.texture = item.texture
    rescale(hover_preview)

func rescale(hover_preview):
    yield(get_tree(),"idle_frame")
    hover_preview.rect_scale = Vector2(4,4)

Shouldn't both of these work exactly the same? what am I missing?

in Engine by (406 points)

No idea really, though I do notice that in the first example, you're both assigning the texture and scaling it after yielding for idle_frame. In the second example, you're assigning the texture before the yield and then scaling it after.

With that in mind, I wonder if moving the texture assignment to before the yield in the first example makes any difference?

It actually does make a different and putting yield just before setting the scaling works as I intended but I don't understand why. Don't the rest of the lines in the function wait for the yield? Maybe it can't set the scaling before the texture is drawn? But you can set the scale of a RectTexture even if it doesn't have a texture...

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.