Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

this.gameObject

Discussion in 'Getting Started' started by pkovacs, Jun 19, 2019.

  1. pkovacs

    pkovacs

    Joined:
    Jun 19, 2019
    Posts:
    3
    Hi, I'm watching a beginners tutorial on using Unity and there's a part in the tutorial about creating your first script I'm stuck at.

    In Unity, the instructor creates a script and then it opens up in Visual Studio. In the void Start () area, he starts typing in this.gameObject and as he types it in, a pop-up opens up with the suggestion "gameObject" which he can click on to complete the word.

    When I try this, I don't get that pop-up and I have to manually type in the whole word gameObject not knowing if Visual Studio is even recognizing it or not. My pop-up just shows a list of generic items like Equals, GetHashCode, GetType, MemberwiseClone, Start, ToString, Update. Any ideas on what's going on this this?

    Also in the tutorial, his Visual Studio is showing the name of his Unity project (ie. FirstUnityProject) whereas my Visual Studio doesn't show my Unity project name... it only shows "C# - Miscellaneous Files".

    I understand I'm using a newer version than the tutorial... I have Unity 2019.3.0a5 and VSC 2019 16.1.3. Maybe the commands are different now?

    Is it possible that VSC is not communicating with my Unity?

    -Pete
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    8,191
    Probably. First of all, you shouldn't be using any "a" (alpha) version of Unity as a beginner. I'm a professional and I don't even jump on those most of the time. Stick to an official release version.

    Secondly, make sure the script you're editing really does derive from MonoBehaviour. If `this` is not a MonoBehaviour, then it probably doesn't have a gameObject member.

    Finally, try just ignoring Intellisense and forging on. It could be that once you've compiled the project once, it will sort itself out.
     
    pkovacs likes this.
  3. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    777
    Your Visual Studio installation may not include the "Game development with Unity" workload.
    1. Launch the Visual Studio Installer.
    2. Under the version of Visual Studio you're using, click Modify.
    3. Under the Workloads section, ensure that Game development with Unity is checked, and if not, check it and then click Modify.
    upload_2019-6-19_10-42-49.png
    upload_2019-6-19_10-43-12.png
     
    pkovacs and JoeStrout like this.
  4. pkovacs

    pkovacs

    Joined:
    Jun 19, 2019
    Posts:
    3
    This seemed to be the problem. I uninstalled everything and just installed the 2019.1.7f1 release which included Visual Studio 2017 15.9.13. Visual Studio now recognizes this.gameObject. Thanks for the suggestion.
     
    Last edited: Jun 19, 2019
    JoeStrout likes this.
  5. pkovacs

    pkovacs

    Joined:
    Jun 19, 2019
    Posts:
    3
    Thanks for the reply... I ended up just re-installing the non-alpha version of Unity and I guess it included the game development stuff for Visual Studio. I didn't get a chance to try your suggestion.