4

I have added Assembly Definition (.asmdef) to my script folder (my custom unity scripts). Now Unity complains that it cannot find OVRInput class which I've used it in one of my scripts (GameManager.cs): enter image description here

This OVRInput class is compiled into Assembly-CSharp.dll managed assembly as seen below:

enter image description here

I expect Unity, by default, to see this dependency and resolve it but somehow it doesn't. So I decided to manually add "Assembly-CSharp.dll" to the dependency section (called "Assembly Definition References") of my assembly but Unity gives error that it cannot find such an assembly.

The following is my custom Assembly Definition File (that puts all of scripts in "Scripts" folder into the assembly):

enter image description here

Target platform: Android (Oculus Gear VR) Unity version 2018.3.13f1.

Kamran Bigdely
  • 7,946
  • 18
  • 66
  • 86

1 Answers1

8

That's kind of the point

Assembly definitions are (effectively) entirely separate projects (part of the same solution, but separate dlls). This is in fact how they are displayed inside Visual Studio's Solution Explorer.

They're meant to be things you reference in to (like TextMeshPro or JsonDotNet) not out of. As such you cannot reference the main Assembly-Csharp "name space."

The advantage is that when a script file changes only its containing assembly is recompiled, instead of the entire project.

In this case, if you want to reference the Oculus files, you either need to create another assembly definition containing those files (and add it as a dependency of your first assembly) or not use an assembly definition at all.

Community
  • 1
  • 1
  • As you and @shingo said, I simply created an assembly definition file (asmdef) in the top-level Oculus folder and added this assembly to the dependency list of my own assembly. Everything worked afterwards! – Kamran Bigdely Apr 23 '19 at 16:51
  • Update: actually several asmdef files are required to separate Oculus files from Assembly_Csharp dll: 1- create one asmdef in the Oculus folder (say "MyOculusAssembly.asmdef" 2- another one in Oculus>VR>Editor folder with a reference to "MyOculusAssembly.asmdef" 3- another one in Oculus>VR>Scripts>Editor folder with a reference to "MyOculusAssembly.asmdef". – Kamran Bigdely Apr 24 '19 at 19:56
  • 1
    Yes, because those other two are Editor magic folders. Also, holy carp, those are ***awful*** assembly names. – Draco18s no longer trusts SE Apr 24 '19 at 19:59
  • 1
    They are not.This is for stackoverflow readers clarity purposes.You can remove 'My' from them in your application. 'My' signifies that you have created them yourself. – Kamran Bigdely Apr 24 '19 at 20:36