Entity.clone() not deep cloning attributes

I’m trying to clone a object I have on the scene with the following code:

const tile = this.prefab.clone();

And then firing up a function in one of the object scripts like this:

    tile: cell,
    delayFactor: 0.2,

I manage to clone the object but the new object doesn’t have the script attributes from the original prefab

This worked a couple of days ago so I don’t know If there was an API change for deep cloning an object or something else I’m missing.

I think what is happening is that the new cloned object is not calling the Initialize method, is there any way I can force it ?

Would you be able to provide a simple reproducible project so we can check it out?

This is exactly my issue, and it happens when cloning disabled objects.

I opened a bug report on GitHub and I’d need a bit of support to find a solution:

Guys we have pushed a fix for this in the Engine’s master branch. Would you be able to test if this fixes the issues you mentioned? You can follow the steps here to run with the master engine: https://developer.playcanvas.com/en/user-manual/scripting/custom_engine/


1 Like

I’ll test it asap (max by tomorrow). Thanks!

1 Like

Yes I confirm that until 1.0.0 the script values were uninitialized until the cloned entity gets enabled.
In the last release 1.0.1 it works as expected, right after cloning.