Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

The script don't inherit a native class that can manage a script

Discussion in 'Scripting' started by HumphreyGames, Nov 25, 2020.

  1. ANDRAGOR82

    ANDRAGOR82

    Joined:
    Mar 13, 2021
    Posts:
    2
    Hey I'm working on a unity project for the first time and i have the same error

    upload_2021-3-14_9-43-28.png
     
  2. ANDRAGOR82

    ANDRAGOR82

    Joined:
    Mar 13, 2021
    Posts:
    2
    FIX:


    The name of your script has to match the name of the script in the code mine is called "PlayerMovement"
    and the public class ***** : Monobehavior
    }

    The **** has to be called PlayerMovement to match the name of the script

    upload_2021-3-14_9-55-0.png
     
    jbreeze likes this.
  3. unity_TAiqdpTmV2Lmug

    unity_TAiqdpTmV2Lmug

    Joined:
    Feb 4, 2021
    Posts:
    1
    [QUOTE="joshuahalls13,
    spell the name of the script and monobehavior class right i spent 2 years doing this
     
  4. kewkumb67

    kewkumb67

    Joined:
    Feb 15, 2016
    Posts:
    1
    That was really nice of you to do!
     
  5. Kewlife

    Kewlife

    Joined:
    Apr 12, 2016
    Posts:
    6
    I made a quick fix when this happened, create a new scrpt, add it to your gameobject, paste your old script into your newly added code.
     
  6. Panakvina

    Panakvina

    Joined:
    Mar 17, 2021
    Posts:
    2
    Make sure, that the name of file is not same as name of any function in your scripts
     
  7. SrBear000

    SrBear000

    Joined:
    Mar 21, 2021
    Posts:
    1
    see if you have spaces somewhere in the nemo of script, or create new script added next changer the nade and now do the code
     
  8. MagyarPeter

    MagyarPeter

    Joined:
    Nov 28, 2020
    Posts:
    13
    I experienced the same problem, REMOVE THE NAMESPACE to fix it.

    (you will have to write "*namespaceName.*scriptInsideNamepace" if you want to get the other scripts in the namespace.)
     
  9. Lucapalooka

    Lucapalooka

    Joined:
    Mar 23, 2021
    Posts:
    2
    CAN ANYONE HELP ME MY CODE WOONT WORK ALWAYS SAYS The script don't inherit a native class that can manage a script.
     
  10. Lucapalooka

    Lucapalooka

    Joined:
    Mar 23, 2021
    Posts:
    2
    THIS IS CODE:
    void Update()
    {
    if (Input.GetKey(KeyCode.LeftArrow))
    {
    transform.position += Vector3.left * speed * Time.deltaTime;
    }
    if (Input.GetKey(KeyCode.RightArrow))
    {
    transform.position += Vector3.right * speed * Time.deltaTime;
    }
    if (Input.GetKey(KeyCode.UpArrow))
    {
    transform.position += Vector3.up * speed * Time.deltaTime;
    }
    if (Input.GetKey(KeyCode.DownArrow))
    {
    transform.position += Vector3.down * speed * Time.deltaTime;
    }
    }
     
  11. Andyz280

    Andyz280

    Joined:
    Mar 18, 2021
    Posts:
    1
    I had the same problem and I found out that moving the folder would fix it.
     
  12. Aleksandr_Novik

    Aleksandr_Novik

    Joined:
    Jul 22, 2018
    Posts:
    2
    If someone is still facing this bug and trying to resolve it, I erased the namespace my bugged script is located inside, switched to Unity (so the code compiled), then went back to IDE and added my namespace. Everything works now.
     
  13. evanmaxey

    evanmaxey

    Joined:
    Feb 28, 2016
    Posts:
    1
    simple fix listed above as well, the name of the script as known to the unity editor "abc123" is different than the name of the script/class in the cs file "abc456"

    just had the same problem after renaming in unity

    keep the name the same ... all better
     
  14. _met44

    _met44

    Joined:
    Jun 1, 2013
    Posts:
    633
    if you rename in visual studio using the renamme feature with unity tools it will rename both the script file name and the meta file name to match (right click on class name then hit the rename menu)
     
  15. sikvar

    sikvar

    Joined:
    Dec 20, 2020
    Posts:
    2
    Sorry, i don't readed this discussion, but i finded solution. Don't name script for ex. "Camera Control", name it "CameraControl".
     
  16. War571

    War571

    Joined:
    May 7, 2020
    Posts:
    1
    That fixed it for me. Thank you so much! I would have never noticed the space.
     
  17. Zongoland

    Zongoland

    Joined:
    Mar 28, 2021
    Posts:
    1
    Worked perfectly for me ! Thanks a lot !!
     
  18. iwobrzostowski

    iwobrzostowski

    Joined:
    Mar 30, 2021
    Posts:
    7
    hi! i am having this problem too. Can somebdoy tell me how to fix it please
     
  19. iwobrzostowski

    iwobrzostowski

    Joined:
    Mar 30, 2021
    Posts:
    7
    So i did everything that is in this conversation, but it still don't work i downloaded some movement asstes to my projcet and it still wasn't working.
     
  20. GrubZGameDev

    GrubZGameDev

    Joined:
    Apr 1, 2021
    Posts:
    1
    All the top comments are from 2020, and im very unhappy because none of the solutions from then are working now, but yes 2021 and im having this problem as well, your not alone. lmao please help
     
  21. Ice_Forge

    Ice_Forge

    Joined:
    Sep 1, 2020
    Posts:
    1
    I was struggling with the same issue, and the problem was a script i had added in the scene previously that was faulty, are you getting 0 errors in the console?
     
  22. theomcortez

    theomcortez

    Joined:
    Apr 2, 2021
    Posts:
    1
    Guys, the name of the class must to be exacly the same of the c# script, for instance, if u created a c# script named "Background Controller", the name of the class will be "BackgroundController" without the space between background and controller, cuz classes names must be only 1 word. So u guys should name the scripts without spaces, that worked for me
     
  23. undevable

    undevable

    Joined:
    Dec 25, 2020
    Posts:
    140
    The same problem happened to me. I just fixed some bugs in my script, which were causing compile errors. Because of the compile errors, the entire Unity compiler just can't work, and therefore these problems happen. So, fix all compile errors, and then Unity can add the script
     
  24. philswan

    philswan

    Joined:
    Apr 20, 2017
    Posts:
    3
    I found that this happened when I first added a new script with the name I wanted, and then tried to import a script with the same name to replace it. The new one was created in the assets folder, but the one I copied over was placed into the scripts folder. Deleting the script and meta file in the assets folder and then dragging the one from the scripts folder and dropping it on "Add component' in the inspector solved my problem. But definitely the error message is confusing and not helpful.
     
  25. asdfsf

    asdfsf

    Joined:
    Dec 14, 2015
    Posts:
    1
    Hi guys,

    I just stumbled about the same error message and came across this thread. Then I saw that my script name accidently contained some white spaces but I did not get any errors neither in Unity nor in Rider. But renaming the file to a proper filename without white spaces solved the problem for me.
     
  26. chrisjrock

    chrisjrock

    Joined:
    Jun 12, 2014
    Posts:
    1
    This just happened to me. Fixed it by deleting the project's 'Library' folder. Unity will repopulate it the next time you open the project and it should work fine.

    Deleting the Library folder often solves bugs like this so remember to give it a shot when you're stumped.
     
    Last edited: Apr 7, 2021
  27. kilouane

    kilouane

    Joined:
    Apr 9, 2021
    Posts:
    1
    I did the same thing . I noticed that the name after public class was different from the name of the script.
    I changed the name after "public class" . I put there the name of the script . Then the problem was fixed
     
  28. Derpasaurus_Flex

    Derpasaurus_Flex

    Joined:
    Apr 9, 2021
    Posts:
    1
    This may just be me fixing my own dumb thing, but I found that the issue was fixed when I changing the name of the Public Class to match the name of the file. IT doesn't seem to do this automatically when renaming the file, which is why it kept happening every time I renamed a script file.

    For example, if I renamed a script from "OldName" to "NewName":
    public class OldName : MonoBehaviour - Wouldn't work, because it's the old name.
    public class NewName : MonoBehaviour - Would work, because it's the new name.
     
  29. KrstenGames

    KrstenGames

    Joined:
    Apr 11, 2021
    Posts:
    1

    In Unity, the name of your script has to be letters if you have used anything like space or numerals. It will prompt up "The script doesn't inherit a native class that can manage a script." I hope I fixed your problem.
     
  30. x0llie5

    x0llie5

    Joined:
    Apr 15, 2021
    Posts:
    1
    Same thing is still happening and im 100% sure the code is flawless.
     
  31. janeler88

    janeler88

    Joined:
    Apr 17, 2021
    Posts:
    1
    I found that if the name matches that with the public class it wont have that error
     
  32. ONOEDIT

    ONOEDIT

    Joined:
    Apr 19, 2021
    Posts:
    2
    Thanks guys. I was following the Ruby's 2D Adventures and doing the first Script Rubys_Controller. After taking it into Visual Basic. I dragged the file into Visual Studio since it opens a second program. 1. Unity 2. Visual Basic/Pink Infinity Logo. Some thing kept happening. The code was very simple, just the Position X part, but for some reason, the title
    was wrong. It's like it changed after I was finished or finishing. Luckily I read these comments while going back
    through each line. The " public class Rubys_Controller : MonoBehaviour" had changed the "Rubys_Controller" into
    " NewBehaviourScript : MonoBehaviour" I just had to change it back, saved it, and then went back to Unity to click on the Ruby's Sprite, then dragged the Script into the empty bottom, add component area, and it worked.

    -ONO
     
  33. Harmelody

    Harmelody

    Joined:
    Apr 18, 2021
    Posts:
    1
    Hi I had this issue in Unity.
    I named the script DialgueManager then realized I made a spelling mistake and corrected the script name to DialogueManager. When I went to try add the script to an empty game object I got the error "The script don't inherit a native class that can manage a script." Its because I had to go into the script and re-name it from there as well.
    So it reads :
    Public class DialogueManager : MonoBehaviour
    {
    etc.
     
  34. KAISENPAII

    KAISENPAII

    Joined:
    Apr 25, 2021
    Posts:
    1
    That worked for me thanks!!!!
     
  35. Redmutant9

    Redmutant9

    Joined:
    Apr 25, 2021
    Posts:
    1
    i have but it still doesn't work
    is it because im an a mac
     
  36. Shaolinzhang

    Shaolinzhang

    Joined:
    Sep 7, 2017
    Posts:
    1
    I solved this after I fixed the DLL errors.
     
  37. am_GA

    am_GA

    Joined:
    Oct 4, 2018
    Posts:
    20
    I just experienced this issue on Unity v2020.3.4f1 for Windows.

    Steps to reproduce:
    1. Opened existing project (that had never previously had this issue)
    2. Created new script Wall.cs; did not edit the new script in any way but did confirm the boilerplate code was generated including correct name and Monobehaviour inhertance
    3. Dragged Wall.cs onto Wall game object
    4. Received the "The script don't inherit a native class that can manage a script" error dialog
    Solution:

    I wondered if having a component the same name as the parent game object was the issue so I renamed it to Wall_.cs, tried adding it to the Wall object again and this time it was accepted.

    Then, I decided to rename the script to Wall.cs while it was still attached to the Wall game object, and it remained attached with no further problems.

    Reason for the issue:

    I still do not know.
     
  38. f3rras

    f3rras

    Joined:
    Nov 23, 2018
    Posts:
    5
    Hello guys!, I just had the same issue, I was able to fix it by making sure the name of the script is the same as the one inside of it next to the " : MonoBehaviour". I hope this helps someone.
     
  39. TheRealMajorGonzo

    TheRealMajorGonzo

    Joined:
    May 12, 2018
    Posts:
    12
    [Fixed] Only had one script, and it was a new, empty script (just empty Start and Update methods), and I got this error. I noticed some of the comments, and found that I had a space in the script name, but in the editor, the space was removed. Created a new script named "script with spaces" and looked over at the inspector, and it was named "scriptwithspaces", but in the project the script was still called "script with spaces". Unity's fault; it is removing the spaces within the file. Renaming the script to remove the spaces allows me to attach them.
     
  40. gkttjs232

    gkttjs232

    Joined:
    May 2, 2021
    Posts:
    1
    I fixed it by changing classname as scriptname. thank u guys :D
     
  41. Hanzuki

    Hanzuki

    Joined:
    Sep 1, 2019
    Posts:
    1
    So, came here looking for an answer to the "Can't add script because the script doesn't inherit from a native class" or some such error. I solved by ensuring that the name of the script file matches the name of the class in the file. Example:ClockBehaviour.cs -> public class ClockBehaviour : MonoBehaviour{}. They must be the same
     
  42. MrBenPi

    MrBenPi

    Joined:
    Jul 24, 2017
    Posts:
    1
    I have not read the entire thread, but did have the same message come up. In my case it was related to the name that I gave the script. I had a space in the name on the script and when I retitled it to match the the issue went away.
     
  43. BG_Grill

    BG_Grill

    Joined:
    Apr 18, 2020
    Posts:
    3
    I had the same issue with my project but it was because of bad references to scripts from other scripts and some errors. After I fixed those errors everything began working fine.
     
  44. arsoni

    arsoni

    Joined:
    May 21, 2020
    Posts:
    1
    Hi, Based on my recent experience, this problem came when the Script name and the class name don't match.
     
  45. Colson316

    Colson316

    Joined:
    May 15, 2021
    Posts:
    1
    Mine wont work too with the same error just started and cant do anything can someone help please
     
  46. ANGELBEAR24

    ANGELBEAR24

    Joined:
    Apr 10, 2020
    Posts:
    2
    Hey guys. Not sure if this has been officially 'solved' or not yet but I just fixed this bug on my own project. I loaded a Unity Learn project and Unity was not able to compile before the first time I tried to run the game on a brand new project. I just had to fix all the code errors in the project scripts (probably caused by upgrading the version beyond what the tutorial had approved ;p shhh) and then hit play and let the game run one time. Problems solved and I can go on about my day attaching scripts to objects as my heart desires :) Good luck and I hope this helps someone!
     
  47. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    192
    The problem for me is that Unity adds a space to some of the scripts when pressing enter so if my Script was "DoSomething" when Unity creates it the name of the file is "Do Something.cs" and the script is titled "DoSomething". Removing the spaces resolves the problem, but it is quite annoying.
     
  48. How do you create that script? And what Unity version? Do you have any 3rd-party plugins present?

    I'm asking because:
    screenshot1.png

    - Right click on an empty space in the folder
    - Write "DoSomething"
    - Hit enter
    That's all what I did. No spaces.
     
  49. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    192
    Unity 2020.3.6f1.
    Right click in folder location, Create New Script... type in name (no space) press enter. I started new project this time around to test some other plugins and had this issue. It very well could be user error, but it has happened to me several times now after switching to 2020 instead of 2019.3. Never got the error before except when I first started programming. (albeit, a bit differently worded... and correctly written) Maybe I've gotten lazy since then?
     
    Last edited: May 22, 2021