Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument Null Exception #33

Open
CQVan opened this issue Oct 24, 2023 · 0 comments
Open

Argument Null Exception #33

CQVan opened this issue Oct 24, 2023 · 0 comments

Comments

@CQVan
Copy link

CQVan commented Oct 24, 2023

Ran Into this error and it seems to be from SerializableCallback

ArgumentNullException: Value cannot be null.
Parameter name: _unity_self
UnityEditor.SerializedObject.FindProperty (System.String propertyPath) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindPropertyRelative (UnityEngine.UIElements.IBindable field, UnityEditor.SerializedProperty parentProperty) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.BindTree (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at :0)
UnityEditor.UIElements.Bindings.SerializedObjectBindingContext.ContinueBinding (UnityEngine.UIElements.VisualElement element, UnityEditor.SerializedProperty parentProperty) (at :0)
UnityEditor.UIElements.Bindings.DefaultSerializedObjectBindingImplementation+BindingRequest.Bind (UnityEngine.UIElements.VisualElement element) (at :0)
UnityEngine.UIElements.VisualTreeBindingsUpdater.Update () (at <79c7b132c51745cbae03eebea8111c0e>:0)
UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <79c7b132c51745cbae03eebea8111c0e>:0)
UnityEngine.UIElements.Panel.UpdateBindings () (at <79c7b132c51745cbae03eebea8111c0e>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.UpdateSchedulers () (at <79c7b132c51745cbae03eebea8111c0e>:0)
UnityEngine.UIElements.UIEventRegistration.UpdateSchedulers () (at <79c7b132c51745cbae03eebea8111c0e>:0)
UnityEditor.RetainedMode.UpdateSchedulers () (at :0)

Heres my code just in case

using RDE.Editor.NodeTypes;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[Serializable]
public struct EventCall
{
    public string eventName;
    public UnityEvent eventCallback;
}

[Serializable]
public class DataCallback : SerializableCallback<string> { }

[Serializable]
public struct DataCall
{
    public string dataName;
    public DataCallback callback;
}

public class DialogManager : MonoBehaviour
{
    public DialogTree tree;

    public Image speakerImage;
    public Text textBox;

    public GameObject optionPrefab;

    public List<EventCall> eventCalls;
    public List<DataCall> dataCalls;

    private void Start()
    {
        RunTree(tree);
    }

    public void RunStartCalls(DialogTree tree)
    {
        foreach (string callName in tree.startEventCalls)
        {
            foreach (EventCall call in eventCalls)
            {
                if (call.eventName == callName)
                {
                    call.eventCallback.Invoke();
                }
            }
        }
    }

    public string testCallback()
    {
        return "dfajsd;lfaj";
    }

    private void RunTree(DialogTree tree)
    {
        if(tree.startEventCalls.Length > 0)
        {
            RunStartCalls(tree);
        }

        RootNode root = tree.root;

        if(root.child is DialogNode dialogNode)
        {
            StartCoroutine(DisplayLine(dialogNode, tree));
        }
    }

    public IEnumerator DisplayLine(DialogNode node, DialogTree tree)
    {

        string message = HandleDataCalls(node.speakerMessage);

        Debug.Log(message);

        int currentTypingSpeed = tree.defaultTypingSpeed;

        yield return new WaitForSeconds(currentTypingSpeed);
    }

    private string HandleDataCalls(string speakerMessage)
    {

        int callStart = speakerMessage.IndexOf("${");
        int callEnd = speakerMessage.IndexOf("}");

        if(callStart == -1 || callEnd == -1)
        {
            return speakerMessage;
        }

        string callName = speakerMessage.Substring(callStart + 2, callEnd - callStart - 2);
        string message = speakerMessage.Substring(0, callStart);

        foreach (DataCall dataCall in dataCalls)
        {
            if (dataCall.dataName.Equals(callName))
            {
                message += dataCall.callback.Invoke();
            }
        }

        message += speakerMessage.Substring(callEnd + 1);

        return HandleDataCalls(message);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant