Search Issue Tracker

By Design

Votes

0

Found in [Package]

0.0.12-preview.12

Issue ID

1080692

Regression

No

[pacman][ECS] "Mathematics" does not exist in the namespace "Unity" when referenced in code using Assembly Definitions

Package: Entity Component System (ECS)

-

Reproduction steps:

1. Open "MinimalRepro.zip" project
2. In Folder "Code" -> "A" create an Assembly Definition
3. See Console Output ("The type or namespace name 'float3' could not be found /
'Mathematics' does not exist in the namespace 'Unity'")

Expected Result: "Unity" Namespaces should work with Assembly Definitions
Actual Result: "Mathematics" does not exist in the namespace "Unity" when referenced in code using Assembly Definitions

Reproduced with: 2018.3.0b1, 2018.2.8f1, 2018.1.9f2, 2017.4.11f1

  1. Resolution Note:

    This is not a bug, but is in fact how assembly definitions are expected to work. While they can reference things in UnityEngine/UnityEditor by opting into the respective platforms, code that exists in other assemblies needs to be added to the list of dependencies (Assembly Definition References in the Inspector). In this case, the user needs to add a reference to Unity.Mathematics to the newly created assembly. Code that does not exist in an assembly definition (i.e. exists in the default assembly, something like Assembly-CSharp) automatically references all the assemblies in the project, which is why mathematics is accessible when not in an assembly defined via an asmdef.

    That said, there is currently a limitation where assemblies imported as a package dependency do not appear in the project. In short, if the user has installed the entities package, it implicitly installs the mathematics package. But because the mathematics package has not been explicitly added, it won't appear in the Project Browser (and respectively, won't appear in the object picker when they try to assign it as an Assembly Definition Reference). As such, the user must do one of two things to reference Unity.Mathematics in their new assembly:

    a) Manually edit the asmdef file in a text editor and add "Unity.Mathematics" to the list of "references"
    b) Explicitly import the mathematics package via Package Manager (after enabling preview packages to find it) and then assign it as a reference to their new assembly definition via the Inspector

Comments (2)

  1. GDevTeam

    Jul 22, 2023 05:44

    In the Package Manager (press on the + sign, and choose 'Add package by name...') . In the Name field type in, 'com.unity.mathematics' Then press the 'Add' button.

  2. krisventure

    Feb 27, 2022 14:05

    The proposed solution doesn't work. Enabled Preview packages yet I can't see Mathematics in Package Manager when I search for it in Unity Registry.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.