NPM package WebXR import to C# component issues in Needle

Made myself a custom npm package of scripts to use across projects, I am hitting an issue with the latest Needle in Unity with WebXR imports. In two identical scripts in the npm package I have import { WebXR } from "@needle-tools/engine/src/engine-components/webxr/WebXR"; which ends up with the generated C# Component using public Needle.Engine.Components.WebXR @xrScript; when it should be public Needle.Engine.WebXR @webXrScript; It only does this for one of the scripts and both have been saved + I have tried reimporting and regenrating the types and components from the npmdef asset in the project view.

The issue is in the asset linked below with LoaderFixer.ts while VRControls.ts does not exhibit the same issue despite the imports being from the same location

I have attached the problematic asset here as a zip in this link if you have time to investigate? Link: epm.modelviewer~.zip - Google Drive

Original Post on Discord

by user 103054507105067008

Hello there – we have an experimental AI bot :robot: that might be able to help you with your question. Would you like to try this out?

by user 103054507105067008

Please dont import from the src or lib paths - this might cause issues in bundling. Import from the toplevel import { WebXR } from "@needle-tools/engine instead.

You also have an error in your import using a type that doesnt exist anymore (WebXREvent)

Is it possible that one script was generated before the update and one script was generated after?

Will try that now - will find out where the WebXREvent is moved to as I used to import it from somewhere

by user 103054507105067008

It’s not moved - it has been removed.

You dont need it anymore to subscribe to XR system events. You can use the XR callback methods that are available on each component (e.g. onEnterXR )

see Needle Engine Scripting | Needle Engine Documentation

As a reference you can also look at e.g. these components (their typescript implementation)
image.png

Little detour:
The latest version also unifies XR inputs - so you can just implement e.g. onPointerDown on your component and you get down events for XR controllers or hands - similarly you can listen to all events via this.context.input.addEventListener("pointerdown", (args) => { } if you really want to get all inputs (the event args include spatial information now even for screenspace touches or clicks, the args object contains a lot more code comments, let me know if anything is missing or unclear)

Just what I’ve been waiting for :slightly_smiling_face: taking a look at updating my XR scripts now

by user 103054507105067008

@marcel :cactus: in LoaderFixer.ts I changed the import to from "@needle-tools/engine";
but I still get the generated componenet error:
Assets\Needle\epm.modelviewer.codegen\LoaderFixer.cs(19,35): error CS0234: The type or namespace name 'WebXR' does not exist in the namespace 'Needle.Engine.Components' (are you missing an assembly reference?)
What could be causing this?

by user 103054507105067008

can you paste the script here?

LoaderFixer.ts

by user 103054507105067008

Omg I see why now

by user 103054507105067008

Sorry I left in β€œ//@type Needle.Engine.Components.WebXR” in the declaration lower down

by user 103054507105067008

Easy for me to miss that when upgrading engine versions but at least it made an error to lead me to checking it

by user 103054507105067008

That was my guess too - happy to hear that’s all :slightly_smiling_face:

Those callbacks are perfect, thanks for adding them :smile: I can get rid of my hacky workarounds in my model viewer now

by user 103054507105067008

Happy to hear that