/// <summary>
        /// Sets the world matrix.
        /// </summary>
        /// <param name="worldMatrix">The world matrix.</param>
        /// <param name="source">The source object that caused this change or null when not important.</param>
        public override void SetWorldMatrix(MatrixD worldMatrix, object source = null)
        {
            MyUtils.AssertIsValid(worldMatrix);

            ProfilerShort.Begin("Scale");
            if (Scale != null)
            {
                MyUtils.Normalize(ref worldMatrix, out worldMatrix);
                worldMatrix = MatrixD.CreateScale(Scale.Value) * worldMatrix;
            }
            ProfilerShort.End();
            MatrixD localMatrix;

            if (this.Container.Entity.Parent == null)
            {
                m_previousParentWorldMatrix = this.m_worldMatrix;
                this.m_worldMatrix          = worldMatrix;
                localMatrix = worldMatrix;
            }
            else
            {
                MatrixD matParentInv = MatrixD.Invert(this.Container.Entity.Parent.WorldMatrix);
                localMatrix = (Matrix)(worldMatrix * matParentInv);
            }

            ProfilerShort.Begin("EqualsFast");
            if (!m_localMatrix.EqualsFast(ref localMatrix) || !m_previousParentWorldMatrix.EqualsFast(ref worldMatrix))
            {
                ProfilerShort.BeginNextBlock("UpdateWM");
                m_localMatrixChanged = true;
                this.m_localMatrix   = localMatrix;
                UpdateWorldMatrix(source);
                ProfilerShort.BeginNextBlock("sync");
                if (MyPerGameSettings.MultiplayerEnabled)
                {
                    if (this.Container.Entity.InScene && source != m_syncObject && ShouldSync && this.Container.Entity.Parent == null)
                    {
                        m_syncObject.UpdatePosition();
                    }
                }
            }
            ProfilerShort.End();
        }
        /// <summary>
        /// Called when [world position changed].
        /// </summary>
        /// <param name="source">The source object that caused this event.</param>
        public override void OnWorldPositionChanged(object source)
        {
            Debug.Assert(source != this && (Container.Entity == null || source != Container.Entity), "Recursion detected!");
            ProfilerShort.Begin("Volume");
            UpdateWorldVolume();
            ProfilerShort.BeginNextBlock("Prunning.Move");
            MyGamePruningStructure.Move(Container.Entity as MyEntity);

            ProfilerShort.BeginNextBlock("Children");
            UpdateChildren(source);

            ProfilerShort.BeginNextBlock("Raise");
            RaiseOnPositionChanged(this);

            ProfilerShort.BeginNextBlock("Action");
            if (WorldPositionChanged != null)
            {
                WorldPositionChanged(source);
            }
            ProfilerShort.End();
        }
        /// <summary>
        /// Updates the world matrix (change caused by this entity)
        /// </summary>
        public override void UpdateWorldMatrix(object source = null)
        {
            if (this.Container.Entity.Parent != null)
            {
                MatrixD parentWorldMatrix = this.Container.Entity.Parent.WorldMatrix;
                UpdateWorldMatrix(ref parentWorldMatrix, source);
                return;
            }

            //UpdateWorldVolume();
            ProfilerShort.Begin("OnChanged");
            OnWorldPositionChanged(source);

            ProfilerShort.BeginNextBlock("Physics.Onchanged");
            if (this.Container.Entity.Physics != null && this.m_physics.Enabled && this.m_physics != source)
            {
                this.m_physics.OnWorldPositionChanged(source);
            }
            ProfilerShort.End();
            m_normalizedInvMatrixDirty = true;
            m_invScaledMatrixDirty     = true;
            // NotifyEntityChange(source);
        }