Can we get component only from specified SerializeField object?
For example:
private class AnimatorOnModelFilter : SceneRefFilter<Animator>
{
public override bool IncludeSceneRef(Animator animator)
{
// Get the EnemyController component
var enemy = animator.GetComponentInParent<EnemyController>();
// Check if this animator is on the enemyModel
return enemy != null && enemy.enemyModel != null && animator.gameObject == enemy.enemyModel.gameObject;
}
}
[Header("Core Components")]
[SerializeField, Anywhere] protected Transform enemyModel;
[SerializeField, Child(filter: typeof(AnimatorOnModelFilter))] protected Animator _animator;
Essentially I want to do:
_animator = enemyModel.GetComponent<Animator>();
Is there any better or shorter way to achieve what I want?
Edit:
I think I'll just use OnValidate for such cases, as it's less verbose code.
It would be great if there was some way directly as an attribute.
Can we get component only from specified SerializeField object?
For example:
Essentially I want to do:
Is there any better or shorter way to achieve what I want?
Edit:
I think I'll just use
OnValidatefor such cases, as it's less verbose code.It would be great if there was some way directly as an attribute.