How to get the GUI coordinates of a game object with another GUI layout than the default one?

Hello!

I would like to make a GUI node follow the coordinates of a game object, even with another GUI layout than the default one.

image

Here’s an extremely simple example of a scene that contains:

  1. A game object (ship)
  2. A GUI node (a little white square)

The following code is used to display the GUI node over the game object:

Ship.script: (where I convert and share the GO’s world position - I’m currently using rendercam to convert world to gui)

function update(self, dt)
	debug.pos_ship_w = go.get_world_position()
	debug.pos_ship_s = rc.world_to_screen(debug.pos_ship_w)
	debug.pos_ship_gui.x, debug.pos_ship_gui.y = rc.screen_to_gui(debug.pos_ship_s.x, debug.pos_ship_s.y, rc.GUI_ADJUST_FIT)
end

Gui.script: (where I position the GUI node)

function update(self, dt)
	local node = gui.get_node("white_square")
	gui.set_position(node, debug.pos_ship_gui)
end

With the Default layout
There are no issues, and I can freely resize the window.
The GUI node (white square) sticks to the game object (ship) position no matter what I do.

When I switch to the iPhone X layout
In this case, the position of the GUI node no longer matches that of the game object.

The issue only occurs with other layouts than Default.

Question
With or without RenderCam (@ross.grams ?), how to get the correct GUI coordinates of a game object with another layout than the default one?