VS or Unity Inserts 'private' infront of void Update...

I'm using Unity 5.6 and VS Community. I'm doing the Roll a Ball Tutorial on Unity.

In the Moving the Player video he writes:

using System.Collections;
using UnityEngine;

public class PlayerController : MonoBehaviour {

    [B]void Update[/B]() {

    }

   [B] void FixedUpdate[/B]() {

    }

}

But when i try to write the same code, it inserts private -

using System.Collections;
using UnityEngine;

public class PlayerController : MonoBehaviour {

   [B][I] private[/I] void Update[/B]() {

    }

   [B] [I]private[/I] void FixedUpdate[/B]() {

    }

}

Is that correct?

I would like to write the code EXACTLY as I see it written. Can I turn that off so it doesn't insert things like that? Should I turn it off?

Thanks for any input.
And sorry for the millions of questions.

1 Like

void Update()
and
private void Update()

are exactly the same. If you don't declare a method as something else(public, protected, etc), it is automatically private. I'm sure there is a way to turn off the inserting of the word private, but honestly, don't worry about it, it doesn't really matter.

Some like to have private there and others don't, but it doesn't effect how your code works.

6 Likes

It's the rules setup in Visual Studio. as @Brathnann 's writing, they're equivalent - it's just that in the first instance the method's implicitly private, but in the other instance it's explicitly private. Visual Studio's default setup is "automatically be explicit about what accessor (private/public etc.) the method has". You can change that in the formatting rules somewhere in the options.

You can also (probably) turn off "format automatically on return" or whatever, which will make VS only reformat the document when you ask it to. That's often easier to keep track of as a beginner.

3 Likes

Okay great. Thank you for the replies.

And again, sorry for the million questions.

I hope everyone who helped make the switch to Visual Studio a reality, burn in hell.

1 Like

?

You revived a year old thread to say this?

6 Likes


It's just another IDE, dude.

1 Like

Brilliant idea for a name: the JAIDE editor for Unity -- "just another IDE".

I do feel bad for the OP. So many new Unity users assume C# is some Unity-made simple scripting language. They never really understand you can read a real book on it, and that you can't learn it in a few days, and you can google "C# private" outside of Unity forums.

3 Likes

I bet it'd be a little too close to the JADE IDE (ade for alternative development environment):
https://github.com/jgfoster/Jade

Or the JADE programing language and db:
https://www.jadeworld.com/developer-center/download-jade/

Yes, proportionate if irrelevant. Apogees

I think you have a fetish for reviving threads.

5 Likes


Just swap the "J" for a "Y". Calling stuff "Yet Another [insert name]" is popular too. Of course then you can't go around and make the joke that after trying out all these IDEs that you've become a little jaided with the way they're progressing. :P

To change this setting:
Tools -> Options -> Tools for Unity -> General -> Unity Message scope -> Default
Hope this helps someone!

10 Likes

Just late to the party, is all. In this modern day, forums seem a bit like sending letters. It works, but hard to compete with instantaneous responses on IM-thingamajiggs.

It did help me, you are my saviour Tyler. Feeling overly incompetent now, having raged through Visual Studio's options multiple times, yet failing to find that particular option every single time. If I could, I would bury you in likes


Thanks man!

I prefer mine to be set as protected in order to avoid having an inheriting class use the same method and possibly ruining everyone's day. Unfortunately this seems not to be possible to set in Tools for Unity, only private and public are available.

protected won't prevent a redeclare (I also assumed it would). Simply hides it so you need to use base-dot. This is legal:

class AAA { protected int x=3; protected int f() {return 4; } }
class BBB : AAA {
  string x="cow";
  public void f() { print(x+" "+base.x+" "+base.f()); }
}

At least you get a compiler warning IIRC?


thank you for reviving the thread, if you didn't he wouldn't have said how to remove the "private" part of the void autofill! i found it funny how schizo u were but now I appreciate

1 Like


I find 8-letters the best, so many options
downsIDE
homicIDE
overrIDE
misguIDE
monoxIDE
mudslIDE