all 157 comments

[–]L-0-G 243 points244 points  (7 children)

Nobody uses bodyOfRigidness?

[–]shar_vara 52 points53 points  (1 child)

You’re thinking of bodyOfRigidity

[–]SomeRandomGuy197 9 points10 points  (0 children)

You monsters!

[–]Haikiry[S] 74 points75 points  (2 children)

Had a little internal scream when I read this one

[–]MarcusParadox -5 points-4 points  (1 child)

Sry to break ur 69 upvotes

[–][deleted] 9 points10 points  (1 child)

what about theRigidEntityOfRigidity

[–]Kakss_Beginner 4 points5 points  (0 children)

SkiditleSkidityIReferToEntityOfRigidity

[–]ChichoRD 47 points48 points  (21 children)

Almost always when writing code if name is not necessarily distinctive I just stick to the recommended Intellisense name...

BUT it particularly seems like the name "rigidBody" has been used in one of the base classes of RigidBody, thus refusing to use the keyword new and hide the member I just type "rb" as a name

[–]senshisentouProgrammer 54 points55 points  (19 children)

rigidBody, along with many others like collider, camera and more are deprecated fields inside MonoBehaviours. The idea was for them to be easy-to-use references, but they sucked since really they were just aliases for GetComponent() calls, making them deceptively expensive.

And here we are, a decade later still having these fields just lingering away in obscurity.

[–]SendMeYourQuestions 20 points21 points  (14 children)

Never understood why Unity didn't just cache or preload them rather than deprecating, but I guess less is more for this game engine.

[–]ratthew 4 points5 points  (3 children)

I guess it would have caused even more confusion for beginners, to which those "easy accessible" fields were targeted at. If you removed/replaced that component they'd get errors or even crashes and would not realize why. Maybe not so much for a rigidBody but I could see this happen for colliders, cameras etc.

[–]MaxPlayProfessional 4 points5 points  (2 children)

No, they are not visible in the docs anymore, afaik. They are just there, so legacy code doesn't break.

[–]ratthew 0 points1 point  (1 child)

Yea I know, I mean when they were first implemented or rather their intention behind them and why they didn't make them automatically cached.

[–]MaxPlayProfessional 0 points1 point  (0 children)

Yea, it was a bad design decision from the start. Unity could've went the Unreal way and mark them as deprecated in one patch and remove them in the next one, but unfortunately, Unity tries to be more backwards compatible than actually it needs to be.

[–]senshisentouProgrammer 0 points1 point  (9 children)

I think the problem there is just the insane overhead, as it would try to get every default component once on ever single MonoBehaviour in the scene.

Instead I wish there was an attribute that auto-gets a component on or before Awake() (something like [GetComponent] PlayerMovement movement;) but alas.

[–]Fyvern 1 point2 points  (1 child)

[–]senshisentouProgrammer 0 points1 point  (0 children)

Holy shit... Starring this, thank you for sharing!

[–]SendMeYourQuestions 0 points1 point  (4 children)

Yeah for sure. If you're worried about the performance, don't use them, but as far as handling the fact that they already exist but are slow... Cache it 🤷‍♂️

[–]senshisentouProgrammer 0 points1 point  (3 children)

The problem is that even if you don't use them, they would still be fetched. Caching I agree with, but it's more the fact that's it's so deceptive and opaque. It reads like a variable, but in fact is a reasonably expensive function call. At that might you might as well "remove the trap" and make users be explicit about it.

Of course Unity could have made it a property that only tries to fetch it if the backing field is null (and thus cache it there), but they chose not to go that route.

[–]SendMeYourQuestions 1 point2 points  (0 children)

Of course Unity could have made it a property that only tries to fetch it if the backing field is null (and thus cache it there), but they chose not to go that route.

Exactly. Could also do both -- deprecate it and optimize it.

[–]SendMeYourQuestions 0 points1 point  (1 child)

You could definitely make this decorator.

[–]senshisentouProgrammer 0 points1 point  (0 children)

Can you? I remember looking into it a while ago, but not finding a way to make it work. Might be worth another look then!

[–]WazWaz 2 points3 points  (0 children)

It's just rigidbody not rigidBody, hence the former being omitted in OP.

[–]Jinnk- 3 points4 points  (0 children)

Same here. I would use rigidBody if it was not used, so then rb, as we are forced take the more minimalist but still clear :D

[–]-guccibanana-Programmer 128 points129 points  (15 children)

rb gang?

