Skip to content

Commit

Permalink
Initialize NM only once during Start (MirrorNetworking#101)
Browse files Browse the repository at this point in the history
* Initialize NM only once during Start

* fix tests, don't start on headless
  • Loading branch information
paulpach committed Mar 22, 2020
1 parent 4fe92b2 commit c3d3209
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
16 changes: 2 additions & 14 deletions Assets/Mirror/Runtime/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ public virtual void OnValidate()
}

/// <summary>
/// virtual so that inheriting classes' Awake() can call base.Awake() too
/// virtual so that inheriting classes' Start() can call base.Start() too
/// </summary>
public virtual void Awake()
public virtual void Start()
{
Debug.Log("Thank you for using Mirror! https://mirror-networking.com");

Expand All @@ -202,13 +202,7 @@ public virtual void Awake()

// setup OnSceneLoaded callback
SceneManager.sceneLoaded += OnSceneLoaded;
}

/// <summary>
/// virtual so that inheriting classes' Start() can call base.Start() too
/// </summary>
public virtual void Start()
{
// headless mode? then start the server
// can't do this in Awake because Awake is for initialization.
// some transports might not be ready until Start.
Expand Down Expand Up @@ -246,7 +240,6 @@ bool IsServerOnlineSceneChangeNeeded()
void SetupServer()
{
if (LogFilter.Debug) Debug.Log("NetworkManager SetupServer");
Initialize();

ConfigureServerFrameRate();

Expand Down Expand Up @@ -316,8 +309,6 @@ public void StartClient(string serverIp)
{
mode = NetworkManagerMode.ClientOnly;

Initialize();

isNetworkActive = true;

RegisterClientMessages();
Expand All @@ -342,9 +333,6 @@ public void StartClient(string serverIp)
public void StartClient(Uri uri)
{
mode = NetworkManagerMode.ClientOnly;

Initialize();

isNetworkActive = true;

RegisterClientMessages();
Expand Down
3 changes: 1 addition & 2 deletions Assets/Mirror/Tests/Play/ClientServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ public void SetupServer()
manager.server = networkManagerGo.GetComponent<NetworkServer>();
server = manager.server;
client = manager.client;

manager.startOnHeadless = false;
manager.autoCreatePlayer = false;

manager.StartServer();
}

public void SetupClient(string hostname = "localhost")
Expand Down
11 changes: 9 additions & 2 deletions Assets/Mirror/Tests/Play/FlagsTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

namespace Mirror.Tests
{
Expand Down Expand Up @@ -45,10 +47,15 @@ public class FlagsTests : ClientServerTests
SampleBehavior behavior2;
Flags flags;

[SetUp]
public void SetupNetworkServer()
[UnitySetUp]
public IEnumerator SetupNetworkServer()
{

SetupServer();
// wait for manager to initialize
yield return null;

manager.StartServer();

playerGO = new GameObject();
playerGO.AddComponent<NetworkIdentity>();
Expand Down
1 change: 1 addition & 0 deletions Assets/Mirror/Tests/Play/HostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public IEnumerator SetupHost()

manager.StartHost();


playerGO = new GameObject();
identity = playerGO.AddComponent<NetworkIdentity>();
component = playerGO.AddComponent<T>();
Expand Down

0 comments on commit c3d3209

Please sign in to comment.