Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Rickers |
I am trying to create a set of buttons which will appear above the players head (A position 2D node). To do this I check how many options the player has, and then add the relevant amount of buttons as children to a VBoxContainer, which is in turn the child of a CenterContainer, who in turn has CanvasLayer as a parent as the root of the scene.
This is instanced within the general Player Scene so that I can easily put the position of the “choice buttons” above the player’s head easily, and when needing dialogue in future I can just call the relevant NPC or player node’s own little dialogue scene and insert relavent Data.
For some reason though, any button that is made a child of the CanvasLayer (regardless of if it is made a child of the CenterContainer, VBoxContainer and so on), seems to act strangely. What I mean is, hovering over the button where it is drawn on screen doesn’t activate the button, I have to hover some area off to the side and below to activate the button, which obviously won’t work for a game.
I don’t know how much the actual code will help, but here is the code for the node where the buttons are added anyway.
func choice_box(conversation,part):
var choices = conversation[part]["choices"]
var count = 0
for i in choices:
count += 1
var button = Button.new()
button.text = i
choices_box.add_child(button)
button.set_name("option_"+str(count))
tween.interpolate_property(choices_container,"rect_scale",choices_container.rect_scale,Vector2(1,1),0.7,Tween.TRANS_QUAD,Tween.EASE_IN_OUT)
tween.start()
My Current solution (I just found) is to change the CanvasLayer to a Node2D and then set the Z index REAL HIGH so that the control nodes can draw over everything else. Now everything works fine.
However, I am still interested as to why the buttons wont work if it’s under a CanvasLayer.
Thanks.