I may be doing something wrong or using the new anchor system in an unintended way, but…
I have a prefab containing a UIPanel with soft clipping anchored to a parent transform, basically set up to fill the screen minus some padding. In the Start method of a component of mine in the prefab, I'm modifying the anchor's absolute values based on some other state, then calling UpdateAnchors on the panel so that GetViewSize will return the correct value:
scrollView.panel.bottomAnchor.absolute += footerPadding;
scrollView.panel.UpdateAnchors();
This causes the following exception:
NullReferenceException: Object reference not set to an instance of an object
UIRect.GetLocalPos (.AnchorPoint ac, UnityEngine.Transform trans) (at Assets/Plugins/Client/NGUI/Scripts/Internal/UIRect.cs:212)
UIPanel.OnAnchor () (at Assets/Plugins/Client/NGUI/Scripts/UI/UIPanel.cs:758)
UIRect.UpdateAnchors () (at Assets/Plugins/Client/NGUI/Scripts/Internal/UIRect.cs:309)
MyClass.Start () (at Assets/Scripts/.../MyClass.cs:344)
I was able to fix the error by modifying UpdateAnchors in UIRect:
public void UpdateAnchors ()
{
if (!mAnchorsCached) CacheAnchors();
if (isAnchored) OnAnchor();
}
I'm not sure if this is the best fix, or if I should be calling something else from my code to get things to recalculate. I need to be able to get the correct size of the scroll view later in my Start method to be able to correctly size and position some other elements.