scene_tree is a variable.
var scene_tree = get_viewport().get_tree()
scene_tree is a variable.
var scene_tree = get_viewport().get_tree()
Thanks....
I think I've worked out an easy method to highlight and click on buttons using the controller and or mouse, I'll post it tonight after work.....
So I created a Script for each of the buttons, then on each of the buttons I set under Node mouse_entered() and mouse_exited() then added the code to the three buttons. Now the Hardware Mouse has control or the Controller has control, and all buttons are clickable....
So I've nearly finished the basic menu system, which I'll post up soon. The only issue I need to resolve is, if I use Viewport setting and keep aspect, in settings. The mouse position doesn't seem to work and controller doesn't work correctly.
Does anyone know how to get mouse position only inside viewport ?
I think get_local_mouse_position() will get the coordinates of the immediate parent.
Yeah I tried that this morning, but didn't fix the problem. I'll post the project file when I get home tonight. The mouse still works fine on changed viewport size, problem happens on controller input....
I'm in Aussie, so I won't be home from work for another 6 hours doh!
Here's the file with faulty Viewport....
https://www.mediafire.com/file/h914xzxkoda0ofb/menu+3.5.1v2.zip/file
Bump.....
Anyone have any idea on how to get the correct mouse position in viewport when the size changes. At the moment as soon as the viewport size is adjusted the mouse position no longer works, then the controller doesn't work correctly anymore ?
What's the issue again?
cursor.position = get_local_mouse_position() print(cursor.position)
Using a print statement like that right after assigning that local mouse position there, I get values printed to the console that are clearly the correct mouse position.
edit: ok, I think I know what your issue is.
The sprite you use for the mouse cursor has it's pivot/origin at the center of the image. You want to have it moved over to the point of the arrow.
Notice on the toolbar the icon in blue? That's the tool for moving the nodes origin/pivot point. In the above screenshot I've already moved it(the red-white cross) to the 'point' of the arrow, but when you open your project and highlight the cursor sprite node you'll see it's still in the middle of it.
Hi All, it's been a while since I've had a play with godot "4" but I'm hoping someone will have an answer for this. So I have a optionsButton and in the picture i have a sprite2d in front of it. the problem is when you open the drop down the sprite2d renders behind it, is there any way to hard code the render layer of the dropdown part of the optionsButton. It's pretty much a deal breaker for me, plus a few other issues with godot so I'm starting to sway back to the old Unity.
Mick in the Node2D>CanvasItem>Visibility you have a top_level
and show_behind
options.
top_level
forces the CanvasItem
to be in front of all nodes without top_level
enabled
.
Thanks for the reply. Yeah I tried that also but made no different. So I quickly built a simple menu in Godot 3.5.3 and it works correctly i.e. Sprite2d in front of options button dropdown with a Z-index +1. Seems maybe the Z-index doesn't work in Godot 4.
Built in Godot 3.5.3 Below.
Mick he Z-index doesn't work in Godot 4
It does? why did you make a test scene in 3 and not in 4?
there's something else wrong with the other nodes, or a change to the way dropdown menus work, which would make sense because you want the dropdowns on top of the other scenes, so it would have top_level enabled, but this is speculation.
you can still access the dropdown from code.
after a very quick research, dropdown
is a window
, a viewport
, not a canvasItem
. It will ALWAYS render on top.
If this is for a cursor, godot 4 lets you set a custom cursor:
https://docs.godotengine.org/en/stable/tutorials/inputs/custom_mouse_cursor.html
otherwise use a viewport
inherited node to render on top, not a CanvasItem
.
During searching on Google, I remembered a post on another forum stating that the Z-index doesn't seem to work in Godot 4. So I thought I'd quickly try and see if it worked in Godot 3.5.3 which it does. But its not upgradable to Godot 4, the order issue returns.
I realize that Godot 4 has a custom cursor, but my implementation is for a Virtual Cursor that is controlled with either Gamepad joystick or Mouse. The reason for using a Virtual Cursor is because if I eventually port to Console, the normal windows cursor isn't transferable.
kuligs2 It's annoying because I have spent time making a good controller system with auto change between Mouse and Joystick, only to be hit with this problem.
Yeah to see it working in 3.5.3 perfectly then I did the upgrade on the project to 4.1.2 and now not working.
Oh well maybe someone will come up with a solution.......... My brain has turned to mush.....
Mick I already told you how to do it
Jesusemora otherwise use a viewport inherited node to render on top, not a CanvasItem.
What do you want pictures? here are your pictures, I did this just now in 5 minutes:
Jesusemora Thats a good try, but your cant click thought it even with mouse passthrough selected.
Mick ok I'm sorry man.
I found a different solution that you will like more:
put the menuButton and whatever needs to spawn a popup or window, all inside a subviewport, inside a subviewportcontainer
set embed subwindows to true. this will make the popups spawn as controls instead of OS windows
it works and you can click through and it works with sprite2D
maybe put the entire game inside a subviewport and put the sprite2D for the cursor outside.
Jesusemora Sorry been away. That does work, thanks man.
I did also send a bug to Godot to see if the issue can be fixed permanently, we'll see what happens.....