Hello friends,
When I followed the Animator Override Controller lecture initially, the animation did override as intended. However, when we did the refactoring to move things into the weapon scriptable object, it stopped working. The sword instantiates as expected and has its expected stats as set in the Sword asset, but the animation remains as the default.
Here are the relevant pieces of code and screenshots to show how things are hooked up in the editor. Thankfully I can move on without this being resolved, but it bothers me that I can’t figure out what I’ve done wrong in the refactoring.
From Weapon.cs:
public void Spawn(Transform handTransform)
{
if (equippedPrefab != null)
{
Instantiate(equippedPrefab, handTransform);
}if (animatorOverride != null) { Animator animator = FindObjectOfType<Animator>(); animator.runtimeAnimatorController = animatorOverride; } }
Fighter.cs doesn’t pass an animator in since it looked like we could find the object from within the Weapon.sc anyway. Seemed like it would streamline that process, but is that what’s breaking it? If so, why would it? I have stared at this code for almost an hour tracing the process with no luck finding where and why it breaks. I get no errors. Some connection is somehow missing, and I’m putting my hands up.
Appreciate any insights. Thanks!