RequireComponent(typeof(Rigidbody2D)) keeps adding Rigidbody2D components.

Hi,

I am running Unity 5.1.1f1 and am learning it.
I found out about “RequireComponent(type)” and tried using it on one of my scripts.
I´ve added

[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(PixelPerfectObject))]
[RequireComponent(typeof(Rigidbody2D))]

All three components are already attached to the game object so I assumed RequireComponent would do nothing.
The first two work fine. If either an Animator or PixelPerfectObject is missing they get added once. If I remove any of them they get added. This was expected.

The Rigidbody2D however, gets added as a new component every single time the game runs, regardless if a Rigidbody2D is already existing or not. So, running the game 10 times adds 10 Rigidbody2Ds. This breaks a lot of stuff. :frowning:

I can´t figure out this behavior and for now have disabled RequireComponent for RB2D. I assumed the RequireComponent would only add if the type is missing but with Rigidbody2D this is obviously not working.

I´ve tried this with the simplest empty script. Added the statements above and attached it to an empty GameObject. Still the same behavior, new RB2D every time while the other two work.

Am I doing something wrong or is this a bug in Unity?

It might be better to null check for the rigidbody instead and add it if its not found.

Have you tried moving the Rigidbody up the list so it is above this script?