Unarmed as a weapon gets around all this

if there is an unarmed scriptable object that is equipped at default and uses an unarmed override, and used when selecting unarmed later, none of this is necessary because it should never be null…

private void OverrideAnimator(Animator animator)
        {
            if (animatorOverride != null)
            {
                animator.runtimeAnimatorController = animatorOverride;
            }
            else
            {
                Debug.LogError("no animator override on " + name + " SObj, if you meant to leave unarmed, use unarmed override");
            }
        }

That’s a lot of ifs…
In a full published game, you’re likely to create a lot of weapons and a lot of characters. That’s a lot of opportunities to forget to set the animatorOverride. Null Reference Checks are only optional when you know it can never ever be null (example: if you’ve used [RequireComponent(typeof(Health))] in a controller script, you can be assured that the health will be there because Unity won’t let you not have it.

I have a hard time understanding this part. Would setting it to a blank override controller do the same thing?

else
{
animator.runtimeAnimatorController = new AnimatorOverrideController();
}

I would think a blank override controller would be worse. Perhaps experiment and see what happens.

Hi Brian,

I don’t understand what do you mean by alot of ifs? I have the same thought as HeathClose way of doing it as in adding one line Debug.LogError under spawn to check if animatorOverride == null since as you said in a full game we will have lots of weapons and different animations. If we forget to set the animatorOverride and Sam’s solution will change the animation back to default animation which may cause the current weapon to use default animation with no error and easily overlooked, which is most likely not what we intended to and isn’t logerror should give us a better way to prevent that?

I’m actually not averse to the debug.log, and my personal preference is to make sure that there is an animator override on every weapon, even unarmed. I was just pointing out that these sorts of things do happen. Designers sometimes do forget to assign things, and in a very large game, sometimes thing slip through cracks. Having a fallback in case a missed item does get into production is always a good plan.

I think that’s the good way to have an animator override for every weapon. Thanks.

Privacy & Terms