- Home /
State object error when implementing Matrix4x4.TRS solution to set resolution independence
I'm trying to set resolution independence by setting my GUI.matrix via the following code:
private float nativeHorizontal = 800.0f; private float nativeVertical = 600.0f;
void Start() { // set resolution independence GUI.matrix = Matrix4x4.TRS( Vector3.zero, Quaternion.identity, new Vector3(1.0f*Screen.width / nativeHorizontal, 1.0f*Screen.height / nativeVertical, 1.0f)); }
Weird thing is, I get the following runtime error:
InvalidOperationException: Operation is not valid due to the current state of the object System.Collections.Stack.Peek ()
I've tried searching for Answers (pardon the pun), but I can't find anything. I don't understand how there could be a "stack" error when call the TRS function. Can anybody enlighten me on this?
Thanks,
Dendro
Answer by StephanK · Sep 20, 2010 at 07:17 AM
The problem is probably that the GUI object is only accessible during the OnGUI function. So probably you would have to move your code from Start() to OnGUI().