diff --git a/Assets/UdonSharp/Editor/Editors/UdonSharpGUI.cs b/Assets/UdonSharp/Editor/Editors/UdonSharpGUI.cs index 3d51cf93..b7dc28a9 100644 --- a/Assets/UdonSharp/Editor/Editors/UdonSharpGUI.cs +++ b/Assets/UdonSharp/Editor/Editors/UdonSharpGUI.cs @@ -1361,6 +1361,9 @@ internal static void DrawSyncSettings(UdonBehaviour behaviour) foreach (UdonBehaviour otherBehaviour in behavioursOnObject) { + if (otherBehaviour.programSource is UdonSharpProgramAsset otherBehaviourProgram && otherBehaviourProgram.behaviourSyncMode == BehaviourSyncMode.NoVariableSync) + continue; + if (otherBehaviour.Reliable) hasReliableSync = true; else @@ -1369,9 +1372,10 @@ internal static void DrawSyncSettings(UdonBehaviour behaviour) if (hasContinuousSync && hasReliableSync) { - if (programAsset.behaviourSyncMode == BehaviourSyncMode.NoVariableSync) - EditorGUILayout.HelpBox("NoVariableSync mode uses Continuous sync mode internally. You are mixing sync methods between UdonBehaviours on the same game object, this will cause all behaviours to use the sync method of the last component on the game object.", MessageType.Error); - else + //if (programAsset.behaviourSyncMode == BehaviourSyncMode.NoVariableSync) + // EditorGUILayout.HelpBox("NoVariableSync mode uses Continuous sync mode internally. You are mixing sync methods between UdonBehaviours on the same game object, this will cause all behaviours to use the sync method of the last component on the game object.", MessageType.Error); + //else + if (programAsset.behaviourSyncMode != BehaviourSyncMode.NoVariableSync) EditorGUILayout.HelpBox("You are mixing sync methods between UdonBehaviours on the same game object, this will cause all behaviours to use the sync method of the last component on the game object.", MessageType.Error); } } diff --git a/Assets/UdonSharp/Editor/UdonSharpEditorManager.cs b/Assets/UdonSharp/Editor/UdonSharpEditorManager.cs index ec9491e8..d064de2f 100644 --- a/Assets/UdonSharp/Editor/UdonSharpEditorManager.cs +++ b/Assets/UdonSharp/Editor/UdonSharpEditorManager.cs @@ -567,31 +567,23 @@ static void UpdateSyncModes(List udonBehaviours) if (behaviour.programSource == null || !(behaviour.programSource is UdonSharpProgramAsset programAsset)) continue; - int originalModificationcount = modificationCount; - behaviourGameObjects.Add(behaviour.gameObject); - if (behaviour.Reliable == true && - (programAsset.behaviourSyncMode == BehaviourSyncMode.Continuous || - programAsset.behaviourSyncMode == BehaviourSyncMode.NoVariableSync)) + if (behaviour.Reliable == true && programAsset.behaviourSyncMode == BehaviourSyncMode.Continuous) { behaviour.Reliable = false; modificationCount++; + PrefabUtility.RecordPrefabInstancePropertyModifications(behaviour); } else if (behaviour.Reliable == false && programAsset.behaviourSyncMode == BehaviourSyncMode.Manual) { behaviour.Reliable = true; modificationCount++; - } - - if (originalModificationcount != modificationCount) PrefabUtility.RecordPrefabInstancePropertyModifications(behaviour); + } } - if (modificationCount > 0) - EditorSceneManager.MarkAllScenesDirty(); - - // Validation for mixed sync modes which can break sync on things + // Validation for mixed sync modes which can break sync on things and auto update NoVariableSync behaviours to match the sync mode of other behaviours on the GameObject foreach (GameObject gameObject in behaviourGameObjects) { UdonBehaviour[] objectBehaviours = gameObject.GetComponents(); @@ -599,9 +591,17 @@ static void UpdateSyncModes(List udonBehaviours) bool hasManual = false; bool hasContinuous = false; bool hasUdonPositionSync = false; + bool hasNoSync = false; foreach (UdonBehaviour objectBehaviour in objectBehaviours) { + if (UdonSharpEditorUtility.IsUdonSharpBehaviour(objectBehaviour) && + ((UdonSharpProgramAsset)objectBehaviour.programSource).behaviourSyncMode == BehaviourSyncMode.NoVariableSync) + { + hasNoSync = true; + continue; + } + if (objectBehaviour.Reliable) hasManual = true; else @@ -624,7 +624,47 @@ static void UpdateSyncModes(List udonBehaviours) if (hasUdonPositionSync) Debug.LogWarning($"[UdonSharp] UdonBehaviours on GameObject '{gameObject.name}' are using manual sync while position sync is enabled on an UdonBehaviour on the GameObject, this can cause sync to work unexpectedly.", gameObject); } + + if (hasNoSync) + { + int conflictCount = 0; + + if (hasManual && hasContinuous) + ++conflictCount; + if (hasManual && (hasUdonPositionSync || gameObject.GetComponent())) + ++conflictCount; + + if (conflictCount > 0) + { + Debug.LogWarning($"[UdonSharp] Cannot update sync mode on UdonSharpBehaviour with NoVariableSync on '{gameObject}' because there are conflicting sync types on the GameObject", gameObject); + continue; + } + + foreach (UdonBehaviour behaviour in objectBehaviours) + { + if (behaviour.programSource is UdonSharpProgramAsset programAsset && programAsset.behaviourSyncMode == BehaviourSyncMode.NoVariableSync) + { + if (hasManual && !behaviour.Reliable) + { + behaviour.Reliable = true; + modificationCount++; + + PrefabUtility.RecordPrefabInstancePropertyModifications(behaviour); + } + else if (behaviour.Reliable) + { + behaviour.Reliable = false; + modificationCount++; + + PrefabUtility.RecordPrefabInstancePropertyModifications(behaviour); + } + } + } + } } + + if (modificationCount > 0) + EditorSceneManager.MarkAllScenesDirty(); } static bool UdonSharpBehaviourTypeMatches(object symbolValue, System.Type expectedType, string behaviourName, string variableName)