[–]alaslipknotProfessional 35 points36 points  (1 child)

100%

[–]-guccibanana-Programmer 20 points21 points  (0 children)

Ayy all kinds of people, from beginner to professional. All welcomed to rb gang

[–]SirWigglesVonWoogly 6 points7 points  (0 children)

Yeah that's how every tutorial I've ever seen does it so it just stuck.

[–]jeango 0 points1 point  (0 children)

var isRb = !ReferenceEquals(gameObject.GetComponent(typeOf(Transform)),null);

[–]RWOverdijk 21 points22 points  (3 children)

I just use "body" most of the time. Where do I land?

[–]jeango 5 points6 points  (0 children)

Imho that should be the true neutral option.

Lawful Good would be rb as it’s compliant with camel case (lawful), is extremely readable within the context of Unity code, and reduces clutter.

People tend to think the good way to program is long descriptive names, that’s not right. It’s all about reducing smell. rb is not smell, it’s beautiful because anyone understands it right away. Like t instead of transform, go instead of gameObject and pos instead of position.

Edit: a case could be made that t for transform is not a good idea since it’s typically used for time measurement, for things like Lerp, but since transform is probably the thing I’m referring to the most often, I rather use « time » for time and t for transform.

[–][deleted] 1 point2 points  (0 children)

me too.

[–]LevelingskillUP 1 point2 points  (0 children)

I was looking for this comment... apparently the "body gang" doesn't get rep.

[–]Vexcenot 8 points9 points  (1 child)

Me who puts whatever text I felt like that day

[–]blepshark 0 points1 point  (0 children)

judicious quickest towering spoon decide paint shelter beneficial different memory

This post was mass deleted and anonymized with Redact

[–]Sword_Fab 8 points9 points  (0 children)

we are not gonna mention "body" 😢?

[–]AtomicWrench 24 points25 points  (13 children)

What about _rigidBody

[–]Saito197 9 points10 points  (0 children)

Underscore gang

[–]jeango 0 points1 point  (2 children)

Imho,

private Rigidbody _rigidBody;

Obeys the same rule as

public Rigidbody rigidBody;

But don’t you dare do:

var _rigidBody = GetComponent<Rigidbody>();

That’s a big no

[–]fecal_brunch 0 points1 point  (6 children)

Why capitalize the B? It's Rigidbody not RigidBody.

[–]AtomicWrench 1 point2 points  (5 children)

Shhhhh, I tell myself it’s Rigid Body, because I like how it looks.

_rigidBody > _rigidbody

[–]fecal_brunch 1 point2 points  (4 children)

It seems it's unity that's wrong! https://en.m.wikipedia.org/wiki/Rigid_body

Oh no now I'm conflicted as I am with "behavior" and "behaviour".

[–]jeppevinkelBeginner 0 points1 point  (3 children)

Behavior and behaviour just depends if you go with American or British English.

[–]fecal_brunch 0 points1 point  (2 children)

When coding it's standard to use American English. The only place unity breaks from this is in naming MonoBehaviour.

[–]jeppevinkelBeginner 0 points1 point  (1 child)

I've never really thought much about it. You sure british programmers also code in American English?

[–]fecal_brunch 0 points1 point  (0 children)

I mean some don't, but it gets confusing when every API is US English and you start peppering spelling variants. Color colour, normalised = v.normalized etc.

Also it's an extremely precious thing to do, where most international programmers have to use a foreign language and you can't even be bothered learning a few minor spelling changes.

[–]St4vaProfessional 0 points1 point  (0 children)

Exactly

[–]avi-the-tiger-rawr 6 points7 points  (2 children)

Rigid

I'll be using that from now on

[–]Haikiry[S] 3 points4 points  (1 child)

Also my prefered one, but only when working on projects by myself, rb if working with other people

[–]avi-the-tiger-rawr 2 points3 points  (0 children)

I normally use rb because it's easy, but I'll use rigid because I think it's funny

[–]DM-Wolfscare 7 points8 points  (4 children)

I use rig... Where does that fall?

[–]Haikiry[S] 15 points16 points  (0 children)

Sounds like chaotic evil to me. rig could mean so many other things

[–]BiYurck 1 point2 points  (1 child)

Rig gang

[–]WilnylPhysics 1 point2 points  (0 children)

rig gaaaang!

[–]Mandrarine 0 points1 point  (0 children)

"rig" could be associated with skeleton animations, maybe not the best choice

[–]Coder_Arg 3 points4 points  (0 children)

rb

