Unknown components - why?

i have created some TS scripts. They got codegen’ed to C#. I used them in unity editor. I exported.

For some reason in the console it is saying all these scripts i created are unknown components. Attached are some useful pics. Any idea why this is happening?

Some other weird stuff:

  1. this is a Next.js project and i can only run the app from the web project. If i try to press play in unity it doesnt work. It says it cant detect the compiler type or something like that. This could be unrelated tho

Original Post on Discord

by user 352282921056468993

In typescript try adding @registerType above your class

export class Rotate extends Behaviour {...

Normally the types are automatically registered (by code generated by the Unity exporter). Can you check if your next.js project has a register_types.ts somewhere? If yes try importing it from somewhere

It sounds like the sample must be updated / is outdated (it was a register_types.js before)

@registerType didnt change anything and register_types.ts is already imported in generated/gen.js.

The sample?

by user 352282921056468993

by user 352282921056468993

Hi @Shmoji I’ve just tried to reproduce it here with our next sample but that works as expected.
Can you check if you have perhaps both a register_types.js and a register_types.ts in that directory? Otherwise can you send us a bugreport from Unity with Needle Engine/Report a bug ?

Thanks :wink:

i assume the bug report doesnt send the web project too. Not sure if that’s important to have or not

by user 352282921056468993

It sends both :slightly_smiling_face: (usually has all necessary info, I’ll check in a bit)

Hi @Shmoji you have to import the attribute of course, it can’t work otherwise (you see the typescript error)

You also seem to reference prefab assets in your Unity Event functions in which case the methods that are called by the Unity Event do receive a string (the url to the exported glb).

You can do this to fix that in the SpawnHandler line ~28:

async handlePlayerSpawn(obj: Object3D | string) {
        if (typeof obj === "string") {
            obj = await AssetReference.getOrCreate(this.sourceId, obj, this.context)?.instantiate();
        <rest of your code>

i also had to change a little bit in the needleEngine.tsx - this is something we have to update in the sample for your usecase. Below is the fixed code (in needleEngine.ts line 27 it now always imports the /generated/gen path)

if (!isServer()) {
        .then((m) => {
          if (props?.src === undefined) {
              console.log('setting src to==', m.needle_exported_files)
        .catch((e) => {

oo okay thank you, im going to process all of this. Also, for this part specifically i was confused by the sample because i couldnt figure out where the sample code was instantiating the player that gets spawned

by user 352282921056468993

Which sample code are you referring to? Sounds like something we should improve then

the one here from first person controller sample. My code is basically the same as the sample. I mainly just copy and pasted everything from the samples. And i noticed i didnt see handlePlayerSpawn actually instantiating any players anywhere (until you suggested that change above, but that’s not in the sample itself)

by user 352282921056468993

Ah the sample uses PlayerSync. Maybe kipash can explain more tomorrow

Ahh okay i thought may be related to that. No worries! I’ll check out the code!

by user 352282921056468993

Everything works now! Im still getting the unknown component warnings for some reason…but it all works!

by user 352282921056468993

Happy it works - but you shouldnt get the warnings anymore :thinking: Maybe a refresh or restart of the next server helps?