@@ -2598,7 +2598,6 @@ export class Control implements IAnimatable, IFocusableControl {
2598
2598
public clone ( host ?: AdvancedDynamicTexture ) : Control {
2599
2599
const serialization : any = { } ;
2600
2600
this . serialize ( serialization , true ) ;
2601
-
2602
2601
const controlType = Tools . Instantiate ( "BABYLON.GUI." + serialization . className ) ;
2603
2602
const cloned = new controlType ( ) ;
2604
2603
cloned . parse ( serialization , host ) ;
@@ -2634,6 +2633,16 @@ export class Control implements IAnimatable, IFocusableControl {
2634
2633
if ( ! this . isSerializable && ! force ) {
2635
2634
return ;
2636
2635
}
2636
+ let idealWidth = 0 ;
2637
+ let idealHeight = 0 ;
2638
+ // the host's ideal width and height are influencing the serialization, as they are used in getValue() of ValueAndUnit.
2639
+ // for a proper serialization, we need to temporarily set them to 0 and re-set them back afterwards.
2640
+ if ( this . host ) {
2641
+ idealHeight = this . host . idealHeight ;
2642
+ idealWidth = this . host . idealWidth ;
2643
+ this . host . idealWidth = 0 ;
2644
+ this . host . idealHeight = 0 ;
2645
+ }
2637
2646
SerializationHelper . Serialize ( this , serializationObject ) ;
2638
2647
serializationObject . name = this . name ;
2639
2648
serializationObject . className = this . getClassName ( ) ;
@@ -2662,6 +2671,11 @@ export class Control implements IAnimatable, IFocusableControl {
2662
2671
2663
2672
// Animations
2664
2673
SerializationHelper . AppendSerializedAnimations ( this , serializationObject ) ;
2674
+ // re-set the ideal width and height
2675
+ if ( this . host ) {
2676
+ this . host . idealWidth = idealWidth ;
2677
+ this . host . idealHeight = idealHeight ;
2678
+ }
2665
2679
}
2666
2680
2667
2681
/**
0 commit comments