pea
August 28, 2014, 4:19am
1
Odd one. I’m trying to move an anchored object by setting its “Pos X” to a new value. Except, nothing happens.
I’m doing this:
RectTransform myRectTransform = myGameObject.GetComponent<RectTransform>();
Debug.Log(myRectTransform.anchoredPosition);
myRectTransform.anchoredPosition.Set(100,100);
Debug.Log(myRectTransform.anchoredPosition);
The position of the object doesn’t change and the log output is:
(-373.0, -52.0)
UnityEngine.Debug:Log(Object)
(-373.0, -52.0)
UnityEngine.Debug:Log(Object)
Maybe this is because I have a Content Size Fitter and Horizontal Layout Group on there? I’ve tried removing them but no dice… Maybe it’s a bug?
pea
August 28, 2014, 4:43am
2
Got it! This works:
myRectTransform.anchoredPosition = new Vector2(100,100);
Not sure why the Set() method exists? Maybe it’s not the setter method?
3 Likes
Tim-C
August 28, 2014, 6:20am
3
Well you are setting the value on the returned anchored position. It just so happens that it’s a struct though so it gets copied. You are setting the value on some intermittent object and not on the real representation.
2 Likes
pea
August 28, 2014, 6:29am
4
Thank you for the clarification, that makes sense.
It’s great how Unity peeps like yourself are all over this 4.6 beta forum like a rash. This developer is feeling the love.
1 Like