Hi,
I would like to share my NavMeshAgent across various actions in my project. I've implemented the following code in BehaviorTree.cs & SharedNavMeshAgent.cs :
SharedNavMeshAgent.cs :
BehaviorTree.cs :

However, I have multiple actions and I'm unable to link the NavMeshAgent defined in the behavior tree (via the variables window). How can I achieve this?

Currently, the options I see are "dynamic", "none", or manually setting it, which I would prefer to avoid. Do you have any suggestions? It seems to be a type-related issue.
EDIT :
I've also tried this:
And this, but I encountered an error that says:"Accessibility: the base class SharedVariable<NavMeshAgent> is less accessible than the class BehaviorTreeSharedCustomClass3."
Thank you for your assistance.
I would like to share my NavMeshAgent across various actions in my project. I've implemented the following code in BehaviorTree.cs & SharedNavMeshAgent.cs :
SharedNavMeshAgent.cs :
Code:
using UnityEngine.AI;
using BehaviorDesigner.Runtime;
[System.Serializable]
public class SharedNavMeshAgent : SharedVariable<NavMeshAgent>
{
public static implicit operator SharedNavMeshAgent(NavMeshAgent value)
{
return new SharedNavMeshAgent { Value = value };
}
}
BehaviorTree.cs :
Code:
using UnityEngine;
namespace BehaviorDesigner.Runtime
{
[AddComponentMenu("Behavior Designer/Behavior Tree")]
public class BehaviorTree : Behavior
{
public class CustomClass
{
public SharedNavMeshAgent sharedNavMeshAgent;
}
}

However, I have multiple actions and I'm unable to link the NavMeshAgent defined in the behavior tree (via the variables window). How can I achieve this?

Currently, the options I see are "dynamic", "none", or manually setting it, which I would prefer to avoid. Do you have any suggestions? It seems to be a type-related issue.
EDIT :
I've also tried this:
Code:
public class Chasing : Action
{
public SharedTransform sharedTransform;
public SharedNavMeshAgent SharedNavMeshAgent;
public SharedTransform target;
public CustomClass test;
public class CustomClass
{
public SharedNavMeshAgent sharedNavMeshAgent;
}
}
Code:
using UnityEngine;
namespace BehaviorDesigner.Runtime
{
// Wrapper for the Behavior class
[AddComponentMenu("Behavior Designer/Behavior Tree")]
public class BehaviorTree : Behavior
{
[System.Serializable]
public class SharedCustomClass3 : SharedVariable<SharedNavMeshAgent>
{
public static implicit operator SharedCustomClass3(SharedNavMeshAgent value) { return new SharedCustomClass3 { Value = value }; }
}
}
}
Code:
[System.Serializable]
public class SharedCustomClass3 : SharedVariable<navmeshagent>
{
public static implicit operator SharedCustomClass3(SharedNavMeshAgent value) { return new SharedCustomClass3 { Value = value }; }
}
Thank you for your assistance.
Last edited: