I have a problem when it comes to creating custom traits. I have followed what information I could find on the forums and in the documentation, yet when I generate the assemblies used for the AI my custom traits are not used/found.
I have made a script inheriting ICustomTrait and IEquatable, placed it in the namespace AI.Planner.Domains(also tried Unity.AI.Planner.DomainLanguage.TraitBased and AI.Planner.Custom.mynamespace) and I’ve made a assembly definition file referencing the necessary assemblies, as well as a trait asset in sync with the trait script in the same folder as the custom trait.
My script is essentially the same as the location trait as I’ve narrowed it down just to get it working, yet when generating the ai code the generator always creates a new trait. I’m sure I am missing something here but I can’t see what…
My asmdef:
My custom trait, copy of location:
using UnityEngine;
using System;
using Unity.AI.Planner.DomainLanguage.TraitBased;
namespace AI.Planner.Domains
{
[Serializable]
public struct InRangeLocation : ICustomTrait, IEquatable<InRangeLocation>
{
public int transformInstanceId;
public Vector3 position;
public Vector3 forward;
public float range;
public Transform Transform
{
get => null;
set
{
transformInstanceId = value.GetInstanceID();
position = value.position;
forward = value.forward;
}
}
public bool Equals(InRangeLocation other)
{
return transformInstanceId.Equals(other.transformInstanceId)
&& position == other.position
&& forward == other.forward;
}
public object GetField(string fieldName)
{
switch (fieldName)
{
case nameof(position):
return position;
case nameof(forward):
return forward;
case nameof(range):
return range;
}
return null;
}
public void SetField(string fieldName, object value)
{
switch (fieldName)
{
case nameof(position):
position = (Vector3)value;
break;
case nameof(forward):
forward = (Vector3)value;
break;
case nameof(range):
range = (float)value;
break;
case nameof(Transform):
Transform = (Transform)value;
break;
}
}
public override string ToString()
{
return $"Location: {position} {forward} {range}";
}
}
}
Unity 2019.3.1f1
AI-planner 0.2.2
