From 0d36c30206865413d4aa197eb5392e06ff4f0fd0 Mon Sep 17 00:00:00 2001 From: mischa Date: Mon, 29 Apr 2024 12:22:37 +0800 Subject: [PATCH] fix(NetworkTransform): Awake now also configures syncInterval and syncScale, in case OnValidate wasn't called --- .../NetworkTransform/NetworkTransformBase.cs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs b/Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs index efedbb672..a30f5d9c0 100644 --- a/Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs +++ b/Assets/Mirror/Components/NetworkTransform/NetworkTransformBase.cs @@ -99,18 +99,9 @@ public abstract class NetworkTransformBase : NetworkBehaviour public Color overlayColor = new Color(0, 0, 0, 0.5f); // initialization ////////////////////////////////////////////////////// - // make sure to call this when inheriting too! - protected virtual void Awake() + // forcec configuration of some settings + protected virtual void Configure() { - // set target to self if none yet. - // OnValidate() already does this, but sometimes OnValidate() doesn't run before launching a project. - if (target == null) target = transform; - } - - protected override void OnValidate() - { - base.OnValidate(); - // set target to self if none yet if (target == null) target = transform; @@ -126,6 +117,22 @@ protected override void OnValidate() if (coordinateSpace == CoordinateSpace.World) syncScale = false; } + // make sure to call this when inheriting too! + protected virtual void Awake() + { + // sometimes OnValidate() doesn't run before launching a project. + // need to guarantee configuration runs. + Configure(); + } + + protected override void OnValidate() + { + base.OnValidate(); + + // configure in awake + Configure(); + } + // snapshot functions ////////////////////////////////////////////////// // get local/world position protected virtual Vector3 GetPosition() =>