Script not appearing as option for GetComponent<>()

I’m sure there’s something absolutely obvious I’m missing here but I just can’t see it.

I have 2 scripts containing just integers, Stats and Storage. Both are attached to Prefabs. On my player object I have an OnTriggerEnter(Collider Col)…however when I attempt to use Col.gameObject.GetComponent<>() to get info from the Storage script, the option just isn’t there. However, I can access Stats.

I’ve compared the scripts and the only difference I can see is that one one, the word ‘monobehaviour’ just after the "public class Storage : " declaration at the top is blue on one of them, and black on the other.

What is going on? Obviously it’s simple as I’ve done it once already, but I can’t for the life of me spot what I haven’t done…

Should be MonoBehaviour :slight_smile:

1 Like

Ooops - writing from memory as I was on me phone…edited

Do you have using UnityEngine; at the top of the script that show mono in black?

Yup. Haven’t added anything either. It’s literally:

  1. create new script.
  2. add some variables.
  3. save.

That’s the only steps I took on either script pretty much.

“Storage” is a pretty generic name. Is there perhaps another package installed in your project that also has that class, perhaps in its own namespace?

Try changing yours to Storage2 (rename the file in Unity, not via the code editor to preserve Prefab linkage) and then try and find it.

Well Something happened. Shutdown and loaded Unity a couple of times - don’t think I played with the script at all…then suddenly the text colour changed and it worked…

I have no idea what went on there…

If that’s what happened (and I was wondering if that was the issue)… it was most likely just an issue with loading properly (sorry, I don’t know the exact terminology) - but that happens to me, too. :slight_smile:
Not fun, but 99% of the time, if I close my IDE and re-open the file, from within Unity, it’s working/fixed.

1 Like