+3 votes

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

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.


in Engine by (54 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.