How to get image size from gui?

Hi i’m trying to get the size of an image of gui node, but the returned size is always wrong

local node = gui.get_node(node_id)
gui.set_texture(node, 'sometexture')
gui.play_flipbook(node, 'someimage')
gui.set_size_mode(image_node, gui.SIZE_MODE_AUTO)
local size = gui.get_size(node)

Somehow gui.get_size always returns a vmath.vector3(512,512,0) or vmath.vector3(512,256,0)

Just wondering is there an ideal way to get the image size of a gui node? I want to make the image fit the parent node

Thank you for the help

In my experience, for auto size mode, it takes a bit time to reflect the texture size, so you can try to use timer.delay to see

1 Like

Correct. There will be a one frame delay before the size is updated.

1 Like

I’ve tried using timer delay, but it takes 1 second delay or more before the size is updated

Is there anyway to force the size update to be faster ?

Thank you

Really? I can get correct size with a timer.delay(0.01, …) so I think it should be less than 1s. Maybe a frame later as britzl said

try use msg.post for get size in new frame - weird but work . if you change go pos and try get pos this work too

The problem has been solved.

The problem only appears on existing node, in my test it took 1 second to really change the size.

So my solution, is to make a new node and set the image within the new node, this method is faster and requires no timer.delay

It will take one frame. Not one second.

This is interesting. So you are saying that this works:

local pos = vmath.vector3(0)
local size = vmath.vector3(1)
local node = gui.new_box_node(pos, size)
gui.set_texture(node, "my_atlas")
gui.play_flipbook(node, "my_animation")
gui.set_size_mode(node, gui.SIZE_MODE_AUTO)
local new_size = gui.get_size(node)
print(new_size) -- correct size?

But this doesn’t?

local node = gui.get_node("my_node")
gui.set_texture(node, "my_atlas")
gui.play_flipbook(node, "my_animation")
gui.set_size_mode(node, gui.SIZE_MODE_AUTO)
local size = gui.get_size(node)
print(size) -- wrong size?


Yes, in my case creating new_box_node returns the real image size without needing to wait

For the old new image node, I’ve tried waiting 0.5 second with timer.delay, but the resulting size is still wrong. In my case the delay must be set to 1s.

Note: the old image node is inside a template

But the problem is now solved, I can just create new_box_node, get the image size and delete the new node