1
\$\begingroup\$

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!

\$\endgroup\$
3
  • \$\begingroup\$ I assume you don't actually have that comment in the manifest.json. Otherwise that would be wrong, as json doesn't support comments. \$\endgroup\$ Commented Aug 23, 2019 at 16:09
  • \$\begingroup\$ I have a solution, maybe it's helpful: youtu.be/1IBUxo0EC44 \$\endgroup\$ Commented Nov 22, 2021 at 16:03
  • \$\begingroup\$ Is your code including namespaces? eg: namespace MyCode { .... } \$\endgroup\$
    – tatmanblue
    Commented Jan 6 at 17:54

2 Answers 2

3
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ You saved my day, thank you man :) great find \$\endgroup\$
    – Oneiros
    Commented Apr 6, 2020 at 13:29
0
\$\begingroup\$

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.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented Aug 24, 2019 at 7:28
  • \$\begingroup\$ 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? \$\endgroup\$ Commented Aug 24, 2019 at 9:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .