I am trying to put a gameobject into a prefab. Unity says "You are trying to save a Prefab that contains the script 'NPCDebugInfo', which does not derive from MonoBehaviour. This is not allowed. Please change the script to derive from MonoBehaviour or remove it from the GameObject 'yourgameobject'.

However, I don't see what I should do.

The script in question looks like this:

using System.Collections;
using System.Collections.Generic;

using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UI;

public class NPCDebugInfo : MonoBehaviour
    public Transform ThePlayer;//public so that we see it in the IDE. If we don't want that, make it private


I don't know what Unity really means and wants from me. What could I do to make this error message go away?

ps: For a clean test, I have created an empty gameobject and tried put my script onto it. Unity says "The script is an editor script."

So I will first find out what goes on here and why the script is actually on the other gameobject.

Thank you!

  • \$\begingroup\$ There is a missing closing bracket. If this is just a pasting here issue then make a small change to the file and save it, wait for Unity to apply the change, restore to the original version and save it again. This sometimes fixes it if there are no other/real issues. \$\endgroup\$
    – Nikaas
    Dec 26, 2021 at 10:01
  • \$\begingroup\$ @Nikaas Thank you, but I don't see what you mean. I have cropped / trimmed the code. Is that what you mean? \$\endgroup\$
    – tmighty
    Dec 26, 2021 at 10:29
  • \$\begingroup\$ Yes, on my phone I see the code just ending with ThePlayer variable row (now on PC it shows as being "cut"). BTW are the file and class names the same? \$\endgroup\$
    – Nikaas
    Dec 26, 2021 at 10:40
  • \$\begingroup\$ @Nikaas Yes, thank you, file and class names are the same. I think the problem is that it's an Editor script. I will edit my question as soon as I know more. I think I already have a clue... \$\endgroup\$
    – tmighty
    Dec 26, 2021 at 10:45

1 Answer 1


I found my mistake:

The script was NOT in the "Editor" folder at first. Then, at some point, I moved it into the "Editor" folder. I didn't notice which effect this had.

Now when I take a look at a game object which uses this script, I can see that it actually doesn't work anymore:

enter image description here

After I moved the script from the Editor folder to a "normal" folder, the error message went away, and I could proceed as I wanted to.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .