Maintaining behavior defaults from cloned object
oranjoose

Correct me if I'm wrong, but it appears that when you clone a Scene Object, the clone does not carry the behavior's custom properties as set in the editor. Take the following behavior for example:

MyBehavior = function () {
  this.myProperty = 0;
};

Then, say myProperty is set in the properties panel in the editor to have a different value. Let's say the value 1 as an example. If I were to clone this object, it appears the clone's myProperty is taking the script's default of 0, rather than the clone's myProperty value of 1.

This is pretty inconvenient for me. The behavior I want to create is generalized across all Scene Objects, and this issue is impelling me toward writing some pretty icky code, like trying to get the behavior owner's template (from which the clone was made) through sprite names (since clones don't carry the template object's name by default) to get the template object's behavior's property values. Gross. I'd prefer not to muck around too much with the SceneObject's prototype, especially since behaviors are pretty elegant and portable.

But if there's nothing ado about this, then I suppose it should be a pretty low impact workaround to modify the SceneObject's prototype clone function to carry a reference to the template object that produced the clone, within the clone, in order to grab those property values set from the editor.

Does this make sense? Basically I'm asking why clones don't inherent the template's behavior's property values. In my opinion, it is more useful to keep the template's values than to grab defaults from the script.

Thanks.

1 Comment
Gio

Hi

It's certainly not like that by design - just an oversight. It's an easy fix, it'll be in the next release.

Thanks for pointing it out and for your other suggestions too.

Post a reply
Add Attachment
Submit Reply
Login to Reply