Script class can't be found

Hello again :sweat_smile:

I want to make FlyControls extends from the EventDispatcher cuz I want to deactivat the default control and add my own control to the camera but I am fasing this error and I tried these solutions c# - Can't add script component because the script class cannot be found? - Stack Overflow

Original Post on Discord

by user 883276031048441917

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?

How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.

Help requested: please wait a moment…

Here is what I found for you :brain: Discord

Hi Aya Ali, I understand you’re trying to customize FlyControls by extending it from EventDispatcher to deactivate the default control and add your own to the camera. However, it seems that FlyControls in Needle Engine is already a class that extends from Behaviour, which means it comes with its own lifecycle methods and ways of interacting with the engine.

Please make sure that you are defining your custom controls in conformance with how Needle Engine expects components to be built. This usually involves extending from Behaviour and implementing the relevant lifecycle methods such as update. Custom controls should ideally be built by composing these behaviors rather than directly modifying core components like FlyControls, which might lead to compatibility issues.

If you are still experiencing an error and it’s related to how you’re trying to extend or implement FlyControls, it could be helpful for you to share a snippet of the code where you are encountering the error so I can provide more targeted guidance.

Additionally, regarding the solutions from Stack Overflow that you tried, it’s important to ensure that you have the correct imports and that your class name matches the file name if you are in a Unity context, since Unity links scripts to game objects using the filename. If you are in the Needle Engine context, make sure to follow Needle Engine’s own conventions for extending and implementing component classes.

1 messages left GPT 4
Thanks for your feedback!

Always extend from Behaviour for your custom components

When you select the camera you’ll see there’s an OrbitControls component on it, just right click that and delete it and add your FlyControls

Yeah, I did that I deleted already “OrbitControls” and added main but I faced that error

by user 883276031048441917

I did it also and it solved

by user 883276031048441917


but I want to edit the FlyControls but it so much complicated

by user 883276031048441917

Is that possibale?

by user 883276031048441917

by user 883276031048441917

What exactly is your goal?
Our “FlyControls” component is using the three.js FlyControls under the hood

You can just copy the lines from there into your own script and call it e.g. “MyFlyControls” (wouldn’t use the same name) and adjust it as you need

I want to cancel control W and e

by user 883276031048441917

I’m sorry if I’m asking silly questions but I’m new to using Unity and needle tool

by user 883276031048441917

and three.js as well

by user 883276031048441917

No worries.

This should do the trick:

import { Behaviour, GameObject, Camera } from "@needle-tools/engine";
import { FlyControls as ThreeFlyControls } from "three/examples/jsm/controls/FlyControls.js";

// Documentation →

export class CustomFlyControls extends Behaviour {

    movementSpeed: number = 3;
    rollSpeed: number = .5;
    dragToLook: boolean = true;
    private _controls: ThreeFlyControls | null = null;

    onEnable(): void {
        const cam = GameObject.getComponent(this.gameObject, Camera)?.cam;
        if (!cam) {
            console.warn("FlyControls: Requires a Camera component on the same object as this component.");
        this._controls = new ThreeFlyControls(cam, this.context.renderer.domElement);
        // pass settings through to the three.js FlyControls
        this._controls.rollSpeed = this.rollSpeed;
        this._controls.movementSpeed = this.movementSpeed;
        this._controls.dragToLook = this.dragToLook;

    onDisable(): void {
        this._controls = null;

    update(): void {
        if (this._controls)

It’s basically a copy from FlyControls.ts that ships with Needle Engine but adjusted so that you can adjust movement speed and roll speed (set it to 0 to disable the movement in the directions you mentionde)