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

Hello!

I know that is problem is on many other threads but i could not find an answer.

Every time i make a new script and attach it to the players gameobject, it comes up with the error “The script don’t inherit a native class that can manage a script.” It even happens when i have just created the script.

I have tried:

Starting a new project
Deleting the scripts and re-writing them

Nothing seems to work :frowning:

Any help?

Thanks :slight_smile:

2 Likes

Hey there, maybe post a code example ?

public class MyClass : MonoBehaviour

5 Likes

Ok here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;

namespace Invector.vCharacterController
{
    public class pickUpSword : MonoBehaviour
    {
        #region Vairables

        [Header("Variables")]
        public KeyCode pickupInputCon = KeyCode.JoystickButton5;
        public KeyCode pickUpInputKey = KeyCode.E;
        public KeyCode unSheathInputCon = KeyCode.JoystickButton3;
        public KeyCode unSheathInputKey = KeyCode.R;
        public KeyCode sheathInputCon = KeyCode.JoystickButton4;
        public KeyCode sheathInputKey = KeyCode.T;

        private Animator anim;
        private vThirdPersonController cc;

        public GameObject swordInHand;
        public GameObject swordToPickUp;
        public GameObject swordOnBack;

        public bool hasSomethingInHand;
        public bool hasUnSheathed;
        public bool hasSomethingOnBack;
        public bool isSwordInHand;
        public bool canPickUp;

        private GameObject thisGameObject;
        public float distance;

        #endregion

        void Awake()
        {
            anim = GetComponent<Animator>();
            cc = GetComponent<vThirdPersonController>();
            thisGameObject = this.gameObject;
        }

        void Update()
        {
            HandleInputs();
        }

        void HandleInputs()
        {
            HandleInput();
            DistanceHandler();
        }

        void DistanceHandler()
        {
            distance = Vector3.Distance(thisGameObject.transform.position, swordToPickUp.transform.position);

            if (distance <= 0.50)
            {
                canPickUp = true;
            }
            else
            {
                canPickUp = false;
            }
        }

        void HandleInput()
        {
            if (Input.GetKeyDown(pickupInputCon) && hasSomethingInHand == false && hasSomethingOnBack == false || Input.GetKeyDown(pickUpInputKey) && hasSomethingInHand == false && hasSomethingOnBack == false && canPickUp == true)
            {
                anim.SetTrigger("pickUp");
            }

            if (Input.GetKeyDown(unSheathInputKey) && hasSomethingOnBack == true && hasSomethingInHand == false || Input.GetKeyDown(unSheathInputCon) && hasSomethingOnBack == true && hasSomethingInHand == false)
            {
                anim.SetTrigger("unSheath");
            }

            if (Input.GetKeyDown(sheathInputKey) && hasSomethingOnBack == false && hasSomethingInHand == true || Input.GetKeyDown(sheathInputCon) && hasSomethingOnBack == false && hasSomethingInHand == true)
            {
                anim.SetTrigger("sheath");
            }
        }

        //Turn on/off sword in players hand
        void TurnOnSwordInHand()
        {
            swordInHand.SetActive(true);
            hasSomethingInHand = true;
            hasSomethingOnBack = false;
            cc.isStrafing = true;
            isSwordInHand = true;
        }

        void TurnOffSwordInHand()
        {
            swordInHand.SetActive(false);
            hasSomethingInHand = false;

            cc.isStrafing = false;
            isSwordInHand = false;
        }

        void TurnOffSwordToPickUp()
        {
            swordToPickUp.SetActive(false);
            cc.isStrafing = true;
            isSwordInHand = true;

            if (swordToPickUp == null)
            {
                Destroy(swordToPickUp);
            }
        }

        //Turn on/off swordOnBack
        void TurnOnSwordOnBack()
        {
            swordOnBack.SetActive(true);
            hasSomethingOnBack = true;
            hasUnSheathed = false;
            cc.isStrafing = false;
            isSwordInHand = false;
        }

        void TurnOffSwordOnBack()
        {
            swordOnBack.SetActive(false);
            hasUnSheathed = true;
            cc.isStrafing = true;
            isSwordInHand = true;
        }
    }
}

Hi yeah I made sure that I am inheriting from MonoBehaviour. Thanks for the suggestion though :slight_smile:

1 Like

how is the file with the script called ? should be precisely “pickUpSword.cs”.

11 Likes

Yes the name of the script is exactly the same as the visual studio name. I even tried copy and pasting it just to make sure

2 Likes

Try creating a brand new Unity project and see if you get the same problem there.

Hi so I tried starting a new project and everything seemed to work fine but then it happened again after about 5-10 minutes. Should I change to another unity version? I am currently on the latest 2020 version

1 Like

thats odd, try removing the namespace

Assuming you were doing stuff in the editor during that 5-10 minutes, then it’s probably related to something you did in that time. Try to remember everything you did from the last time you know your scripts worked until the first time you know they didn’t. See if you can undo those things and make them work again. If you can’t get your scripts to work again, start another new project and do stuff again, but check for this error as often as you can so that you know exactly when things go wrong and can figure out what you did right before that.

l will try removing the namespace and creating a new project. If that doesnt work i will try and delete unity and restart. Oh yeah btw during those 5-10 mins i was just writing the script

So after you wrote that one particular script, all scripts in your project stopped working? If you delete that script from your project (you can save a copy elsewhere on your computer if you want), then do other scripts work again?

Yes, all scripts stop working. When i try deleting it nothing happens

I think its a bug but maybe not

I went back into my ctrl+z and found I accidentally moved the MonoBehaviour script from it’s home. Not saying that’ll work for you but it fixed my “The script don’t inherit a native class that can manage a script” problem

If you are still having a problem, I imagine not, it’s been six days. But I just had the same thing happen and it was because I had an extra space in the .cs script name that wasn’t in the actual code.

14 Likes

Guys, it’s definitly a bug from Unity 2020. I’m using 2020.2.1f1 and I’m getting this all the time.
I have fixed this one time when I noticed the script name was different from the class name.
Right now I was trying to drop a brand new script to an existing game object in my scene and I was getting this error.

Later I found out that one of my other scripts was having a compile error, I just fixed this and I could drop the script to meu object. This is like… WTF? Non-sense error…

Unity definitly needs to do something about this…

13 Likes

One trick!

If you try to add a script while the game is Play, you get this (badly worded) message!

8 Likes

hello, it’s my first day in unity and I am on my first project, I am having the same problem, so I tried making a new script without writing anything in it I dragged it to the player and the same message came again anyway does anyone know how to fix it in my case? thank you

1 Like