engine icon indicating copy to clipboard operation
engine copied to clipboard

attribute setter will clone Entity, if new value setted

Open Casval111 opened this issue 2 years ago • 2 comments

In class ScriptAttributes, attribute-setter will clone old value, if it is not json and has clone function. But, entities should not be cloned, in this situation. That may waste plenty of memory and time, if I had referenced Root entity previously.

Casval111 avatar Sep 09 '22 03:09 Casval111

Can you link directly to the line you are referring to please and maybe a small code example?

yaustar avatar Sep 09 '22 08:09 yaustar

https://github.com/playcanvas/engine/blob/ff5ebcb10c1561d27f5427797f9045122d81f77f/src/script/script-attributes.js#L290

test project https://playcanvas.com/project/980169/overview/attributetest In the scene, the "attr0" attribute of TestAttribute script, is assigned with BoxA entity, then assigned with BoxB. see console Usually, it should be "attr0 changed: "Root/BoxA" => "Root/BoxB" and "the old entity is the same one, BoxA". But, the console print "attr0 changed: "" => "Root/BoxB" and "the old entity is not the same one, BoxA". oOld !== boxA

I found that, attribute setter will clone Entity, if new value assign triggered.

Casval111 avatar Sep 09 '22 11:09 Casval111