Unity Cannot See the Scripts in Assembly-CSharp.dll assembly from a Custom Assembly Definition
Asked Answered
E

1

5

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.

E answered 20/4, 2019 at 0:20 Comment(1)
You should create another asmdef to include the Oculus libraryErnest
M
9

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.

Mcclean answered 20/4, 2019 at 1:34 Comment(4)
As you and @Ernest 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!E
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".E
Yes, because those other two are Editor magic folders. Also, holy carp, those are awful assembly names.Mcclean
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.E

© 2022 - 2024 — McMap. All rights reserved.