I think you are missing the
World in your path…
get_tree().get_root() returns the root viewport of the scene.
Also, on a second note, i think you shouldnt add user interface as a child of a camera, but instead place the user interface on a canvas layer.
And lastly, why are you setting the user inteerface, added as child of the camera, as the tree current scene?
Thanks a lot!
I want an inventory that moves with the player. To accomplish this, I am playing around with several ideas. One of them was to make it child of the camera - maybe a bit too naive. But up until now I have only created static inventories which pause the game while the user does things inside it.
You mentioned a canvas layer would be a better way to do this. Where should I put it best inside my project structure? Are there best practices for it?
Ciavarie | 2020-09-03 13:39
Ah, i thought it was more like an HUD.
About the canvas layer, you can just put it into the scene as child of world. But is your
UserInterface.tscn inheriting from a control node? Can you share the structure of that scene? You want something to appear in the middle of the screen? and why instancing it on runtime instead of makint it always present, and just changing visibility?
Basically it is a grid of boxes, that shows up when a button is pressed and disappears if it is pressed again. The user interface name is abit far fetched.
Yes, it inherits from a control node. The UI structure is basically this:
Control > TextureRect > VBoxContainer > GridContainer > a bunch of Panesl and texture buttons
I want it to appear in the center of the screen above the player, but the player can still move around.
For the last one: Simply because this possibility did not occur to me - not my brightest moment tbh. I guess this would be much better, performancewise.
Ciavarie | 2020-09-03 14:13
I added the ui to a new canvas layer which I set as child of World. It does not follow the player, viewport or anything. It just stays a static inventory. So I guess i will add it to the Camera and work with changing visibility.
Ciavarie | 2020-09-03 14:28
Thats strange… thats the way i always do user interfaces in all the games, idk why is not working fot you. But whatever works for you, use it! BTW, the original question, about why you couldn’t use
add_child was solved?
Yes, you solved it A severe case of sudden inability to read paths on my side.
I think, it is strange too, because after reading through some stuff, it should work as yous suggested, but just adding it to the camera works as well. My inventory finally does what it is supposed to do.
Ciavarie | 2020-09-03 15:14
Cool! glad yo help.
Yeah, idk why is not working yo you the canvas layer… but as long as it works your way, i think you are good. The problem is that if you add smooth to the camera, probably the child will also move with it the same way.
I do not plan on adding any effect to the camera - it is a pixel art rpg so I do not see the point. As long as everything just moves along with the player, I am fine. So thanks a bunch!
Ciavarie | 2020-09-03 15:38