Author Topic: Anchors not working after loading another scene  (Read 5227 times)

TJHeuvel

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Anchors not working after loading another scene
« on: June 20, 2016, 08:57:21 AM »
I have a setup where the UI looks good in the regular game scene, but when i load it through the main menu the anchors are all messed up. We have a fairly complex loading mechanic that first goes through a separate loading scene with a specific UIRoot. After this the regular scene is loaded, with another UIRoot, but everything under this and their panels are placed incorrectly. The loading screen's UIRoot is destroyed after the scene is loaded.

I've tried to call `UpdateScale` on the offending root to no avail.

TJHeuvel

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Anchors not working after loading another scene
« Reply #1 on: June 20, 2016, 11:13:17 AM »
Just to clear a few things up, this is a normal scene: https://gfycat.com/UnrealisticSorrowfulAntelope
When i load it through our loading procedure its like this: https://gfycat.com/IdenticalOffbeatEthiopianwolf

Our loading routine goes like this: In the mainmenu load is called, spawn a new gameobject with a UIRoot that doesnt get killed on scene load. Load LevelLoader scene, that in turn loads the actual scene. When the loading of the scene is done destroy the loading screen UIRoot et all. I've tried to updatescale a frame after destroying the loading uiroot, to no avail. It seems like the width/height of the panel the elements are anchored to isnt updated.
« Last Edit: June 20, 2016, 11:53:38 AM by TJHeuvel »

TJHeuvel

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Anchors not working after loading another scene
« Reply #2 on: June 21, 2016, 03:00:42 AM »
I've found out a little more, its due to the camera's. When i move the old camera to the position of the new camera and then disable all components it everything works fine. When i destroy the new camera it pops back to the incorrect position.

https://gfycat.com/CheerySlushyHerring

*Edit: Found the cause, after destroying our camera some elements dont update their `anchorCamera` reference in UIRect. I've fixed this by destroying the old camera, finding all UIRects and calling UpdateAnchor.  :-\
« Last Edit: June 21, 2016, 03:32:33 AM by TJHeuvel »