diff --git a/engine/src/core/com/jme3/scene/control/AbstractControl.java b/engine/src/core/com/jme3/scene/control/AbstractControl.java index abfa2a85d..39ebc14e8 100644 --- a/engine/src/core/com/jme3/scene/control/AbstractControl.java +++ b/engine/src/core/com/jme3/scene/control/AbstractControl.java @@ -82,6 +82,29 @@ public abstract class AbstractControl implements Control { */ protected abstract void controlRender(RenderManager rm, ViewPort vp); + /** + * Default implementation of cloneForSpatial() that + * simply clones the control and sets the spatial. + *
+ * AbstractControl c = clone(); + * c.spatial = null; + * c.setSpatial(spatial); + *+ * + * Controls that wish to be persisted must be Cloneable. + */ + @Override + public Control cloneForSpatial(Spatial spatial) { + try { + AbstractControl c = (AbstractControl)clone(); + c.spatial = null; // to keep setSpatial() from throwing an exception + c.setSpatial(spatial); + return c; + } catch(CloneNotSupportedException e) { + throw new RuntimeException( "Can't clone control for spatial", e ); + } + } + public void update(float tpf) { if (!enabled) return;