Custom SceneEventQuestAction
-
- Posts: 11
- Joined: Tue Nov 28, 2023 9:36 am
Custom SceneEventQuestAction
Hello! I'm wondering if it would be possible to create a custom SceneEventQuestAction, that doesn't just contain the onExecute UnityEvent field. I tried to modify the QuestMachineSceneEvent class to include more fields, but they are not showing in the editor ui.
Re: Custom SceneEventQuestAction
Hi,
You can create your own quest actions -- no need to modify existing ones. Duplicate QuestActionTemplate.cs, move it into your own scripts folder, and fill in the code where indicated.
You can create your own quest actions -- no need to modify existing ones. Duplicate QuestActionTemplate.cs, move it into your own scripts folder, and fill in the code where indicated.
-
- Posts: 11
- Joined: Tue Nov 28, 2023 9:36 am
Re: Custom SceneEventQuestAction
Hello,
That's what I did first time but I noticed that I cannot drag and drop scene objects into the declared fields. I suppose it's a limitation of how these classes are handled, and thats why there is a separate SceneEventQuestAction.
So my question is would it be possible to create custom scene event quest actions other than the default?
That's what I did first time but I noticed that I cannot drag and drop scene objects into the declared fields. I suppose it's a limitation of how these classes are handled, and thats why there is a separate SceneEventQuestAction.
So my question is would it be possible to create custom scene event quest actions other than the default?
Re: Custom SceneEventQuestAction
Sure! Here's an example subclass that also logs a message to the Console when it runs the quest action:
CustomSceneEventQuestAction.cs
And in an Editor folder:
CustomSceneEventQuestActionEditor.cs
CustomSceneEventQuestAction.cs
Code: Select all
using UnityEngine;
namespace PixelCrushers.QuestMachine
{
public class CustomSceneEventQuestAction : SceneEventQuestAction
{
[SerializeField] private string m_logMessage;
public string logMessage => m_logMessage;
public override void Execute()
{
base.Execute();
Debug.Log(logMessage);
}
}
}
CustomSceneEventQuestActionEditor.cs
Code: Select all
using UnityEditor;
namespace PixelCrushers.QuestMachine
{
[CustomEditor(typeof(CustomSceneEventQuestAction), true)]
public class CustomSceneEventQuestActionEditor : SceneEventQuestActionEditor
{
protected override void Draw()
{
base.Draw();
if (serializedObject == null) return;
serializedObject.Update();
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_logMessage"), true);
serializedObject.ApplyModifiedProperties();
}
}
}
-
- Posts: 11
- Joined: Tue Nov 28, 2023 9:36 am
Re: Custom SceneEventQuestAction
Hi,
Thank you, I was missing the Editor folder part. Just for completeness sake, this is what I needed to include to be able to drag-and-drop a scene game object:
Also, placing the editor script in the Editor folder is not optional - I did not know that.
Thanks for the help!
Thank you, I was missing the Editor folder part. Just for completeness sake, this is what I needed to include to be able to drag-and-drop a scene game object:
Code: Select all
var t = target as Custom;
t.gameObject = (GameObject) EditorGUILayout.ObjectField(t.gameObject, typeof(GameObject), true);
Thanks for the help!
Re: Custom SceneEventQuestAction
Glad to help!
Yes, any scripts that add custom Unity editor functionality must be inside an Editor folder hierarchy.
Related, if any scripts that are outside of an Editor folder reference any Unity editor namespaces (e.g., "using UnityEditor;"), Unity won't be able to build the project to an executable. Just for future reference.
Yes, any scripts that add custom Unity editor functionality must be inside an Editor folder hierarchy.
Related, if any scripts that are outside of an Editor folder reference any Unity editor namespaces (e.g., "using UnityEditor;"), Unity won't be able to build the project to an executable. Just for future reference.