Question about CustomObjectDrawer.

Stas Kostikov

New member
Hi. I have a question about Behaviour Designer Editor (original not pro)

I have code like this:

public class CheckEnemyCooldown : Conditional
{
[AutoSetIfAvailable]
public AINetworkedCharacter Character;

public override TaskStatus OnUpdate()
{
return !this.Character.IsOnCooldown ? TaskStatus.Success : TaskStatus.Failure;
}
}

And what I want that Character field is auto field with suitable value as soon as node added into editor.
Best idea that I come with is this.

[CustomObjectDrawer(typeof(AutoSetIfAvailableAttribute))]
public class AutoSetIfAvailableDrawer : ObjectDrawer
{
}

but as soon as I add this code. I start receiving exception about using new to create MonoBehaviour my guess there some new inside DrawField if I use a custom drawer.

Any way to solve it? Or there is a different way?
 
What is the stack trace of the exception? Have you seen this page on how to create an object drawer? It contains a couple of examples:

 
That message I got in console:
Code:
You are trying to create a MonoBehaviour using the 'new' keyword.  This is not allowed.  MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor ()
Fusion.Behaviour:.ctor ()
Fusion.SimulationBehaviour:.ctor () (at C:/Users/Luke/ExitGames/Fusion2/Fusion/Fusion.Runtime/Components/SimulationBehaviour.cs:23)
Fusion.NetworkBehaviour:.ctor () (at C:/Users/Luke/ExitGames/Fusion2/Fusion/Fusion.Runtime/Components/NetworkBehaviour.cs:51)
Fusion.ReactiveNetworkBehaviour:.ctor () (at Assets/Cortopia/Scripts/Core/ReactiveNetworkBehaviour.cs:16)
Cortopia.Scripts.Character.NetworkedCharacter:.ctor ()
Cortopia.Scripts.Character.AINetworkedCharacter:.ctor () (at Assets/Cortopia/Scripts/Character/AINetworkedCharacter.cs:130)
System.Activator:CreateInstance (System.Type,bool)
BehaviorDesigner.Editor.FieldInspector:DrawField (BehaviorDesigner.Runtime.Tasks.Task,UnityEngine.GUIContent,System.Reflection.FieldInfo,object)
BehaviorDesigner.Editor.TaskInspector:DrawObjectFields (BehaviorDesigner.Runtime.BehaviorSource,BehaviorDesigner.Editor.TaskList,BehaviorDesigner.Runtime.Tasks.Task,object,bool)
BehaviorDesigner.Editor.TaskInspector:DrawTaskFields (BehaviorDesigner.Runtime.BehaviorSource,BehaviorDesigner.Editor.TaskList,BehaviorDesigner.Runtime.Tasks.Task)
BehaviorDesigner.Editor.TaskInspector:DrawTaskInspector (BehaviorDesigner.Runtime.BehaviorSource,BehaviorDesigner.Editor.TaskList,BehaviorDesigner.Runtime.Tasks.Task)
BehaviorDesigner.Editor.BehaviorDesignerWindow:DrawPropertiesBox ()
BehaviorDesigner.Editor.BehaviorDesignerWindow:Draw ()
BehaviorDesigner.Editor.BehaviorDesignerWindow:OnGUI ()
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
 
Hmm, I can actually think of a better solution since you aren't dealing with drawing and instead want to auto assign:

And what I want that Character field is auto field with suitable value as soon as node added into editor.
Couldn't you use the constructor of the task?
 
Back
Top