I've made a progress indicator for my game which should show up on the HUD when something is being built, and I'm positioning it in the _process() method. I've also carefully set it up so that the origin point is at the very base of the progress indicator.

func _process(_delta: float):
	set_position(Game.main.player.camera.unproject_position(target.transform.origin))

The position is correct, and even if I set it to something like Vector2(100, 100) it still works the same way which is that it seems to show up way off screen. If I manually insert it into my scene I see warnings about how it's position is dependent on it's parent.

The parent is just a Container node set to fill up the whole screen.

I hope this was enough information to be able to tell what I'm doing wrong. I'm unsure what the problem could be.

Could you expand the rect section in the inspector and show that too?

I didn't think to show that, it's all default properties. I've done my best not to set anything I don't need to. This is the indicators container node:

Pic 1

This is the progress margincontainer node:

Pic 2

At this stage I just don't understand control nodes, but I have something close to working. The following seems to position it on the screen just in the wrong position.

func update_position(position: Vector3) -> void:
	var vert: Vector2 = Game.main.player.camera.unproject_position(position)
	margin_left = vert.x
	margin_bottom = vert.y

I have been trying to get this to work for over a day now. I'm so tired of looking at it. Using margin_top instead of margin_bottom for example it doesn't move and just stays off at the top of the screen at position 0 I have no idea why.

I assume I'm supposed to be using a node other than a container to position the margincontainer node inside. Like maybe progress should be a margincontainer inside of a margincontainer. So that way I can position the inner margincontainer to be the offset to center it.

Then the outer ones to set the position. Then I guess the container node I'm putting them all inside of, can just be size 0,0... because it doesn't seem to matter anyway.

On the other hand that's already what I have. There is no margin set at all on the progress node, so putting a margin on it is what allows it to be positioned on the screen.

But it's just not quite in the right spot.

Yeah, I think this might be the problem. Since your margin container is the root of a instanced scene it ought to be positioned at 0, 0. Thats whats offsetting it.

Ok so here's what I did.

I switched to just basic Control nodes and abandoned the Container nodes, that seems to have cleared up the issue. I wrapped the progress elements with un-resized Control nodes, and put them into a control node too.

I'll just not use Container nodes.

Doing this I was also able to revert back to using the set_position method.

3 years later