Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Aechy · Jun 19, 2017 at 11:49 PM · animationinstantiateprefabs

Animations on instantiated prefabs not working

I'm trying to make a game where you equip weapons from a hotbar. When a weapon is selected from the hotbar, a prefab for the weapon with a script and an animator is spawned via Instantiate() in the player's "hands". All weapon scripts use an interface that allows the player's script to call methods on them.

The interface methods work correctly, but animations within these methods cause warnings. I'm trying to get a sword to play a swinging animation when the player equips it and left clicks. When equipping it, the sword's draw animation plays correctly, as the state machine would make it do. However, when left clicking, (The "PrimaryDown" method in the sword script) I get a "Animator does not have an AnimatorController" warning, even though the sword has both of those. The AnimatorController state machine has even been configured already.

When placing the sword prefab in the scene and calling PrimaryDown() on it, the animation plays normally. The animation also plays normally when it is told to play from Awake(), even if I instantiate the sword. Why doesn't the animation work when I instantiate the Sword at runtime?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;

 public class Sword : MonoBehaviour, IWeaponFunctions {
     
     Animator myAnim;
 
     void Awake() {
         myAnim = GetComponent<Animator>();
         myAnim.Play("Swing"); //Plays if called from here
     }
     public void PrimaryDown() { //Implementation from IWeaponFunctions interface
         myAnim.Play("Swing"); //But not from here
     }
 
 }

I can provide more details as needed, I'm not sure what would be causing this.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image _dns_ · Jul 21, 2017 at 08:42 PM 0
Share

Hi, It's an old question but I ran into what I think is the same problem: this is a misleading warning message that occurs when using "Animator.Play" on an animator that is disabled (either the GameObject itself, or one of it's parent), or maybe on one that that has never been enabled since instantiated (occurred on 2017.1.0)

Using myobject.gameObject.SetActive(true) (or on the disabled parent) before calling the first "Play" should remove the message.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

170 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to call the animation of prefab 0 Answers

Can the animation editor create local rotational data? 3 Answers

Instantiating multiple prefabs with animations all appear at 0,0,0 3 Answers

How to instantiate and destroy objects with 2d trigger 1 Answer

instantiate prefabs/gameObjects 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges