Missing HostManager

Hi

This could have been handled later in the course, otherwise…

I can’t seem to properly figure out why I am missing the HostManager gameobject. In the video at 6:22 I can see ClientManager and HostManager have been created.

However at 19:25 I can see the HostManager has mysteriously vanished. I get the same behaviour in my project.

I believe this maybe because the HostManager has not been created yet before the scene is switched. If I comment out the scene change:

if (authenticated)
{
   // clientSingleton.GameManager.GoToMenu();
}

And run, then I can see the ClientManager is created immediately but the HostManager takes a second to appear. That’s a mystery as the HostManager doesn’t have any code to delay it’s creation.

Removing my comment above and switching ClientManager and HostManager creation order to:

HostSingleton hostSingleton = Instantiate(hostPrefab);
hostSingleton.CreateHost();

ClientSingleton clientSingleton = Instantiate(clientPrefab);
bool authenticated = await clientSingleton.CreateClient();

if (authenticated)
{
   clientSingleton.GameManager.GoToMenu();
}

This now works and I see both ClientManager and HostManager on the Menu Scene.

Generally I have always found my objects are instantiated immediately but I don’t play around with asynchonous programming.

Any ideas why this is happening?

Thanks!

This is actually discussed later in the “Allocating A Relay” lesson. In that lesson, around 11:32, Nathan discovers the non existence of the HostSingleton.

Funnily his fix was what I tried above. Nathan does supply the correct reasoning for this odd behaviour; the Start method of the HostSingleton is never called, therefore DontDestroyOnLoad is not called in time before the scene is changed.

This is easily observed by putting the

DontDestroyOnLoad(hostSingleton)

in the LaunchInMode method. Alternatively, adding

await Task.Delay(1);

seems to be sufficient time for Unity to run the HostSingleton Start method.

However, with more objects, it maybe better to have some overall checker inspect the all objects have been properly created and then change scenes.

In any case mystery solved.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms