How to create an instance of a class

Hello. If I create a class in a script, dont use scriptRegistry, how do I access it and create an instance in another pc script? For example import/export

Hi @sergey_ch,

You can’t use modules (import/export) in PlayCanvas scripts.

But any global class (available in the window context) can be referenced and instantiated in other script files.

Can you explain a bit more on what you are trying to do?

I have class. I don’t want to create it via pc.createScript. There is a second script that is created via pc.createScript and attached to entity. How do I get access to the first script, in the second. In C# I would use namespace for example. In js + webpack would connect the script via import/export.

Now I just created a class in one editor window. It works, but I want to physically split the scripts into two files.

Ensure that the file that the class is in is above the where you use it in the script loading order of the project settings

And you just use it as you do normally.

All PlayCanvas does add the script file into the body of the HTML in the order of the Scripts Loading Order.

1 Like