# Script class can't be found

**URL:** <https://forum.needle.tools/t/script-class-cant-be-found/510>\
**Category:** 🌵 Needle Engine\
**Tags:** question\
**Created:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510 "2024-01-22T00:00:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/1 "2024-01-22T00:00:00Z")

</div>

Hello again 😅

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](https://stackoverflow.com/questions/51713497/cant-add-script-component-because-the-script-class-cannot-be-found)

 ![IMG_20240122_090149.png](https://europe1.discourse-cdn.com/flex006/uploads/needle1/original/1X/5ac6b3ef8c5ec80a0bb7a0580bc1b4dff770626b.png)  
 ![IMG_20240122_090208.png](https://europe1.discourse-cdn.com/flex006/uploads/needle1/original/1X/b8b4492eaf0ebfe0c714002d5dccb4d64c7fe659.jpeg)

[Original Post on Discord](https://discord.com/channels/717429793926283276/1198874633382936698)

_by user 883276031048441917_

---

<div class="post-metadata">

**Author:** ![needle-bot](https://forum.needle.tools/user_avatar/forum.needle.tools/needle-bot/32/20_2.png) [@needle-bot](https://forum.needle.tools/u/needle-bot)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/2 "2024-01-22T00:00:00Z")

</div>

Hello there – we have an experimental AI bot 🤖 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…_

---

<div class="post-metadata">

**Author:** ![needle-bot](https://forum.needle.tools/user_avatar/forum.needle.tools/needle-bot/32/20_2.png) [@needle-bot](https://forum.needle.tools/u/needle-bot)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/3 "2024-01-22T00:00:00Z")

</div>

Here is what I found for you 🧠 [Discord](https://discord.com/channels/717429793926283276/1198874633382936698/1198874917299552347)

---

<div class="post-metadata">

**Author:** ![needle-bot](https://forum.needle.tools/user_avatar/forum.needle.tools/needle-bot/32/20_2.png) [@needle-bot](https://forum.needle.tools/u/needle-bot)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/4 "2024-01-22T00:00:00Z")

</div>

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_  
_thread\_edUqRb4gYN7pKFHXNEauU5it_  
_Thanks for your feedback!_

---

<div class="post-metadata">

**Author:** ![hybridherbst](https://forum.needle.tools/user_avatar/forum.needle.tools/hybridherbst/32/3416_2.png) [@hybridherbst](https://forum.needle.tools/u/hybridherbst)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/5 "2024-01-22T00:00:00Z")

</div>

Always extend from `Behaviour` for your custom components

---

<div class="post-metadata">

**Author:** ![hybridherbst](https://forum.needle.tools/user_avatar/forum.needle.tools/hybridherbst/32/3416_2.png) [@hybridherbst](https://forum.needle.tools/u/hybridherbst)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/6 "2024-01-22T00:00:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/7 "2024-01-22T00:00:00Z")

</div>

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

_by user 883276031048441917_

---

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/8 "2024-01-22T00:00:00Z")

</div>

I did it also and it solved

_by user 883276031048441917_

---

<div class="post-metadata">

**Author:** ![hybridherbst](https://forum.needle.tools/user_avatar/forum.needle.tools/hybridherbst/32/3416_2.png) [@hybridherbst](https://forum.needle.tools/u/hybridherbst)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/9 "2024-01-22T00:00:00Z")

</div>

Great!

---

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/10 "2024-01-22T00:00:00Z")

</div>

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

_by user 883276031048441917_

---

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/11 "2024-01-22T00:00:00Z")

</div>

Is that possibale?

_by user 883276031048441917_

---

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/12 "2024-01-22T00:00:00Z")

</div>

![image.png](https://europe1.discourse-cdn.com/flex006/uploads/needle1/original/1X/01209210775578215d289a448f6786cc8242fc2f.png)

_by user 883276031048441917_

---

<div class="post-metadata">

**Author:** ![hybridherbst](https://forum.needle.tools/user_avatar/forum.needle.tools/hybridherbst/32/3416_2.png) [@hybridherbst](https://forum.needle.tools/u/hybridherbst)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/13 "2024-01-22T00:00:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hybridherbst](https://forum.needle.tools/user_avatar/forum.needle.tools/hybridherbst/32/3416_2.png) [@hybridherbst](https://forum.needle.tools/u/hybridherbst)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/14 "2024-01-22T00:00:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/15 "2024-01-22T00:00:00Z")

</div>

I want to cancel control `W and e`

_by user 883276031048441917_

---

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/16 "2024-01-22T00:00:00Z")

</div>

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

_by user 883276031048441917_

---

<div class="post-metadata">

**Author:** ![discord-import](https://forum.needle.tools/user_avatar/forum.needle.tools/discord-import/32/33_2.png) [@discord-import](https://forum.needle.tools/u/discord-import)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/17 "2024-01-22T00:00:00Z")

</div>

and three.js as well

_by user 883276031048441917_

---

<div class="post-metadata">

**Author:** ![hybridherbst](https://forum.needle.tools/user_avatar/forum.needle.tools/hybridherbst/32/3416_2.png) [@hybridherbst](https://forum.needle.tools/u/hybridherbst)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/18 "2024-01-22T00:00:00Z")

</div>

No worries.

---

<div class="post-metadata">

**Author:** ![hybridherbst](https://forum.needle.tools/user_avatar/forum.needle.tools/hybridherbst/32/3416_2.png) [@hybridherbst](https://forum.needle.tools/u/hybridherbst)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/19 "2024-01-22T00:00:00Z")

</div>

This should do the trick:

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

// Documentation → https://docs.needle.tools/scripting

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.");
            return;
        }
        
        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?.dispose();
        this._controls = null;
    }

    update(): void {
        if (this._controls)
            this._controls.update(this.context.time.deltaTime);
    }
}

```

---

<div class="post-metadata">

**Author:** ![hybridherbst](https://forum.needle.tools/user_avatar/forum.needle.tools/hybridherbst/32/3416_2.png) [@hybridherbst](https://forum.needle.tools/u/hybridherbst)\
**Post date:** [January 22, 2024, 12:00am UTC](https://forum.needle.tools/t/script-class-cant-be-found/510/20 "2024-01-22T00:00:00Z")

</div>

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)

[Next page](https://forum.needle.tools/t/script-class-cant-be-found/510.md?page=2)
