refactored scripts to avoid execution order issues
This commit is contained in:
@ -107,7 +107,7 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
{
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
StartListening();
|
||||
StartCoroutine(WaitAndSubscribe());
|
||||
|
||||
// Immediately try to assign an enabled NPC
|
||||
if (useActiveNPC && targetNPC == null)
|
||||
@ -227,13 +227,6 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
|
||||
try
|
||||
{
|
||||
// Wait for shared listener to be ready
|
||||
if (SharedUDPListener.Instance == null)
|
||||
{
|
||||
ConvaiLogger.Error("SharedUDPListener not found! Make sure it's in the scene.", ConvaiLogger.LogCategory.Character);
|
||||
return;
|
||||
}
|
||||
|
||||
// Subscribe to shared listener
|
||||
SharedUDPListener.Instance.OnPacketReceived += HandlePacketReceived;
|
||||
_isListening = true;
|
||||
@ -246,6 +239,22 @@ namespace Convai.Scripts.Runtime.Multiplayer
|
||||
ConvaiLogger.Error($"Stack trace: {ex.StackTrace}", ConvaiLogger.LogCategory.Character);
|
||||
}
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator WaitAndSubscribe()
|
||||
{
|
||||
float timeout = 3f;
|
||||
while (SharedUDPListener.Instance == null && timeout > 0f)
|
||||
{
|
||||
timeout -= Time.unscaledDeltaTime;
|
||||
yield return null;
|
||||
}
|
||||
if (SharedUDPListener.Instance == null)
|
||||
{
|
||||
ConvaiLogger.Error("SharedUDPListener not ready after wait.", ConvaiLogger.LogCategory.Character);
|
||||
yield break;
|
||||
}
|
||||
StartListening();
|
||||
}
|
||||
|
||||
public void StopListening()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user