Rigid body 2d classes do not work anymore

just as a heads up it would appear when trying to access the “this.rigidbody.velocity” section of this tutorial it would appear that it no longer works in 5.4.0f3. I have tried to get around it using the “GetComponent()” but not figured it out. maybe this could be addressed.


It’s still there in the 5.4 documentation?

Are you trying to retrieve it, or set it?

1 Like

I’m trying to set it, however it appears to be crossed out. I thought this may be because it may not have been attached correctly to the Ball game object but I have checked that and it seems fine.

looking around I have read that it has been depreciated and you have to do it by the “GetComponent()” method but I can’t seem to figure it out.
here is a link to other people mentioning it. http://forum.unity3d.com/threads/rigidbody-property-is-deprecated.309499/


here is the rigidbody2D on the Ball


“This” relates to the script, better form would be gameObject.GetComponent<Rigidbody2D>().


Thanks Joao! :grinning::blush:

This worked perfectly for me, I was missing the “gameObject.”


You are welcome Louis! I’m glad it worked. :grinning:


This worked for me!

I recommend that @ben fixes this within the tutorial by either adding a annotation or possibly editing the video like he did with a few other videos with similar issues.

I know I didn’t need to do this part of the course as suggested in a update from @ben, but I wanted to do this as another form of practice AND I’m a little OCD and want to have it 100% on the course when I finish it. Also if he explains something differently I might catch on it easier than another way.


Hi Aron, thanks for this. I think it may be more confusing to patch this sort of thing. There are two audiences, those who use Unity 4.6 as advised, and those brave souls who use Unity 5.X. The former will be fine, and so are the latter… because they are brave and resourceful :slight_smile:


Was just thinking it could be something to mention for unity 5 developers. Eitherway, I finished the vid now and will start on the rest. Can’t wait to finish Block Breaker and add my own spin on the game too.


Thanks Joao for the solution and Lious for asking the question. I was moving along this course nicely and got stuck here as well. Would have to agree with Aron that perhaps Ben could mention this as a side note for future students, without having to do another video. Anyhow, great course!


As with many others, I too ran headfirst into this, however, it seems by the time of 5.4.2f2, once you put the Unity 4.x valid code in (i.e. this.rigidbody2D.velocity = new Vector2(2f, 10f);), save and return to Unity, it will detect the older API use and ask if you want to automatically update it. If you take the offer it will alter the offending line of code to this.GetComponent<Rigidbody2D>().velocity = new Vector2(2f, 10f);

Unity does only make this offer once however, and if you want to see it again you’ll have to comment out the old code, save, close and reopen the project, uncomment the code and save it, then go back to Unity again.

Thanks for supporting each other on this. Keeping the course relevant without us having to spend a huge amount of time on upgrading it to Unity 5 means we can focus on new content.

The course will be updated at some point, just know that you’re appreciated.

1 Like

I got the API not supported message, but before i could think about i had to suddenly deal with a dog stuck on my neighbours roof.
After 20 minutes in the rain etc, i figured it was just another one of the course “challenges” to update your own code for Unity 5.
I went with the GetComponent on the game object, but using “this”…

if (Input.GetMouseButton (0)) {
print(“mouse clicked”);
hasStarted = true;
Rigidbody2D rigi;
rigi = this.GetComponent();
rigi.velocity = new Vector2(2f, 10f);

1 Like

…don’t you just hate it when that happens… one minute you’re writing code and then the next minute… :smiley: :smiley:

1 Like

Before coming to this course, I’d done a few of the Unity tutorials (Roll-A-Ball, Space Shooter, etc.). As a consequence, I felt confident enough to try and run through the early sections of this course using Unity 5.5. I ran into similar issues as the OP but solved these using AddForce and a publically available speed float for tweaking purposes. It works but…are there any issues I should be aware of using this approach? Code below:

If you are going to use forces you’ll want to handle that using the FixedUpdate() method instead, but you will need to give some consideration with regards to other parts of your code that you don’t want in the FixedUpdate() method.

The following links should be useful. :slight_smile:

See also;

1 Like

Gotcha. Helpful response. Thanks. :slight_smile:

1 Like

You’re welcome Ralph :slight_smile:

Privacy & Terms