Global variables visible from some scripts and not others.

Hi there.

I have a bit of an odd problem I can’t understand. For the sake of argument I have 2 different scripts (Startup and Globals). Each script is attached to an empty object in the project.

If I say: – public static int testing=5; – in Startup I can reference it across the project. If I put the same line in Globals I can’t reference it anywhere.

The setup of each class is identical, only the class name is different.

Could someone please let me know what’s going on here, it makes no sense to me at all.

Many thanks.

(Editor vs2019 comm)

You should always include the relevant code when you asking about problems specific to your code. My guess would be that the static class is in another namespace, and you’re not referencing that namespace from one of your scripts, but most people don’t use namespaces, so that seems less likely. Anyway, show your code.

2 Likes

That’s all the code there is, it seemed easier to put that little line in rather than paste 2 big classes full of nothing but Start and Update, which are empty. Honestly, they’re two completely fresh classes.

Show the first lines of each script, then, up through the class name. I want to know if there are any namespaces in your classes, for any of the classes involved. I’d also want to know where these classes are located. Did you put any of the classes into a directory named Editor, or a child directory of a class named Editor?

And you originally said “If I put the same line in Globals I can’t reference it anywhere.” Do you mean you get a compiler error if you try to use that property? If so, what’s the exact error? If not, then what specifically do you mean that you can reference it?