Package script cannot access another assembly

Posted this at Opsive’s Ultimate Character Controller forum, they directed me here.

Basically, I’m attempting to modify the source for CharacterLocomotion.cs. However, if I add a ‘using [xyz Namespace]’ to the file, it is not detected. Unity also throws an exception on compile, so this isn’t a limitation of the IDE.

Repro steps:
Create a fresh 3D (legacy pipeline) project (Unity 2021.1.3.f1, but others have been tested).
Import TPC 2.4.2 (latest)
Import Final IK 2.1 (latest)
Open CharacterLocomotion.cs
Add “using RootMotion.FinalIK;” on line 20 (just after “using UnityEngine;”)
Observe that IDE and Unity do not recognize the assembly reference.
Create a new script in Assets folder
Add “using RootMotion.FinalIK;”
Observe that it accepts the assembly reference.

Error:
Assets\Opsive\UltimateCharacterController\Scripts\Character\CharacterLocomotion.cs(20,11): error CS0246: The type or namespace name ‘RootMotion’ could not be found (are you missing a using directive or an assembly reference?)

Notes:
I’ve tested this on Odin (“using Sirenix.OdinInspector.Internal;”) - this works.
I’ve tested this with Chronos (“using Chronos”) - this doesn’t work.
If CharacterLocomotion.cs is moved to Assets folder, all tests work, but this will of course break other things from what I’ve read in the Discord.
This appears to match a behavior from a long time ago where scripts within an Editor folder will fail to detect non-Editor script. However, the path for CharacterLocomotion.cs is not in an Editor folder.
Additionally, both FinalIK and Odin exist within the Plugins folder, whereas Chronos does not. Placing Chronos into a Plugins folder does not change the above behavior.

UCC isn’t in a special folder (Plugins, Editor) other assemblies have been tested in and out of special folders.

Any guidance here?

1 Like

Found the answer.

UCC has an Assembly Definition Asset at the root level of the package (Opsive.UltimateCharacterController). All scripts below that folder must reference scripts within the package.

The exception to this is if you change the Assembly Definition References list to include another assembly.

I needed to create an Assembly Definition for Chronos, and use the existing RootMotion.FinalIK assembly definitions.

Once I added both of those to Opsive.UltimateCharacterController.asmdef CharacterLocomotion.cs was able to identify the 3rd party scripts.

Few things to note:
Unity docs on Assembly Definitions - Unity - Manual: Assembly definitions

Unity compilation order (didn’t apply in this case) - Unity - Manual: Special folders and script compilation order

1 Like