You need to export the class and
> runtime.objects.plr.setInstanceClass(plr.plr);
the first plr is the module, the second plr is the class.
Hello, ok thank you.
So basically, i noticed why it was working for me before.
If i set instance class of a instance in main, you both are right i have to export the subclass and then use plr.plr
However, i noticed, if i add the runOnStartUp in my subclass file, i dont have to export the class at all, and it works aswell.
Look at the Player class here:
class PlayerInstance extends globalThis.InstanceType.Player
{
constructor()
{
super();
console.log("Created!");
}
}
runOnStartup(async runtime =>
{
// Code to run on the loading screen.
// Note layouts, objects etc. are not yet available.
runtime.objects.Player.setInstanceClass(PlayerInstance);
runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime));
});
async function OnBeforeProjectStart(runtime)
{
// Code to run just before 'On start of layout' on
// the first layout. Loading has finished and initial
// instances are created and available to use here.
runtime.addEventListener("tick", () => Tick(runtime));
}
function Tick(runtime)
{
// Code to run every tick
}
Then i just import the class in main, without using export at all.
HOWEVER, if i setInstanceClass in main, i will have to do PlayerInstance.PlayerInstance like you mentioned, and i have to export the subclass.
Thanks for clearing this out guys, i was confused after a few hours of work yesterday.
Have a great weekend!