I just want to instantiate a prefab that is assigned from the inspector in Unity. Here is my code
import {AssetReference, Behaviour, GameObject, serializable, InstantiateOptions} from "@needle-tools/engine";
import {Object3D} from "three";
export class BallSpawner extends Behaviour {
// @serializable(GameObject)
// ball: GameObject | null = null;
@serializable(AssetReference)
ball? : GameObject;
@serializable(Object3D)
spawnPoint: Object3D | null = null;
timer: number = 0;
public start(): void {
console.log("BallSpawner started");
console.log("BallSpawner ball: " + this.ball);
console.log("BallSpawner spawnPoint: " + this.spawnPoint);
}
public update(): void {
//instantiate the ball every 1 second
this.timer += this.context.time.deltaTime;
if (this.ball && this.spawnPoint && this.timer > 1) {
console.log("BallSpawner update");
GameObject.instantiate(this.ball) as GameObject;
const spawnPoint = this.spawnPoint;
//newBall.position.copy(spawnPoint.position);
this.timer = 0;
}
}
}```
When I try ```ts
@serializable(GameObject)
ball: GameObject | null = null; ```
I get the error: ```Detected wrong usage of @serializable with Object3D or GameObject. Instead you should use AssetReference here! Please see the console for details.```
and when I try ```ts
@serializable(AssetReference)
ball? : GameObject;```
i get the error:
```instance.clone is not a function```
[Original Post on Discord](https://discord.com/channels/717429793926283276/1154747892867809360)
*by user 216692838757433347*