0
votes

I have built a custom package for Unity called world-renderer. This is the folder structure.

enter image description here

Inside "Runtime" is all my source code. To use it inside a Unity project, I add this line into the manifest.json of that project.

"com.tamagames.extinction.word-renderer": "file:C:/Users/dbugger/projects/unity/world-renderer",

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:

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:

{
  "name": "com.tamagames.extinction.word-renderer",
  "version": "1.0.4",
  "displayName": "Extinction - World renderer",
  "description": "World renderer for Extinction",
  "unity": "2019.1",
  "unityRelease": "0b5",
  "keywords": [],
  "dependencies": {
    "com.unity.entities": "0.1.1-preview" // Dependency added
 },
  "author": {
    "name": "Enrique Moreno Tent",
    "email": "[email protected]",
    "url": "https://enriquemorenotent.com"
  }
}

But I still keep getting the same error.

What am I doing wrong?

UPDATE

I try adding the reference to the Assembly of my package, like this:

{
    "name": "Unity.com.tamagames.extinction.world-renderer-ecs",
    "optionalUnityReferences": ["com.unity.entities"],
    "includePlatforms": [],
    "excludePlatforms": [],
    "allowUnsafeCode": false,
    "overrideReferences": false,
    "precompiledReferences": [],
    "autoReferenced": true,
    "defineConstraints": [],
    "versionDefines": []
}

That did solve the problem with "Unity.Entities" not found, but now, in the Unity Project, the classes inside my source code cannot be found!

2

2 Answers

0
votes

I suspect this has to do with Assembly Definitions: you can fix this by adding a reference in your code (in your Assembly Definition file - if you don't have one you will need to create one in your Runtime folder) to Unity.Entities.

0
votes

Well, I got it to work.

First of all, I should not have used optionalUnityReferences, but references.

But the big mistake is that, event though the dependeny in the package.json is called com.unity.entities, the one in the Assembly file should have been called Unity.Entities.