Unknown components in scene

After adding a script.ts to the /src/scripts directory it generates the C# script correctly and I can add it to my GameObject.
However when launching the local server, I get this error

**Unknown components in scene**
ContentManager This could mean you forgot to add a npmdef to your ExportInfo [documentation](https://engine.needle.tools/docs/project_structure.html#creating-and-installing-a-npmdef)

I obviously visited the docs but have a hard time following it to be honest. Some old topics on the forums suggested adding @registerType above the class, but that also didn´t help.

Where does the npm def need to be created and what do I do with it?

Hi v4C38,

The error message indicates that you have an unknown component in your scene, potentially due to a missing npm definition (npmdef) for the component you implemented. To resolve this, you’ll need to follow a few steps to create and install an npmdef.

  1. Create npmdef: You should create an npmdef file if one does not yet exist. This file typically goes within the exported information for your scene and should be structured to define your component appropriately.

  2. Add @registerType: Ensure you have the @registerType decorator above your class definition. This decorator is essential for registering your component type correctly.

  3. Update ExportInfo: After adding your script and npmdef, you need to ensure that the ExportInfo component in your scene is aware of the new definition. You may need to add the package to the devDependencies in your project’s package.json file.

  4. Install npm dependencies: Run npm install in your project’s root directory to install the dependencies, including your new npmdef.

  5. Restart the local server: After making these changes, restart your local server and see if the error persists.

For a more detailed guide, you can refer to the documentation on installing a npmdef, which may include specific examples and additional options you might need (see the documentation).

If you are still seeing issues, please ensure your npm and Node.js versions are up to date and compatible with Needle Engine. If you provide the current versions you are using, I can help verify their compatibility.

Let me know if you need further assistance!

1 replies left - Get a PRO license for more AI replies.
thread_xPoM5Vq0BBrXy5GJ5AotCIgY
Reply to this message to continue the conversation

1 Like

I created the npm def in /Assets/Needle and it is correctly referenced in the Project&Export component. The Project Folder is set to /Needle.

This is what it looks like:

name	"npmdef"
version	"1.0.0"
main	"index.ts"
dependencies	{}
peerDependencies	
@needle-tools/engine	"^4.2.5"
three	"npm:@needle-tools/three@^0.169.5"
devDependencies	
@needle-tools/engine	"^4.2.5"
three	"npm:@needle-tools/three@^0.169.5"
@types/three	"0.169.0"

package.json has a reference too (this was added automatically here so I assume that part works):

  "dependencies": {
	  "@needle-tools/engine": "^4.2.5",
	  "three": "npm:@needle-tools/three@^0.169.5",
	  "npmdef": "file:./../Assets/Needle/NpmDef~"
	}

@registerType was added above my classes, they now show up correctly in register_types.ts like so:

// Import types from dependencies
import "npmdef"
import "npmdef/codegen/register_types.ts"

/* eslint-disable */
import { TypeStore } from "@needle-tools/engine"

// Import types
import { ContentManager } from "../scripts/ContentManager.js";
import { TriggerableObject } from "../scripts/TriggerableObject.js";

// Register types
TypeStore.add("ContentManager", ContentManager);
TypeStore.add("TriggerableObject", TriggerableObject);
  • npm install and a Unity + Server restart was done as well.

Yet, I still get the error “Unknown components in scene” error message.

How do I add a new .ts script to my project so I can actually use it?!?

€dit: I also tried to right-click the npm def and add a TypeScript file there. Again, it generated the C# component correctly, but launching the server results in the unknown components error.

Hi, your initial workflow was already the right one and should works. Npmdefs are just another way of organizing your scripts in separate packages instead of the web project.

@registerType is also optional if there’s no codegen (which you have when using Unity).

Can you check that your index html imports the src/generated/gen.js script?

1 Like

Hi, did you solve the issue? What was causing it?

Hi,
I ended up creating a new project from scratch and keeping track of the project location from the very beginning on.

This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.