Gui.set_parent doesn't work (SOLVED)

Hi,
I create dynamically 2 nodes in my GUI: a text node and a box node.
The text node has to be the parent node of the box node.
When the text node moves in the screen, the box node doesn’t appear (and remains still anyway).
Could you help me?
This is the code:

	local node_tondo = gui.new_box_node(message.position, vmath.vector3(80, 80, 0))
	gui.set_texture(node_tondo, "gui")
	gui.play_flipbook(node_tondo, "tondo_punteggio_volante")
	gui.set_adjust_mode(node_tondo, gui.ADJUST_STRETCH)


	local node = gui.new_text_node(message.position, tostring(message.amount))
	gui.set_font(node, "main")														
	gui.set_color(node, vmath.vector4(1, 0, 0, 1))
	gui.set_outline(node, vmath.vector4(0, 0, 0, 0))
	gui.set_adjust_mode(node, gui.ADJUST_STRETCH)
	
	gui.set_parent(node_tondo, node)

	
	gui.animate(node, gui.PROP_COLOR, vmath.vector4(1, 0, 0, 1), gui.EASING_OUT, 0.3)		-- fade in
	gui.animate(node, gui.PROP_OUTLINE, vmath.vector4(0, 0, 0, 1), gui.EASING_OUT, 0.3)
	local offset = vmath.vector3(0, 20, 0)				-- float
	gui.animate(node, gui.PROP_POSITION, gui.get_position(node) + offset, gui.EASING_NONE, 0.5, 0.0, float_done)

Thanks, Marco

1 Like

(Site’s having issues and won’t let me remove this. Sorry about that.)

This looks ok from what I can tell. I’ll give this a try myself in a sec. Need to get on a plane now :slight_smile:

2 Likes

I just ran this code and it works as expected. Do you get any message in the console?

1 Like

I’m unable to reproduce the problem. The box node follows the text node throughout the animation.

What I fail to do is to play the flipbook animation though. It sets the texture but never plays the animation which is very strange… It seems like we may have a bug with flipbook animations and box nodes created using gui.new_box_node(). If you’re experiencing the same thing then the solution would be to have a prefab/template node with the texture and animation set and then clone that instead of using new_box_node(), but that is an aside since you’re not getting the animation to work.

Can you please zip the whole project or a minimal project with the error and share with me (bjorn.ritzl@king.com)?

I was having the same issue reported by @mrduneit with a similar test project.

Using gui.set_parent() on dynamically created nodes would cause the child node to disappear.

After further digging, I found it was related to the position set for the child node. The position becomes relevant to the parent position. Make sure that the childed node, node_tondo in this case has a position of (0,0,0) instead of the same position as the parent (which it will already inherit).

If you want the childed node to keep it’s scene transform after parenting it you can use the new keep_scene_transform flag added in the latest 1.2.135 release.

5 Likes

@decoded: I followed your suggestion, and effectively setting the child position to vmath.vector3(0, 0, 0) works. But now child and parent have the same position, and if I try to give an offset to the position of the child (at least the z cohordinate!) , it disappears newly. @Johan_Beck-Noren: And it doesn’t help supposedly to set the keep_scene_transform to true/false…

You should not change z-value. Keep it at 0 for gui nodes. It is ignored in terms of render order, BUT a z-value outside the range of your projection will not be drawn.

1 Like

Yes - to offset the position you could adjust the x and y coordinates, but as @britzl mentioned - the z value is ignored for gui elements.

Gui elements use layers to manage which element is in front of, or behind the other. I think you would have to manually add the layers to your gui scene, and set the layer for given node with gui.set_layer()

1 Like

Not really. The order of nodes in the outline is the order they are drawn. Top to bottom. You can override this order with layers to improve draw call performance, for instance.

3 Likes

Oh, very nice. I did not know that.

I did know about using layers to do things like, group text nodes for improved draw performance -but, I think that is another topic :smiley:

So, how then would we order these nodes in similar fashion, if they are created programmatically?

1 Like

I think gui.set_render_order and gui.set_layer should help.

2 Likes

Check out GUI scenes in Defold

4 Likes

Thanks for the great support, my issue is solved!

3 Likes