Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    48
    Try adjusting the Anchor position in the RectTransform of your slider in relation to your game object.
     
  3. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    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. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    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
     
    LiterallyJeff likes this.