Godot Version
4.6.1
Question
Hello there! I’m currently leraning godot and trying to figure out how different nodes work and interact.
I have a very simple concept of a mini-game that pops up as a separate small creen on top of main scene. What you do is blow up balloons by clicking at them, very fancy.
I got the spawning of balloons and destroying them by clicking part, that’s easy enough.
The problem is with the “screen inside a screen” feature.
I am using a ViewportContainer node with SubViewport as a child, which has an area box as a child of it. I also attached a Marker2d as a child of the area as a balloon spawning pont.
Also balloon itself is a separate scene that I create an instance of.
When I run the project, the SubViewport spawns in the middle of the screen, however the balloon itself spawns not where I intended it to, but on the edge of the larger Viewport in a seemingly arbitrary position.
I tried moving the marker around, messed around with layering, watched a couple youtube guides - fellas, I am completely lost.
Sorry if it’s a super basic problem, I would love to figure it out by myself but honestly just don’t know where to even start looking.
Here’s some code (very fancy) and a screenshot of the scene tree:

extends SubViewport
@export var balloon: PackedScene
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("interact"):
spawn_balloon()
func spawn_balloon():
var balloon_instance = balloon.instantiate()
get_tree().root.add_child(balloon_instance)
balloon_instance.global_position = $Area2D/Marker2D.global_position
Thank you in advance for answering!
Need a lot more info to answer that, but the short version is you are placing those objects outside of the SubViewport, you just don’t know that you are. The problem is that SubViewportContainer is a Control, which means its position is relative to the screen using anchors, where the MArker2D is an Node2D and its position is absolute.
Basically you’re making a lot of work for yourself. But since this is an experiment, you need to figure out how to translate the coordinates of the Balloons into the Viewport’s area.
1 Like
From this statement, I’m assuming the SubViewportContainer showing the SubViewport’s output is positioned correctly (in the middle of the screen) while the instantiated balloon_instance is not. Is that correct?
From your code, I can see that the balloon_instance is placed outside the SubViewport while its position is based on Marker2D’s position inside the SubViewport. This leaves me to believe that a difference in space between the two viewports (the root viewport and your subviewport) is causing your issue.
I barely have experience with Godot’s 2D functionality though, so I don’t know how mixed Node2D/Control hierarchy transformations are handled. If they behave in the way I assume, your Marker2D’s global_position is computed from the hierarchy contained inside the SubViewport while the global_position of nodes outside the viewport (i.e. your balloon_instance) is computed from the root hierarchy. If the transform of the SubViewport does not sit at the origin, there will be a discrepancy between the hierarchies which will lead to the results you’re seeing.
Have you tried placing the balloon inside the SubViewport?
I hope it works. Here’s some pages that I found in the docs that might be worth reading.
2 Likes
Have you tried placing the balloon inside the SubViewport?
Yes, and the balloon itself shows, but it doesn’t read inputs. From what I understand, SubViewport is like a “window” from which you can see a part of the world that you normally couldn’t. And by default it can only read inputs from child Control nodes, so you can use it like a mini-map or a surveillance camera or a looking glass or another interface element.
And my ballon instances aren’t sharing transform properties with SubViewport.
I figured out a way how to display balloons “correctly” by spawning them outside of the main Viewport, adding a camera to SubViewport and setting its position to where balloons are. This doesn’t solve the input problem, though. And I don’t see a clear solution.
The only idea I have is to create a CanvasLayer with custom background and put balloons inside. This way, I CAN click on them and they will show on top of everything else, the only issue would be, if I give them ability to float around the screen in random directions, they will not “dissapear” from the screen as soon as they leave their designated area, which doesn’t happen with SubViewport, since it only shows the area that’s directed by the camera I set up.
Sorry for a lot of abstract rambling, there’s not a lot to discuss script vise and Viewport layers and Transform changes is a bit too low level for me to figure out.