Debug throwing exceptions
-
- Posts: 11
- Joined: Tue Feb 28, 2023 3:52 pm
Debug throwing exceptions
Hi! I'm trying to get some C# script to check the dialogue system for the value of a boolean. When a sentence in a conversation is had, the boolean "InLove" turns from false to true and the character follows the player.
I wrote this in the monobehaviour
public bool InLove = DialogueLua.GetVariable("InLove").isBool;
And then later in the Update part of the script wrote this:
if (Lua.IsTrue("(InLove")) {....}
which leads to the script that makes that sprite follow the player.
But I keep getting isdebugbuild exceptions and the program crashes. The actual compiler errors are:
UnityException: get_isDebugBuild is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'FollowLove' on game object 'Danni'.
See "Script Serialization" page in the Unity Manual for further details.
PixelCrushers.DialogueSystem.Lua.RunRaw (System.String luaCode, System.Boolean debug, System.Boolean allowExceptions) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:250)
PixelCrushers.DialogueSystem.Lua.Run (System.String luaCode, System.Boolean debug, System.Boolean allowExceptions) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:129)
PixelCrushers.DialogueSystem.Lua.Run (System.String luaCode, System.Boolean debug) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:139)
PixelCrushers.DialogueSystem.DialogueLua.InitializeChatMapperVariables () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/DB/DialogueLua.cs:119)
PixelCrushers.DialogueSystem.DialogueLua..cctor () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/DB/DialogueLua.cs:88)
Rethrow as TypeInitializationException: The type initializer for 'PixelCrushers.DialogueSystem.DialogueLua' threw an exception.
FollowLove..ctor () (at Assets/Scripts/FollowLove.cs:16)
Do you know what I am doing wrong here? I feel like it's probably something simple about how the C# script is talking to Lua, but I don't know what it is.
I wrote this in the monobehaviour
public bool InLove = DialogueLua.GetVariable("InLove").isBool;
And then later in the Update part of the script wrote this:
if (Lua.IsTrue("(InLove")) {....}
which leads to the script that makes that sprite follow the player.
But I keep getting isdebugbuild exceptions and the program crashes. The actual compiler errors are:
UnityException: get_isDebugBuild is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'FollowLove' on game object 'Danni'.
See "Script Serialization" page in the Unity Manual for further details.
PixelCrushers.DialogueSystem.Lua.RunRaw (System.String luaCode, System.Boolean debug, System.Boolean allowExceptions) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:250)
PixelCrushers.DialogueSystem.Lua.Run (System.String luaCode, System.Boolean debug, System.Boolean allowExceptions) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:129)
PixelCrushers.DialogueSystem.Lua.Run (System.String luaCode, System.Boolean debug) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Lua/Lua Wrapper/Lua Interpreter/Lua.cs:139)
PixelCrushers.DialogueSystem.DialogueLua.InitializeChatMapperVariables () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/DB/DialogueLua.cs:119)
PixelCrushers.DialogueSystem.DialogueLua..cctor () (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/MVC/Model/Logic/DB/DialogueLua.cs:88)
Rethrow as TypeInitializationException: The type initializer for 'PixelCrushers.DialogueSystem.DialogueLua' threw an exception.
FollowLove..ctor () (at Assets/Scripts/FollowLove.cs:16)
Do you know what I am doing wrong here? I feel like it's probably something simple about how the C# script is talking to Lua, but I don't know what it is.
Re: Debug throwing exceptions
Hi,
If not, then don't use Debug.isDebugBuild in any properties or variables that have initializers.
Can you post your FollowLove script?VideoMedicineBear wrote: ↑Mon May 29, 2023 7:18 pmUnityException: get_isDebugBuild is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'FollowLove' on game object 'Danni'.
If not, then don't use Debug.isDebugBuild in any properties or variables that have initializers.
-
- Posts: 11
- Joined: Tue Feb 28, 2023 3:52 pm
Re: Debug throwing exceptions
Hi! Here it is:
using System.Collections;
using System.Collections.Generic;
using PixelCrushers;
using PixelCrushers.DialogueSystem;
using UnityEngine;
using UnityEngine.UI;
using static UnityEngine.GraphicsBuffer;
public class FollowLove : MonoBehaviour
{
[SerializeField]
private GameObject player;
private Rigidbody2D body;
public Vector2 velocity = Vector2.one;
public Vector3 offset = new Vector3(-3, 0, 0);
public bool InLove = DialogueLua.GetVariable("InLove").asBool;
void Awake()
{
body = GetComponent<Rigidbody2D>();
}
void Update()
{
if (Lua.IsTrue("(InLove"))
{
Vector2 toTarget = player.transform.position - transform.position + (offset);
float speed = 1.5f;
transform.Translate(toTarget * speed * Time.deltaTime);
}
}
}
using System.Collections;
using System.Collections.Generic;
using PixelCrushers;
using PixelCrushers.DialogueSystem;
using UnityEngine;
using UnityEngine.UI;
using static UnityEngine.GraphicsBuffer;
public class FollowLove : MonoBehaviour
{
[SerializeField]
private GameObject player;
private Rigidbody2D body;
public Vector2 velocity = Vector2.one;
public Vector3 offset = new Vector3(-3, 0, 0);
public bool InLove = DialogueLua.GetVariable("InLove").asBool;
void Awake()
{
body = GetComponent<Rigidbody2D>();
}
void Update()
{
if (Lua.IsTrue("(InLove"))
{
Vector2 toTarget = player.transform.position - transform.position + (offset);
float speed = 1.5f;
transform.Translate(toTarget * speed * Time.deltaTime);
}
}
}
Re: Debug throwing exceptions
Thanks. This is the offending line:
Try changing your script to:
Code: Select all
public bool InLove = DialogueLua.GetVariable("InLove").asBool;
Code: Select all
using System.Collections;
using System.Collections.Generic;
using PixelCrushers;
using PixelCrushers.DialogueSystem;
using UnityEngine;
using UnityEngine.UI;
using static UnityEngine.GraphicsBuffer;
public class FollowLove: MonoBehaviour {
[SerializeField]
private GameObject player;
private Rigidbody2D body;
public Vector2 velocity = Vector2.one;
public Vector3 offset = new Vector3(-3, 0, 0);
public bool InLove { get { return DialogueLua.GetVariable("InLove").asBool; } }
void Awake() {
body = GetComponent < Rigidbody2D > ();
}
void Update() {
if (InLove) {
Vector2 toTarget = player.transform.position - transform.position + (offset);
float speed = 1.5 f;
transform.Translate(toTarget * speed * Time.deltaTime);
}
}
}
-
- Posts: 11
- Joined: Tue Feb 28, 2023 3:52 pm
Re: Debug throwing exceptions
Thanks so much! That works perfectly.
Really appreciate this!
Really appreciate this!
Re: Debug throwing exceptions
Happy to help!
-
- Posts: 11
- Joined: Tue Feb 28, 2023 3:52 pm
Re: Debug throwing exceptions
Oh now my problem is that Unity is not resetting the bool to false when I play it again after stopping. Do you know how to fix that? The bool is in the dialogue system and is set to start out as false initially, but seems to remember itself as true.
Re: Debug throwing exceptions
Hi,
Are you using an AutoSaveLoad component to automatically save the game state when exiting play mode and restore the saved game state when re-entering play mode?
If not, then it's probably not something directly related to the Dialogue System.
Are you using an AutoSaveLoad component to automatically save the game state when exiting play mode and restore the saved game state when re-entering play mode?
If not, then it's probably not something directly related to the Dialogue System.
-
- Posts: 11
- Joined: Tue Feb 28, 2023 3:52 pm
Re: Debug throwing exceptions
Oh nevermind! I figured out player prefs was saving it. I fixed it.
Thanks again!
Thanks again!