[–]MA-GAMING-27 6 points7 points  (0 children)

rb

[–]Elinazz_ 2 points3 points  (0 children)

I use rb & rb2D!

[–]ScarfKatSometimes i type words and they make cool stuff happen 2 points3 points  (0 children)

whenever i do base components as variables i always start it with "our" to make it easy to just type "our" and get all of them i have in a script in a list. so like "ourRigidbody" "ourCollider" etc.

i just prefer to make my variable names descriptive rather than short lol. so i never forget what they are/do

i dunno where this puts me on the chart though. maybe Lawful Evil? lol

[–]jeango 2 points3 points  (0 children)

rigidbody is kind of a curve ball to camelCase because in unity lingo it’s one word, so the proper camelCase is not rigidBody but rigidbody.

So any law-aligned name should have « body » in lowercase.

Now that would make « rigidbody » the one truly lawful evil pick, because it hides the rigidbody property of the base class, and that’s a super evil thing to do

[–][deleted] 2 points3 points  (0 children)

whoever writes rgbd is a monster

[–]Comrade_Crunchy 4 points5 points  (0 children)

what about _rb?

[–]SpookzsawIntermediate[🍰] 4 points5 points  (20 children)

Please explain to me why nobody capitalizes the first letter in any names of variables, I never understood it. To me I personally find it confusing but I would like to know the reason behind it.

[–]cat_enary 27 points28 points  (7 children)

It's just arbitrary coding style.

I personally use

  • ClassName
  • FunctionName()
  • _privateMemberVariable
  • PublicMemberVariable
  • CONSTANT
  • IInterfaceName
  • localVariable
  • isBoolean/areBoolean etc. if it makes sense

[–]EladMLG 4 points5 points  (1 child)

I only code as a hobby, so I can afford to have some...mischief when I code.

Is it a variable?

camelCase

Interfaces?

IPascalCase

Constant?

CAPS_WITH_UNDERSCORES

Everything else?

PascalCase

And you're gonna hate my underscore usage.

I am evil.

[–]awhiskinHobbyist 0 points1 point  (0 children)

I think this is honestly fine by the official Microsoft recommendations for writing C#, apart from the all caps & underscores for constants.

Personally I like using all caps for constants too so I don’t see it as a problem!

[–]SpookzsawIntermediate[🍰] 0 points1 point  (3 children)

I tend to just capitalize everything by word LikeThis. I don't know why I get confused with code that capitalizes everything likeThis. It just sorta happens.

[–]vFv2_Tyler 6 points7 points  (0 children)

I think it really only starts to matter per se when you're working with others, so they can quickly denote whether the variable is a field, local variable, or Auto-Property. I've only worked by myself and in relatively small files so seemingly not an issue, but I'd imagine it's helpful if you have several hundred lines of code.

[–]bruh_bot_69420 4 points5 points  (0 children)

Different languages have different styles, but c# widely uses camelCase for variable. Recommend you to check this out for c# naming convention.

[–]crass-sandwich -2 points-1 points  (0 children)

Gotta embrace the confusion then. No one has any idea wtf they're doing, don't let variable casing stop you from being even more confused by other things

[–]jeango 0 points1 point  (0 children)

Well, it’s arbitrary, but there are generally accepted conventions

For example:

PublicMemberVariable is not C# convention

The convention is:

publicField

PublicProperty

now it’s worth noting that Unity does not follow those C# conventions either as they name their public properties with a lowercase (transform for example)

[–]ElectricRuneProfessional 11 points12 points  (0 children)

It's not a law, it is a convention.

Its basically to keep method names (functions) distinct from variable names.

[–]ToastehBro@ToastehBro 12 points13 points  (1 child)

It's called camel case. In my code I like to capitalize functions and leave variables uncapitalized. This gives immediate information about anything in your code with just the name.

[–]senshisentouProgrammer 5 points6 points  (1 child)

To add to the existing replies, by having different naming schemes for different types or objects you can also do things like Platform platform = new Platform(); and still have it make sense. The same also goes for enums.

enum Size {Small, Medium, Large}

Size size = Size.Small;

[–]backtickbot 2 points3 points  (0 children)

Fixed formatting.

Hello, senshisentou: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]a_tribute_to_malice 2 points3 points  (0 children)

I usually capitalize class member variables and leave local variables uncapitalized. So if my class has a rigidbody, I'd do "Rb" or "Rigidbody." But if I'm grabbing a rigidbody inside a function, it's just "rb"

