SkipCtrl - Build Issue

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Caidran
Posts: 20
Joined: Wed Jan 03, 2018 5:02 pm

SkipCtrl - Build Issue

Post by Caidran »

Hi Tony,

Just ran into a bit of a strange one. I'm using a script to skip ahead text to the next response menu from a thread here, couple of slight modifications but nothing major. It has always worked fine however today I have created some content no different than before and figured I'd build and see how it plays.

The skip script stops working when I build and fails to work in both the build and the unity editor until I close the editor and open the project again. This is the full script in use;

Code: Select all

using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;

public class SkipButtonCtrl : MonoBehaviour
{
	
	void Update()
	{
		if (Time.timeScale != 0) {
			
			if (Input.GetKeyUp (KeyCode.LeftControl)) {
13>				SkipToResponseMenu ();
			}
		}
	}

	public bool skip;

	private AbstractDialogueUI dialogueUI;

	private void Awake()
	{
		if (Time.timeScale != 0) {
			
			dialogueUI = GetComponentInChildren<AbstractDialogueUI> ();
		}
	}

	public void SkipToResponseMenu()
	{
		if (Time.timeScale != 0) {
			skip = true;
34>			dialogueUI.OnContinue();
		}
	}

	void OnConversationLine(Subtitle subtitle)
	{
		if (Time.timeScale != 0) {
			
			if (skip)
				StartCoroutine (ContinueAtEndOfFrame ());
		}
	}

	IEnumerator ContinueAtEndOfFrame()
	{
		yield return new WaitForEndOfFrame();
50>		dialogueUI.OnContinue();
	}

	void OnConversationResponseMenu(Response[] responses)
	{
		skip = false;
	}

	void OnConversationEnd(Transform actor)
	{
		skip = false;
	}

}
Any idea why this would stop working after a build? I'm completely puzzled.

I have numbered the two parts where the error below points to.
Errors;

NullReferenceException: Object reference not set to an instance of an object
SkipButtonCtrl.SkipToResponseMenu () (at Assets/SkipButtonCtrl.cs:34)
SkipButtonCtrl.Update () (at Assets/SkipButtonCtrl.cs:13)

When I start to just hit space to skip ahead, the following error appears as well;

NullReferenceException: Object reference not set to an instance of an object
SkipButtonCtrl+<ContinueAtEndOfFrame>c__Iterator0.MoveNext () (at Assets/SkipButtonCtrl.cs:50)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

Cheers
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: SkipCtrl - Build Issue

Post by Tony Li »

Hi,

It's possible that your project has some code that sets Time.timeScale to 0 for your build target, so Awake doesn't cache a reference to the dialogue UI. I recommend replacing this code:

Code: Select all

	private AbstractDialogueUI dialogueUI;

	private void Awake()
	{
		if (Time.timeScale != 0) {
			
			dialogueUI = GetComponentInChildren<AbstractDialogueUI> ();
		}
	}
with this:

Code: Select all

private AbstractDialogueUI m_dialogueUI = null;
private AbstractDialogueUI dialogueUI
{
    get
    {
        if (m_dialogueUI == null) m_dialogueUI = GetComponentInChildren<AbstractDialogueUI> ();
        return m_dialogueUI;
    }
}
Caidran
Posts: 20
Joined: Wed Jan 03, 2018 5:02 pm

Re: SkipCtrl - Build Issue

Post by Caidran »

Superb, thanks Tony.

That fixed the issue, whatever the issue was. I've copied this version of the game elsewhere to try and figure out what caused it at some point.

Thanks again :)
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: SkipCtrl - Build Issue

Post by Tony Li »

Glad to help!
Post Reply