I’m running into a weird issue with my AI character setup. When I drag the AI prefab directly into the scene through the Unity editor, everything works perfectly fine. The character moves around properly and all animations play correctly.
But when I try to instantiate the exact same prefab during gameplay using code, something goes wrong with the AI behavior. The character gets stuck playing the idle animation and won’t transition to walking.
I tracked down the issue to the ground detection system in my character controller script. There’s a function called VerifyGroundContact() that’s failing, specifically this line:
animatorComponent.applyRootMotion = false;
When this happens, my character just slides across the ground instead of playing the proper walk animation. It seems like the ground detection isn’t working when the prefab is spawned at runtime.
I can’t figure out what’s different between placing the prefab in the editor versus spawning it with code. Has anyone else run into this kind of problem before?