- Home /
Weird UIScrollRect Behaviour
So, I have some nice code that is working to display a basic tech tree. I'm using the UILineRenderer class that comes with the awesome UI Extensions to do the rendering of lines between the panels of my techs. I'm also using the excellent RectTransformExtension.switchToRectTransform() function to handle the switching around of coordinates that the UILineRenderer needs to work.
The tech tree code works fairly well when I set things up in the editor ahead of time. However, when I set up the tech tree programmatically, I've bumped into a weird bug that I don't understand.
If I'm inside a default scroll window, as provided by default Unity, all the spacing for my line drawings gets shifted by half a screen to the right when initially drawn.
If I click on the GameObject in the hierarchy while the game is running, everything fixes itself. This is because that triggers a function to run thanks to some editor extensions I wrote. This function they call is the exact same function that is used to initialise the tech tree line. If I also take the GameObjects out of the scroll window, everything also fixes itself.
My question is... does anyone understand the inner workings of the ScrollRect and Viewport classes? Clearly something is changing at some point between configuring things programmatically and viewing the UI elements afterwards. About the only other detail that's relevant is that the ScrollRect is inactive when the setup is done and activated afterwards, which might trigger things to happen.
Any pointers on how to handle things would be helpful.
Your answer
Follow this Question
Related Questions
Scroll Rect as bitmap 0 Answers
New UI ScrollRect Sensitivity for mouse wheel and for trackpad. 1 Answer
force scrollrect only to scroll with scrollbar 1 Answer
Scroll Rect in Scroll Rect 0 Answers
How make UI scroll movement effect? 1 Answer