engine
engine copied to clipboard
attribute setter will clone Entity, if new value setted
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.
Can you link directly to the line you are referring to please and maybe a small code example?
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.