How to clone a component instance with different component definition


#1

how to clone a component instance with different component definition


#2

By “cloning” you mean to insert a component instance that has all (or most) its properties identical to a source component of the same definition, for example same position, transformation etc.

You cannot change the definition after having inserted an instance.

But you can insert an instance of different definition, and then apply the same properties:

instance_a # is of definition_a
instance b = entities.add_instance(definition_b, instance_a.transformation)
# Transfer the properties
instance_b.visible = instance_a.visible?
instance_b.material = instance_a.material
…

#4

Credits to @sjdorst for mentioning make unique. If you mean not an existing “different definition”, you can create a new definition on the fly:

instance_b = entities.add_instance(instance_a.definition, IDENTITY)
instance_b.make_unique # Now instance_b.definition is different from instance_a.definition

#5

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.