playMaker

Author Topic: Issue calling variable on CustomActionEditor wihout DrawDefaultInspector()  (Read 308 times)

coxy17

  • Beta Group
  • Sr. Member
  • *
  • Posts: 352
    • View Profile
Hi,

I am creating a CustomActionEditor and it seems when you try and access a value of a variable without calling DrawDefaultInspector() it throws the following error when adding the script from the actions panel to the FSM for the first time.
"NullReferenceException: Object reference not set to an instance of an object"

If i include the DrawDefaultInspector() I get no errors.

It seems there is an issue with hiding DrawDefaultInspector() and calling variables by reference. ? The culprit is this.... "action.databaseName.Value"

NOTE: if i save and refresh the scene, or click off the FSM and click back into it, the error message goes away.

Code: [Select]
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using HutongGames.PlayMaker;
using HutongGames.PlayMaker.Actions;
using HutongGames.PlayMakerEditor;

using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEditorInternal;

[CustomActionEditor(typeof(PMDTAddRow))]
public class TestCustomEditor : CustomActionEditor
{

private static Testing action;
private bool isDirty = false;

public override void OnEnable()
    {
        action = target as Testing;
    }

    public override bool OnGUI()
    {
        //reset isDirty
isDirty = false;

//blocks everything that follows if in Action Browser (so that no errors happen when getting scene-references)
if(action.Fsm == null || action.Fsm.FsmComponent == null) {
return false;
}

//isDirty = DrawDefaultInspector();

//Example
FsmString _myDatabaseName = EditorGUILayout.DelayedTextField("Database Name", action.databaseName.Value);

return isDirty || GUI.changed;

    }

}