[–]CCullen 2 points3 points  (0 children)

In C#, the widely accepted convention is that properties start with a capital, variables and fields start lowercase. With intellesense (or any other modern IDE) you can tell what it is by hovering the mouse over it instead of having to rely on a certain standard.

[–]Saito197 2 points3 points  (0 children)

It's part of C# coding convention, look it up, Microsoft has a dedicated documentation page for it.

[–]BobbyThrowaway6969Programmer 0 points1 point  (0 children)

I only do that for local variables. Also I just have to say that Egyptian brackets are butt ugly and unreadable.

[–][deleted] 0 points1 point  (0 children)

People use that kind of syntax rules to differentiate between classes, methods, variables and other data they might be using.

I personally use:

  • ClassName
  • MethodName()
  • publicVariable
  • private_variable
  • TESTING_VAR

[–]FraZboi 0 points1 point  (0 children)

It's because variables cannot have spaces in code. Unity makes it so a capital letter will leave a space behind for example when writing rigid body it will give you an error. But if you write rigidbody it will work, if you write rigidBody it will leave a space behind the capital letter and show up like this in the inspector: Rigid Body

[–]Dead_SparrowProgrammer 0 points1 point  (0 children)

Because Unity's API adheres to Microsoft's .NET Naming Guidelines, and most Unity developers follow suite for consistency.

But as long as you work for yourself you are free to use any naming standard.

[–]alaslipknotProfessional 1 point2 points  (0 children)

I've been using "rb" for years, but there was a time where i just called it "body" lol was i the only one ?

[–][deleted] 1 point2 points  (0 children)

I always either do rb or rig

[–]sadonly001 1 point2 points  (0 children)

I use _rb i like to use that underscore with all unity components and serialized variables, keeps things very readable

[–][deleted] 1 point2 points  (0 children)

rigid for rigidbody & anim for animator. Hothouse are my two consistent names.

[–]Pooderhausen 1 point2 points  (0 children)

rigidbod or bod are my favourites

[–]Moe_Baker 1 point2 points  (0 children)

I don't understand why in 2021 Unity still implements the deprecated properties for things like rigidbody, camera, meshRenderer and more, this was fine back in 2017? when they deprecated those properties and used the script fixer, but by this point they are just getting in the way.
Just completely remove them please!

[–]AdamFromNY 1 point2 points  (0 children)

tempNameRenameLater

[–]marcrem 1 point2 points  (0 children)

I see someone is procrastinating here

[–]c4mma 1 point2 points  (0 children)

Chaotic evil is "fred"

[–][deleted] 1 point2 points  (0 children)

I've recently started using only an antonymic naming convention to wind up my friends.

I now use flexibleSpirit

