Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Can't Add Script Component to Game Object

Discussion in 'Scripting' started by waynechriss, Dec 25, 2019.

  1. waynechriss

    waynechriss

    Joined:
    Feb 21, 2017
    Posts:
    2
    Yes this question has come up many times but I've yet to find a solution for me. In my Unity scene I created an empty GameObject. I created a C# script, renamed the script and the class name to match the script name. That's it, I've made no other edits to said C# script. Yet I can't even attach this script to the GameObject because of this error (see image). So....how do I add scripts to GameObjects?

    Images showing error in Unity as well as the script in Visual Studio: https://imgur.com/a/vdfyc6D
     
  2. waynechriss

    waynechriss

    Joined:
    Feb 21, 2017
    Posts:
    2
    Solved my problem. Uninstalled Unity Hub and downloaded Unity as its own client. Something about that Hub was screwing up the script compiling but doesn't matter, scripts now attach to game objects.
     
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,151
    Unity hub was not the issue. If you look at the editor, it has a compile time error. This is what keeps you from being able to add scripts to gameobjects. Also note that if there is an asterisk in the tab for a script in VS, that means you haven't saved that script after you've changed something. But either way, in this case your DemoScript is the problem.
     
  4. amitDklein

    amitDklein

    Joined:
    Apr 10, 2017
    Posts:
    20
    You forgot to save your script so the correct name wasn't updated as long as you see the '*' next to your script name the changes wont be loaded