Right, well The scriptableObject there is to host static data regarding that incredient. You might need to work around that.
For picking stuff up, you just need to playerPickupHolder.add(foodObject);
Where both are Object3D / GameObject.
Right, well The scriptableObject there is to host static data regarding that incredient. You might need to work around that.
For picking stuff up, you just need to playerPickupHolder.add(foodObject);
Where both are Object3D / GameObject.
Try out some stuff and return back if something doesn’t work
for this i can create like json file ?
by user 691445074055397447
ok ok thank you for your help
by user 691445074055397447
You can make behaviours and attached them to game objects and then use these as references. ScriptableObject is just an object without game object, and so it can possibly be on an object if you know that it won’t ever get destroyed.
Oh, okay, perfect! Thank you very much for your help.
by user 691445074055397447
Just to add to that: you can use ScriptableObjects and export them if you need to / the tutorial asks you to. Just create a class in typescript with the name of your scriptable object and use it in a field of your component.
Here’s a minimal example (it just prints some things to the browser console)
You can add this to your scripts
folder e.g. inside scripts/ScriptableObjectTest.ts
export class MySO {
test!: number[];
Hello(){
return "Hello"
}
}
export class IHaveAnSO extends Behaviour {
@serializable(MySO)
mySo?: MySO;
start(): void {
console.log('IHaveAnSO.start', this.mySo, this.mySo?.test, this.mySo?.Hello());
this.mySo?.test.push(1);
}
}
The scriptable object in Unity C#
[CreateAssetMenu(menuName = "MyScriptableObject")]
public class MySO : ScriptableObject
{
public List<int> test;
public void Hello(){}
}
Ohhh, okay, perfect! Thank you very much. Now I understand better.
by user 691445074055397447
I have tried this approach in a new scene on Needle 3.47.3, but MySO does not appear as a serialized field in the inspector on the IHaveAnSO component.
The codegen for IHaveAnSO says “Could not resolve C’ type” next to the MySO variable.
import { Behaviour, serializable } from "@needle-tools/engine";
import { MySO } from "./MySO";
export class IHaveAnSO extends Behaviour {
@serializable(MySO)
public mySO! : MySO;
public start() {
console.log('IHaveAnSO started');
}
update(): void {
}
}
The MySO.ts script (A separate script to the IHaveAnSO.ts script)
export class MySO {
test!: number[];
Hello(){
return "Hello"
}
}
![CouldNotResolveCSharpType|690x152]
Is there something fundamentally wrong I have done here?
Hi, ScriptableObjects do work but you need to create the ScriptableObject type In Unity. So make sure you have a MySO C# ScriptableObject in Unity. Then the code generator will pick it up and you can assign it.
(See the Warning at the bottom of your script “CouldNotResolveCSharpType” - this is telling you that the matching C# ScriptableObject doest not exist in Unity. The ComponentCompiler does only generate Components and no other types)
Hey Marcel, I have created the Scriptable object, exactly as above, but I still have the same “Can not resolve C # type” in the codegen
I have created an instance of a SO via the context menu, so that itself is fine, however my IHaveAnSO script codegen still cant resolve the type
Hi, you can always also force the compiler to generate the field you expect. See the table here with // @type
- in your case you’d add a comment above your field with //@type MySO