is rigidbody2D obsolete?

is rigidbody2D obsolete?

if not what is it there for? is it a quick reference?
if so why is it still around? it keeps people from using the name rigidbody2D as a instance of __R__igidbody2D
also shouldn’t body be __B__ody?

It was a shortcut for GetComponent(), or in this case to GetComponent(), just like .transform is a shortcut for GetComponent(), but unlike a Transform component, objects aren’t required to have a Rididbody, 2D or otherwise. Programmers who were just starting out were using it and getting null reference exceptions because they hadn’t actually added a Rigidbody to the GameObject. They decided to remove all of the ‘possibly null’ shortcuts in more recent versions.

Use GetComponent() instead, be sure to null-check it if there’s a possibility it doesn’t exist, and just cache it to a class member if you need to repeatedly access it in your script.

You can check for null reference exceptions in either case; the reason for making shortcuts accessors obsolete was to help the process of making Unity more modular. If you don’t assume that the physics engine and so on are always present (by having built-in shortcut accessors for everything), you can potentially remove things that aren’t being used.

–Eric

are the developers going to remove the obsolete accessor?
it has no purpose and it just take up the namespace.

Yes, that’s the reason for marking things obsolete. You do that to give people time to stop using it and then eventually remove it, rather than yanking it immediately and breaking lots of code.

–Eric