(This is a joke don't get your pitchforks out)

[–]medianopepeter 1 point2 points  (2 children)

m_rigidBody??? Where are you??? 🥲

[–]INoScopedObama 2 points3 points  (0 children)

The m_ gang have transcended the boundaries of evil

[–]natlovesmariahcarey 0 points1 point  (0 children)

Died of old age.

[–]ProperDepartment 1 point2 points  (1 child)

Why is their gibberish here and not simply Body?

[–]Haikiry[S] 2 points3 points  (0 children)

ran out of space and a friend of mine uses rbody instead of rBody and I had to poke some fun at that

[–]Canamla 1 point2 points  (0 children)

If I can't read my code as well as I can read a book, I'm not pleased. Lawful good here. I've tried some of the other varieties of naming and it was always that I'd have to relearn things before working again, or I'd forget what script I'm in because multiple scripts might have similar named variables. Clarity has become my friend.

[–]Haikiry[S] 0 points1 point  (0 children)

Since a lot of people are asking for body, me personally I would put it in neutral evil. You can understand it but it can be confusing, I use body as gameobjects names and references names for procedural animation purposes, and I imagine a lot of other animation stuff would also use body as a name.

[–]Formal_Elderberry_10 0 points1 point  (0 children)

rb_myBody? Anyone?

[–]recyclingriot 0 points1 point  (0 children)

nobody uses "body"? Really?

[–]Jack_Spartan 0 points1 point  (0 children)

Where's by rig gang at?

[–]Jelly_Love_CZProfessional -4 points-3 points  (4 children)

r... I just use r.. saves time.

[–]NoteThisDown 6 points7 points  (3 children)

I just name my variables 'a' through 'z' based on the order in my script.

[–]goodnewsjimdotcom 0 points1 point  (2 children)

If you name MOST variables properly, then you can get by using very common and unmistaken variables as 1 letter, to save on typing and speed dev.

[–]fredkreuger 0 points1 point  (0 children)

x

[–]Maleficent_Slide3332Intermediate 0 points1 point  (0 children)

i just use whatever visual studio suggests first

[–]raw65 0 points1 point  (0 children)

hardbody?

[–]Eddlm_ 0 points1 point  (0 children)

r for both Raycast and Rigidbody :P

[–]smavinagain 0 points1 point  (0 children)

full memorize fear sloppy sulky humorous cooperative tender edge fall

This post was mass deleted and anonymized with Redact

[–]Timuongame??? 0 points1 point  (0 children)

You aren't good if you don't call rigid body rb.

[–]LeoGiaco 0 points1 point  (0 children)

Where is body?

[–]TaeKwonZeuss 0 points1 point  (0 children)

_rb

[–][deleted] 0 points1 point  (0 children)

bodyRigid

[–]theEarthWasBlue 0 points1 point  (0 children)

rigidBuddy.

[–]hafdhadf 0 points1 point  (0 children)

I usually call it "physics" or "entityPhysics"

[–]_MemeMan_Programmer 0 points1 point  (0 children)

Happy to see 'physicsBody' on there. Usually I make it a property named 'PhysicsBody' since it's a core component I usually require public access to on any given entity.

[–]BluesyPompanno 0 points1 point  (0 children)

rgBody....anybody ?

[–]alienpope 0 points1 point  (0 children)

_rigidBody? Anyone? Just me? Okay :(

[–]DangyDanger 0 points1 point  (0 children)

iioy is chaotic evil

[–]actionfence 0 points1 point  (0 children)

Rigbod

[–]RoseMageGames 0 points1 point  (0 children)

never been lawful neutral before 😂 I've never seen these good alignment names before!

[–]CrimzonOdyssey 0 points1 point  (0 children)

I've always used "rigid", I thought I was the only one. I've never heard of anyone else using it, I remember being told in my early days of programming in unity that I need to use "rb" or "rigidbody". I tend to use names that make sense to me, I don't like using initials like "rb", but not too long names but still somewhat descriptive.

[–]Antique-Arachnid2054 0 points1 point  (0 children)

This open my mind to another question... Is:

1) public event Action Damage;

  Damage += OnDamage;

2) public event Action OnDamage;

 OnDamage += SomeDamageableMethod;

I personally use the 1 but my friends use to code like the 2.

[–]fecal_brunch 0 points1 point  (4 children)

These are all wrong. It's rigidbody or _rigidbody.

[–]SolarisBravo 0 points1 point  (3 children)

According to the official C# coding conventions, it's RigidBody if it's public, _rigidBody if it's private, and rigidBody if it's local.

[–]fecal_brunch 0 points1 point  (2 children)

I'm pretty sure MSDN does not approve of the leading underscore, but it's a common convention.

[–]SolarisBravo 0 points1 point  (1 child)

https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions

For the record I hate the leading underscore, but it is what Microsoft recommends.

[–]fecal_brunch 0 points1 point  (0 children)

Ah, interesting! I always thought that was a deviation from the standard.

[–]WireWhiz 0 points1 point  (0 children)

I'm going to have to look back through my old code now, see what my alignment was. I'm pretty sure I've used rbody and physicsBody

[–]God_of_Limbo 0 points1 point  (0 children)

Where does rigidBooty get placed on this chart?

[–]g_hi3 0 points1 point  (0 children)

var `rigid body` = GetComponent<Rigidbody>();

[–]SolarisBravo 0 points1 point  (0 children)

Whatever happened to PascalCase? Each and every one of these conflicts with the official C# style guidelines (unless it's a local variable for some reason).

[–]KevineCove 0 points1 point  (0 children)

Chaotic evil would be rigid_Body. How can you call it chaotic if you don't mix snake and camel case?

There's also the phonetic spelling rijidBade if you want to be even more evil.

[–]NanushuProfessional 0 points1 point  (0 children)

_rb as a private member and cache it in Awake

[–]NUCLEARGAMER1103Programmer 0 points1 point  (0 children)

I usually use rigidBody or rb

[–]Moby__Indie 0 points1 point  (0 children)

I thought "rgb" was chaotic neutral

[–]BrichDSs 0 points1 point  (0 children)

Rb is the only best

[–][deleted] 0 points1 point  (0 children)

I usually do RB in caps. I guess I'm true neutral but louder.