Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Child object always appear in center

Discussion in '2D' started by melmomen, Jan 7, 2017.

  1. melmomen

    melmomen

    Joined:
    Dec 25, 2016
    Posts:
    4
    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
     
  2. supermoof

    supermoof

    Joined:
    Sep 24, 2015
    Posts:
    45
    Try adjusting the Anchor position in the RectTransform of your slider in relation to your game object.
     
  3. jeffreyschoch

    jeffreyschoch

    Joined:
    Jan 21, 2015
    Posts:
    2,634
    Is your Slider a child of a World space canvas? Otherwise it will exist in Camera or Screen space.
     
  4. melmomen

    melmomen

    Joined:
    Dec 25, 2016
    Posts:
    4
    Tried that, didn't work
     
  5. melmomen

    melmomen

    Joined:
    Dec 25, 2016
    Posts:
    4
    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)
     
  6. jeffreyschoch

    jeffreyschoch

    Joined:
    Jan 21, 2015
    Posts:
    2,634
    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.
     
    theANMATOR2b and melmomen like this.
  7. melmomen

    melmomen

    Joined:
    Dec 25, 2016
    Posts:
    4
    Thanks jeffreyschoch, The Canvas component was not set to "World Space".. I fixed that and I managed to set it to right position
     
    jeffreyschoch likes this.