Child object always appear in center

Hello,

Currently I have a 2D game object (Cannon) that contains another UI object (Slider) as a child…
When I start the game in Play mode, The Cannon appears correctly in its right position as supposed.
However the child Slider is always centered in the screen.

Shouldn’t the slider inherit its position from its parent? so it appears relative to it

How to fix that?

Thanks in advance

Try adjusting the Anchor position in the RectTransform of your slider in relation to your game object.

Is your Slider a child of a World space canvas? Otherwise it will exist in Camera or Screen space.

Tried that, didn’t work

My slider is in a Canvas… And the Canvas is a child of the Cannon game object (Prefab)…So when the Cannon game object is spawned the slider should appear beneath it.

However, what happens is that the Cannon is spawned in the right position but the slider is always centered in the screen (Not below the Cannon)

Just so we’re totally clear, the Canvas component is indeed set to “World Space”, and it looks correct if you just drag it out into the scene? It’s possible the event camera needs to be assigned after instantiation.

2 Likes

Thanks jeffreyschoch, The Canvas component was not set to “World Space”… I fixed that and I managed to set it to right position

1 Like