Page 1 of 1

Reference a class from another folder

Posted: Sat Jun 06, 2020 1:37 am
by undecode
Hi.

I know this question is more related to c# but I've been slamming my head against the wall for a good amount of time by now, so I come here for some guidance.

I have a script called "Assets/Scripts/x.cs" that I want to use in a custom sequence command, which is in Plugins/Pixel Crushers/Dialogue System/Templates/SequencerCommandX.cs.

I'm trying to have a reference to my own script from the Sequencer command.
I tried using a namespace in my x.cs file and also using global namespace (:: operator) from the sequencer command but I can't see it.

What do I need to do this? By now the only thing that comes into my mind is copying my script to the Plugins folder, but I don't want to duplicate my files.

Any help is appreciated. Thanks

Re: Reference a class from another folder

Posted: Sat Jun 06, 2020 8:35 am
by Tony Li
Hi,

Move your SequencerCommandX.cs script out of the Plugins folder. For example, move it into the same folder as Assets/Scripts/x.cs.

Unity separately compiles scripts in Plugins first. Scripts in Plugins cannot access scripts that are outside of Plugins. However, scripts that are outside of Plugins can then reference the Plugins scripts that have already been compiled.

Re: Reference a class from another folder

Posted: Sat Jun 06, 2020 10:30 am
by undecode
That is interesting... didn't know that at all!
It's working, thanks a lot Tony :)

Now, out of curiousity, how come namespace "PixelCrushers.DialogueSystem" can be accesed outside Plugins? Did you have to reference the assemblies somewhere?

Re: Reference a class from another folder

Posted: Sat Jun 06, 2020 10:49 am
by Tony Li
Plugins is compiled first, without knowledge of things outside of Plugins.

Scripts outside of Plugins are compiled next, and they have access to everything that's in Plugins as well as outside of Plugins.

Re: Reference a class from another folder

Posted: Sat Jun 06, 2020 11:26 am
by undecode
I got it right the first time and somehow managed to not fully understand it lol

Thanks :D