# Using ECS in a custom Unity package

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

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": {
},
"author": {
"name": "Enrique Moreno Tent",
"email": "enriquemorenotent@gmail.com",
"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!

• I assume you don't actually have that comment in the manifest.json. Otherwise that would be wrong, as json doesn't support comments. – Chillersanim Aug 23 '19 at 16:09

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 dependency in the package.json is called com.unity.entities, the one in the Assembly file should have been called Unity.Entities.

• You saved my day, thank you man :) great find – Oneiros Apr 6 at 13:29

I've replicated your problem, and think that I know what causes it.

When you have a package, it needs to be in the Packages folder.
This folder is next (not in) the Assets folder.
Only then, Unity will recognize your package as such and try to fix missing dependencies.

There are multiple ways how to import packages:

• Simply move the package folder to the Packages folder
• In the packages manager, click the small + sign in the top left and select your package.json file.

As long as you are actively developing the package, it might be usefull to keep it in the assets folder.
To resolve the Entities issue, you can manually add the package using the package manager.
Later, when you give the package to other people (asset store, github, whatever) make sure they import it correctly.
Then the dependencies should be resolved by Unity.

• You are wrong. When the package is referenced in the manifest.json (inside the Packages folder), Unity will import it for you automatically. So developing my package outside of the Packages folder is completely OK, since Unity will reimport it every single time. – Enrique Moreno Tent Aug 24 '19 at 7:28
• Hmmm I understood that you had trouble with the development environment of the package. Instead you have your package somewhere on your pc and wanted it referenced. So the import was not working. Is that correct? – Chillersanim Aug 24 '19 at 9:35