Search Unity

Adding ECS to custom package

Discussion in 'Package Manager' started by dbugger, Aug 23, 2019.

  1. dbugger

    dbugger

    Joined:
    Jan 10, 2013
    Posts:
    55
    I have built a custom package for Unity called `world-renderer`. Inside the folder "Runtime" is all my source code. To use it inside a Unity project, I add this line into the `manifest.json` of that project.

    Code (Javascript):
    1. {
    2.    "com.tamagames.extinction.word-renderer": "file:C:/Users/dbugger/projects/unity/world-renderer",
    3.    ...
    4. }
    This has worked great so far, but now I want to start using ECS inside my custom package. so I add its namespace to one of the files:

    Code (CSharp):
    1. using Unity.Entities;
    and now when I return to the Unity Editor, I see the following error message:

    CS0234: The type or namespace name 'Entities' does not exist in the namespace 'Unity' (are you missing an assembly reference?)

    I figured I needed to add the dependency to the `package.json` of my custom package, so I wrote updated it like this:


    Code (Javascript):
    1. {
    2.   "name": "com.tamagames.extinction.word-renderer",
    3.   "version": "1.0.4",
    4.   "displayName": "Extinction - World renderer",
    5.   "description": "World renderer for Extinction",
    6.   "unity": "2019.1",
    7.   "unityRelease": "0b5",
    8.   "keywords": [],
    9.   "dependencies": {
    10.     "com.unity.entities": "0.1.1-preview" // Dependency added
    11.  },
    12.   "author": {
    13.     "name": "Enrique Moreno Tent",
    14.     "email": "enriquemorenotent@gmail.com",
    15.     "url": "https://enriquemorenotent.com"
    16.   }
    17. }
    But I still keep getting the same error.

    What am I doing wrong?
     
  2. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    asmdef needs dependency too
     
  3. dbugger

    dbugger

    Joined:
    Jan 10, 2013
    Posts:
    55
    I solved the problem.

    The issue was that in the package.json, the dependency had to be called "com.unity.entities", but in the .asmdef it had to be called "Unity.Entities".

    Weird that there has to be used 2 different names, but whatever.
     
  4. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,066
    The names come from two different systems:
    - The Package Manager requires an identifier for the whole package, defined in package.json.
    - The compiler requires an identifier for every assembly, defined in the Assembly Definition file.

    There can be multiple Assembly Definitions inside a package, so it's not always possible to use the same identifiers. If you split your Assembly Definitions by the namespace they contain, it also makes sense to use the namespace prefix as the identifier instead of the package identifier (as the ECS package did).
     
  5. dbugger

    dbugger

    Joined:
    Jan 10, 2013
    Posts:
    55
    Right, that makes sense. I just figured that if I write the identifier for the package, it would automatically add ALL the assemblies. But I guess that was just a wrong assumption.

    Thanks for the explanation.