Sure! I'm calling the method from a function in a React context. Any calls on this script class instance fails in production because setVisible is undefined.
MyScript
export class MyScript extends Behaviour {
setVisible(b: boolean) {
GameObject.findObjectOfType(MyOtherScript)?.setShowObject(b);
}
}```
**MyOtherScript**
```export class MyOtherScript extends Behaviour {
setShowObject(b: boolean){
if (this.object) {
this.object.children[1].visible = b;
}
}
}```
**React Context**
'use client';
import { createContext, useContext, useEffect } from 'react';
import { MyScript } from '@/scripts/MyScript';
import '@needle-tools/engine';
import { GameObject } from '@needle-tools/engine';
const isClient = typeof window !== 'undefined';
export const Context = createContext<null | ContextAttributes>(null);
export default function NeedleContext({
children,
src: srcProp,
...props
}: NeedleContextProps) {
useEffect(() => {
async function importCodeGen() {
try {
const codegen = await import('../generated/gen');
if (srcProp === undefined) {
setSrc(codegen.needle_exported_files);
}
} catch (e) {
console.error(e);
}
}
importCodeGen();
}, [srcProp]);
if (!isClient) return null;
const setVisible = (show: boolean) => {
try {
const script = GameObject.findObjectOfType(MyScript);
script?.setVisible(show);
} catch (error) {
console.error({ error });
}
};
...```
In this example it seems unneccesary to have two script files, but i just simplified it to make it a little clearer.