Playcanvas API changed?

Hi,

I have a Playcanvas project with some instructions that used to work but don’t work now:

For instance:

entity.script.create(“nameOfTheScript”);

What is the syntax for script creation now??

this.app.scene.skybox.setSource(imageArray);

What is the syntax for changing the skyBox textures now??

Thanks in advance.

Is it shareable? Would it be possible to post a link to it please?

Well, I prefer not to share the whole project.

Anyway, it seems that the API has changed and there are several things that I used to do that don’t work anymore, like creating a script or accessing the skybox.

They don’t work because the function does not exist anymore, so the project would not provide much information. I just need to know the new syntax.

AFAIK, the API hasn’t changed since 2016 for creating new scripts.

var OrbitCamera = pc.createScript('orbitCamera');

OrbitCamera.prototype.initialize = function () {
    var self = this;
    var onWindowResize = function () {
        self._checkAspectRatio();
    };
};

//etc

The method you have shown above is to add a new script instance of an existing script type that is in the registry to an entity and still exists in the engine code https://github.com/playcanvas/engine/blob/master/src/framework/components/script/component.js#L326

This code worked last week:

var entity = new pc.Entity();
 entity.script.create("nameOfScript");

Now it does not work…

I mean, the code for ASSIGNING an existing script to an entity.
Not the code for designing a script…

It’s different.

Are you using the Editor or just the engine? The API hasn’t changed so if you don’t want to share your whole project just add me to take a look. My username is vaios.

I think you first need to attach the script component to the entity.

entity.addComponent(“script”);

then you can use the script component “entity.script.create” :slight_smile:

Thanks,

I have solved it changing the code, but I am 99,99% sure, this code was working last week…

I have solved with your suggestion ( entity.addComponent(“script”); ) but I didn’t use this line before, and the code was working…

Very strange.
Are you sure the API hasn’t changed???

this.app.scene.skybox.setSource(imageArray);

was also working and does not work now either…

I think the dev team launched an important update of the engine (or are about to), so maybe there’s things that change! Always happen on evolving software, no biggie, we can help each other.

the setSource doesn’t appear to have changed tho:

https://developer.playcanvas.com/en/api/pc.Texture.html

The function is still there in the docs.

I think the problem is that

this.app.scene.skybox defaults to null

I am almost sure it wasn’t that way before.

Again that all sounds weird. First of all you’re saying that before you were able to create a new entity and call entity.script.create on it without adding a script component? That would have never worked. They skybox would be null if you didn’t set one for you scene.

My impression is that something has changed in your project - otherwise if you can add me to a project that shows this behaviour then I could have a look.

I’ll double check if something has changed in my project.
Maybe you are right.

Ok,
this one was my fault.
Sorry!

But I am sure there are other things that have changed, like

entity.script.create

that I was using without addComponent()

I was also using

var texture = new pc.Texture();

and now it needs to have the graphicsDevice. Otherwise it doesn’t work.

var texture = new pc.Texture(graphicsDevice);

Several things have changed recently.
That’s for sure.

Thanks anyway!

When was the last time you were using PlayCanvas that these previously worked?

I don’t remember well.
It could be 2 weeks, 3 weeks, or a month. Something like that.

Very strange… I’m looking at the repo for Dec 2017 and pc.Texture API had always had graphicsDevice as a param: https://github.com/playcanvas/engine/blob/d71de2d143dee4d39498950093b8037a2fe8fc6e/src/graphics/texture.js#L88

It’s very odd that it worked before :thinking:

Yes.
It did have the graphicsDevice as a param, but it worked without.

Okay, there is a way to figure it out for sure.

You have to run your project with old build.

https://developer.playcanvas.com/en/user-manual/scripting/custom_engine/