diff --git a/unity/DigAndAnnotate/Assets/iwsd_vrc/Tools/OnEditorEmu/Scripts/Emu_Trigger.cs b/unity/DigAndAnnotate/Assets/iwsd_vrc/Tools/OnEditorEmu/Scripts/Emu_Trigger.cs index d63420e..abfea83 100644 --- a/unity/DigAndAnnotate/Assets/iwsd_vrc/Tools/OnEditorEmu/Scripts/Emu_Trigger.cs +++ b/unity/DigAndAnnotate/Assets/iwsd_vrc/Tools/OnEditorEmu/Scripts/Emu_Trigger.cs @@ -23,7 +23,7 @@ internal Val_Trigger(VRCSDK2.VRC_Trigger vrcTrigger) } - class Emu_Trigger : MonoBehaviour + public class Emu_Trigger : MonoBehaviour { // [SerializeField] // TODO Make trigger definition visible with Unity inspector to debug scene. Val_Trigger vrcTrigger; @@ -355,7 +355,7 @@ private LayerMask GetLayerMaskOf(VRCSDK2.VRC_Trigger.TriggerType triggerType) { if (vrcTrigger == null) { - Iwlog.Error(gameObject, "vrcTrigger == null"); + Iwlog.Trace(gameObject, "vrcTrigger == null"); return Enumerable.Empty(); } @@ -739,9 +739,13 @@ private ActionResult Execute_SpawnObject(GameObject receiver, VRCSDK2.VRC_EventH // true: includeInactive foreach (var comp in newOne.GetComponentsInChildren(true)) { - comp.gameObject.AddComponent(); + comp.gameObject.GetOrAddComponent(); } - + // In-scene prefab references are spawned as inactive game objects. + // Usually the root object has an OnSpawn -> SetGameObjectActive true, + // but the Emu_Trigger cannot execute before the object is Awake(). + // To workaround this, we force the newly spawned object active. + newOne.SetActive(true); foreach (var comp in newOne.GetComponentsInChildren(false)) { comp.ExecuteTriggers(VRCSDK2.VRC_Trigger.TriggerType.OnSpawn); diff --git a/unity/DigAndAnnotate/Assets/iwsd_vrc/Tools/OnEditorEmu/Scripts/InUnityDebug.cs b/unity/DigAndAnnotate/Assets/iwsd_vrc/Tools/OnEditorEmu/Scripts/InUnityDebug.cs index 436780b..ec21e45 100644 --- a/unity/DigAndAnnotate/Assets/iwsd_vrc/Tools/OnEditorEmu/Scripts/InUnityDebug.cs +++ b/unity/DigAndAnnotate/Assets/iwsd_vrc/Tools/OnEditorEmu/Scripts/InUnityDebug.cs @@ -116,7 +116,7 @@ static private void Setup_TriggersComponents() } // Emu_Trigger find brother VRC_Trigger by itself - var emu_trigger = triggerComp.gameObject.AddComponent(); + var emu_trigger = triggerComp.gameObject.GetOrAddComponent(); emu_trigger.debugString = triggerComp.gameObject.name; } diff --git a/unity/DigAndAnnotate/Assets/iwsd_vrc/Tools/OnEditorEmu/Scripts/LocalPlayerContext.cs b/unity/DigAndAnnotate/Assets/iwsd_vrc/Tools/OnEditorEmu/Scripts/LocalPlayerContext.cs index a4f3471..803c81a 100644 --- a/unity/DigAndAnnotate/Assets/iwsd_vrc/Tools/OnEditorEmu/Scripts/LocalPlayerContext.cs +++ b/unity/DigAndAnnotate/Assets/iwsd_vrc/Tools/OnEditorEmu/Scripts/LocalPlayerContext.cs @@ -65,7 +65,11 @@ private static Dictionary makeAssetPathMap(List objects) #if UNITY_EDITOR // This implementation requires UnityEditor. foreach (T obj in objects) { - var p = UnityEditor.AssetDatabase.GetAssetPath(obj); + var p = UnityEditor.AssetDatabase.GetAssetPath(obj); + if (p == null || p.Length == 0) { + // in-scene prefab references use the object name. + p = obj.name; + } Iwlog.Trace("asset path='" + p + "'"); if (map.ContainsKey(p)) { Iwlog.Warn("Duplicate?: path='" + p + "'");