Updating the GUI from the game world immediately, without a one frame delay (SOLVED)

The GUI health bar follows a game object in my game by passing messages of the game object position. This works, but there is a one frame delay between the game object moving and the health bar updating. This means that when the camera or character move quickly, the health bar is in the wrong place.

I’ve tried to use a module with a callback instead of a message, but because the callback is sent from the module I get a “Node used in the wrong scene” error.

Is there another way of achieving an instant update of the health bar position?

Instead of putting callback in the module, change the position from the player(or whatever it has to follow) and access the position from the module in the gui script.

Eg:

--the module 
local M
M.position = vmath.vector3()
return M

-- in script, the update function 
module.position = go.get_position()

--in gui script.
gui.set_position(healthbar, module.position)
1 Like

Hey, I actually tried this first! There was no difference from sending a message, so I assumed keeping things in the update loop is always delayed one frame. And why I tried to use a cheeky callback instead.

Then I’m at sea now :laughing:

Thinking about this a bit more, I realise I’ve put the coordinate conversion code in the wrong place! It was in game go script, and of course it should have been in the GUI script.

Your solution worked when I moved the code TheKing009! Cheers.

4 Likes