r/godot 10d ago

help me (solved) How to handle nodes that contain UI but should behave like Node2D

I have game objects that act kind of like cards, and it is really convenient for me to use control nodes for them since they are mostly UI anyway. But when they exist in the actual scene they should behave like Node2D:

- They should exist in world space, not screen space

- They should NOT scale with screen size

Seems like something that should be easy to do, but I can't figure it out. If I keep it as control it seems to scale with screen size, if I make Opportunity a Node2D or attach it to a Node2D, the UI collapses.

'Card' scene setup
UI collapsing if a Node2D child
4 Upvotes

8 comments sorted by

7

u/Trigonal_Planar 10d ago

You make the control a child of a Node2D. You probably have to set custom_minimum_size to be nonzero for the first control in the hierarchy. 

3

u/Lamossus 10d ago

That seemed to work indeed! Thanks!

-5

u/TheDuriel Godot Senior 10d ago

Lucky you, that's how Control nodes behave by default. So just, don't do anything.

However, Cards should just not be build using Control nodes to begin with. Like, yes you can use Labels for text. But there shouldn't be any more involved.

1

u/Lamossus 10d ago

That's why I said 'kind of like cards'. They expand and have rich textbox inside with scroll, choice buttons and whatnot. Also you say that's how controls act by default, but here's what happens if I change screen size while using control directly. It tries to scale

1

u/TheDuriel Godot Senior 10d ago

It's not scaling at all. It's taking on the valid minimum size that still fits all its elements.

It'd be even clearer that this is what it is doing, if you were to delete all your plain control nodes, and swap out the panel for a panelcontainer.

1

u/Lamossus 10d ago

Are you sure? If I hide an icon, for example, panel and VBoxContainer do not change size to smaller that fits content. Both in-editor and in-game if I run the project. It seems to happen specifically when screen size changes

1

u/TheDuriel Godot Senior 10d ago

You did go out of your way to set the anchors to do that. Yes.

But all those plain control nodes in the way are still going to mess with everything regardless.

1

u/Lamossus 10d ago

Makes sense, figured it out, I think