Reference a class from another folder

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
undecode
Posts: 25
Joined: Mon Apr 13, 2020 3:53 pm

Reference a class from another folder

Post 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
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Reference a class from another folder

Post 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.
undecode
Posts: 25
Joined: Mon Apr 13, 2020 3:53 pm

Re: Reference a class from another folder

Post 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?
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Reference a class from another folder

Post 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.
undecode
Posts: 25
Joined: Mon Apr 13, 2020 3:53 pm

Re: Reference a class from another folder

Post by undecode »

I got it right the first time and somehow managed to not fully understand it lol

Thanks :D
Post Reply