Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by RoleyBaxter · Apr 20, 2014 at 01:14 AM · cameraspriteanimatormissingcomponentexception

MissingComponentException after changing Animator component.

Hi!

I'm having a wierd MissingComponentException that fixes itself efter rebooting Unity. I'll explain...

I have a player-gameobject. It's a 2d-sprite with a walking and running animation. I control this by through an animator component. I also have a main camera that has a "Follow Player"-script. It references my player gameobject to get its position and follows if it leaves a "deadzone", I guess you'd call it. At first everything works as intended, no errors. That's until I make an adjustment in the player-gameobjects animator component. For example, change a float value in a transition for at which speed it should transist to the running animation. Or any other small change it seems. Then at the next play I get this error:

MissingComponentException: There is no 'Rigidbody2D' attached to the "Player1(Clone)" game object, but a script is trying to access it. You probably need to add a Rigidbody2D to the game object "Player1(Clone)". Or your script needs to check if the component is attached before using it. UnityEngine.Rigidbody2D.get_velocity () (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/Physics2DBindings.cs:705) FollowPlayer.FixedUpdate () (at Assets/Scripts/Camera/FollowPlayer.cs:33)

And the FollowPlayer-script on the main camera component stop functioning. (This of course leads to my player running out of the view, which is annoying.) Now, everything goes back to normal if I simply restart the Unity Editor, even if I saved all changes. But that is still annoying. I can't seem to fix the issue, but I think it somehow has to do with the above mentioned reference to "Player1(Clone)". My player gameobject is present in the scene at start, but it is saved as a prefab.

What exacly is going on here? All answers are appreciated. I consider myself a beginner.

I'll also post my FollowPlayer script for reference: (moves camera and zooms out if the player is going fast enough.)


 public class FollowPlayer : MonoBehaviour {
     public float camDeadZoneX;
     public float camDeadZoneY;
     public float moveSpeed;
     public float zoomOutPlayerSpeed;
     public float zoomAspect;
     public float zoomSpeed;
     private GameObject plr;
     private float normalSize;
     private float maxPlrVelo;
     void Start()
     {
         normalSize = camera.orthographicSize; 
         plr = GameObject.FindGameObjectWithTag(Tags.player);
     }
     void Update()
     {
         maxPlrVelo = Mathf.Max(Mathf.Abs(plr.rigidbody2D.velocity.x), Mathf.Abs(plr.rigidbody2D.velocity.y)); 
     }
     void FixedUpdate()
     {
         Vector3 newPosX = new Vector3(plr.transform.position.x, transform.position.y, transform.position.z);
         Vector3 newPosY = new Vector3(transform.position.x, plr.transform.position.y, transform.position.z);
         if(plr.transform.position.x-transform.position.x > camDeadZoneX || plr.transform.position.x-transform.position.x < -camDeadZoneX)
             transform.position = Vector3.Lerp(transform.position, newPosX, moveSpeed*(Mathf.Abs(plr.rigidbody2D.velocity.x)/2f));
         if(plr.transform.position.y-transform.position.y > camDeadZoneY || plr.transform.position.y-transform.position.y < -camDeadZoneY)
             transform.position = Vector3.Lerp(transform.position, newPosY, moveSpeed*(Mathf.Abs(plr.rigidbody2D.velocity.y)/2f));
         if((plr.rigidbody2D.velocity.y > zoomOutPlayerSpeed || plr.rigidbody2D.velocity.y < -zoomOutPlayerSpeed) || (plr.rigidbody2D.velocity.x > zoomOutPlayerSpeed || plr.rigidbody2D.velocity.x < -zoomOutPlayerSpeed))
             camera.orthographicSize = Mathf.Lerp(camera.orthographicSize, normalSize+maxPlrVelo/zoomAspect, zoomSpeed*Time.fixedDeltaTime);
         else
         {
             camera.orthographicSize = Mathf.Lerp(camera.orthographicSize, normalSize, zoomSpeed*Time.fixedDeltaTime);
             if(camera.orthographicSize - normalSize < 0.01f)
                 camera.orthographicSize = normalSize;
         }
     }
 }


Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kFOZ · Dec 13, 2015 at 02:50 PM

Change the tag on your player to something different.

I'm no pro, but this worked. Now I have to edit out 'FindWithTag("Player")' to FindWithTag("plr")' for all of my scripts...

Comment
Add comment · Share
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

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

21 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

Related Questions

Any way to make Animation.Play take effect immediately? 2 Answers

Restoring animations after rescaling objects 0 Answers

Sprite size as a fraction of Viewport size 0 Answers

Avoid/Minimize Sprites extrapolation in 2D while camera changes size 0 Answers

Two Animated Sprites fed into One Shader as Separate Textures? 0 Answers


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