Cris
Cris

Reputation: 317

Unity - How to access a class from another project?

In my Unity solution I have two projects, the main one and the editor one. I am creating an editor script and I would like to reference a class I have in the main project.

I've tried adding a namespace in the class I want to reference from the editor but Visual Studio don't detect it in the editor script.

I tried following this post: How can I refer to a project from another one in c#?

However when I try that I get the following error message: "A reference to 'Assembly-CSharp' could not be added. Adding this project as a reference would cause a circular dependency.

Many thanks!

Upvotes: 1

Views: 3813

Answers (2)

Cris
Cris

Reputation: 317

I came back to this after a while and found what I was looking for just in case it can be useful to anyone. What I wanted is called a Custom Inspector. Basically having a regular Monobehavior componenet and override its inpector with a UnityEditor script (many tools in the Asset Store use this).

Here it is greatly explained: https://unity3d.com/es/learn/tutorials/topics/interface-essentials/building-custom-inspector

Upvotes: 0

Immorality
Immorality

Reputation: 2174

In Unity you can not reference a different project directly. You can however export classes, objects etc. into a package in Unity.

After exporting the package from your "Editor" project, you can then Import it in your "Main" project.

You can export a package with Assets > Export Package and select what you want to export:

enter image description here

Upvotes: 2

Related Questions