Calling ScreenView.Transition(string)

0 votes
asked Sep 11, 2016 in Help by m

Hi, 

I am using EasyTouch to trigger the MaterialUI transition function, but I am getting a null reference error on the line where I call it. 

	public Gesture thisGesture;
	private static bool swiped;
	public static ScreenView screenView;

	void OnEnable () {
		EasyTouch.On_SwipeEnd += On_SwipeEnd;
	}

	void OnDestroy () {
		EasyTouch.On_SwipeEnd -= On_SwipeEnd;
	}


	public void On_SwipeEnd(Gesture gesture){
		if (gesture.isOverGui){
			if (gesture.pickedUIElement == gameObject){
				print ("This works");
				swiped = true;
				StartCoroutine(waitTransition(swiped));
			}
		}
	}

	IEnumerator waitTransition(bool swiped){
		if ( swiped == true) {
			print ("this also works");
			yield return new WaitForSeconds (.05f);
			screenView.Transition ("screenTwo", ScreenView.Type.In);
		}

	}
}

Both print line statements go to the console. I'm getting a Null Reference Error on this line 

screenView.Transition ("screenTwo", ScreenView.Type.In);

What am I doing wrong?

1 Answer

0 votes
answered Sep 13, 2016 by Marius
Hello

Static variables are not thread safe. When you enter a Coroutine you start a new thread.

Consider either passing the screenView as a parameter or fetching it inside the Coroutine.
Welcome to MaterialUI support! Ask us anything :)
...