Author Topic: Turning off UIAnchors at runtime.  (Read 3638 times)

catlard

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 24
    • View Profile
Turning off UIAnchors at runtime.
« on: June 13, 2014, 05:03:58 AM »
I'm trying to figure out the correct way to turn off UIAnchors at runtime. I've tried assigning null to the anchorpoints' targets as such:

  1.                 _widget.updateAnchors = UIRect.AnchorUpdate.OnEnable;
  2.                 _widget.rightAnchor = null;
  3.                 _widget.leftAnchor = null;

But this results in an error that seems to occur in the update function. The error states:

Quote
NullReferenceException: Object reference not set to an instance of an object
UIRect.get_isAnchored () (at Assets/FromAssetStore/NGUI/Scripts/Internal/UIRect.cs:261)
TweenPosition.set_value (Vector3 value) (at Assets/FromAssetStore/NGUI/Scripts/Tweening/TweenPosition.cs:41)
TweenPosition.OnUpdate (Single factor, Boolean isFinished) (at Assets/FromAssetStore/NGUI/Scripts/Tweening/TweenPosition.cs:60)
UITweener.Sample (Single factor, Boolean isFinished) (at Assets/FromAssetStore/NGUI/Scripts/Tweening/UITweener.cs:335)
UITweener.Update () (at Assets/FromAssetStore/NGUI/Scripts/Tweening/UITweener.cs:242)
UITweener.Start () (at Assets/FromAssetStore/NGUI/Scripts/Tweening/UITweener.cs:158)

And points to the targets of the anchors being null, it seems.

The reason why I'm doing this (or trying to) is because I have a bunch of photos laid out in a grid -- I'm using a scrollview and adding horizontal rows of photos as prefabs. In order to keep the photos at a good distance from each other, regardless of screen size, I'm using anchors to get them seperated from each other at start. But the user has to be able to cause the photos to go full screen, and if they're anchored (even if it's only anchoring on enable), the tweening to a full screen size acts funny. So I'm trying to start with an anchored UITexture to get the positioning correct, but then turn them off. Here's what I'm trying to accomplish -- I've got it laid out, but it doesn't work correctly because of the anchoring issue, I think.

http://imgur.com/KPEy4aG

Am I going about this in the right way? And if so, how can I turn off the anchors?


Cheers,

Simon
« Last Edit: June 13, 2014, 05:28:17 AM by catlard »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Turning off UIAnchors at runtime.
« Reply #1 on: June 13, 2014, 05:50:24 AM »
widget.rightAnchor.target = null;
widget.leftAnchor.target = null;

catlard

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: Turning off UIAnchors at runtime.
« Reply #2 on: June 15, 2014, 09:01:47 PM »
Thanks, ArenMook! That was it.