Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

SetSiblingIndex reordering in hierarchy but not in scene

Discussion in 'UGUI & TextMesh Pro' started by jfarias, Oct 9, 2014.

  1. jfarias

    jfarias

    Joined:
    Apr 8, 2014
    Posts:
    53
    Hi!
    I'm having a problem that I hope you can help me with. I'm not entirely sure it's a Unity bug though.

    My object hierarchy is as follows:

    - ScrollRect with mask
    ----- GameObject with a Vertical Layout Group that is the content for the ScrollRect
    ----- ----- Prefabs instantiated at run-time

    The ScrollRect is inside other objects (has 3 parents before the canvas) if that matters.

    The prefabs are instantiated when I drop items from another place inside the scrollrect. I then want to reorder them by dragging and dropping in the desired position. To do that, I use the SetSiblingIndex to reorder them inside the vertical layout group. It works well in the hierarchy but it's not reflected in the scene or the game view.

    Worst part is: I have other 4 situations just like this (2 using grid layout, 1 using horizontal layout and 1 using vertical layout) that work absolutely fine! I cannot find what I'm doing wrong with this one. Is there some reason for the game not to be updated?

    The workaround I found is using
    Code (CSharp):
    1. modulesContainer.gameObject.SetActive(false);
    2. modulesContainer.gameObject.SetActive(true);
    before or after the SetSiblingIndex call.

    This led me to believe it has something to do with its "activeness" but activating it before or after the call, without deactivating it first has no results.

    Other thing to notice, if I scroll after reordering (without the workaround) the objects update and show up in their correct places.

    I tried to reproduce this in an empty project but because I already did this successfully 4 other times, I have no idea how to do it.

    This is on beta 19! Should have pointed it out before. Sorry about that.

    Any thoughts?
     
    Last edited: Oct 10, 2014
  2. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
    Hi,

    I think I am suffering something similar. I believe it is to do with prefabs inside of a layout group that is inactive when the game starts. Try making them not prefabs see if that works..

    Mike
     
  3. jfarias

    jfarias

    Joined:
    Apr 8, 2014
    Posts:
    53
    Hi Mike,

    Thanks for your suggestion but it still doesn't work.

    Also, it should have nothing to do with being inactive when the game starts because I have another situation just like that that works fine. The only difference is that it uses a grid layout and not a vertical layout. This actually gave me the idea of switching the grid for a vertical to see if the problem is with the vertical layout only. Just tested: it's not. It works fine with either a grid or a vertical layout.
     
  4. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
    Ughh really weird. As I am experiencing something similar, let me know if you solve it!
     
  5. Mikeysee

    Mikeysee

    Joined:
    Oct 14, 2013
    Posts:
    155
  6. jfarias

    jfarias

    Joined:
    Apr 8, 2014
    Posts:
    53
    I forgot to say this is on beta 19. I just edited the first post to mention it.

    I tried to port the game to beta 20 but it's breaking all over. I also had the bug you linked then.
     
  7. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    @jfarias Could you report a bug if it hasnt already been done
     
  8. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    Looks like #633152 is the same. And supposedly fixed in b22. :)
     
  9. jfarias

    jfarias

    Joined:
    Apr 8, 2014
    Posts:
    53
    I didn't submit a bug because I couldn't reproduce it in a simple project. Mine is already too big to be of any help. But it looks to be the bug pointed out by ortin, which is already fixed.

    Yeah, seems like it. I searched for ages and couldn't find it. Nice job! :)