- Home /
problem using OnStartServer() for unity multiplayer networked game
Hello everyone I am making a football game which you control one player from the team. It will connect 11v11 players per server (using a "Host" acting as server and client, and other clients connecting to them)
I believe I have followed the examples and information provided by Unity to the letter, but I can't seem to get it working properly.
The problem: My code seems to work fine, provided I open the 'Host' instance from the Unity Editor, but if I make the full build version the Host it doesnt work.
Strangely all my player-objects will all spawn and act exactly as I intended, but the ball will not spawn unless the 'Host' instance is the one opened inside Unity Editor. I've made the Ball a Network Identity, NetworkTransform etc and Registered Prefab in the NetworkManager in inspector.
Here's the code I am using to spawn the ball on the server, what could be the problem as I really have no ideas, thanks:
using UnityEngine;
using UnityEngine.Networking;
public class MatchdayManager : NetworkBehaviour {
GameObject ballPrefab;
private void Awake()
{
DontDestroyOnLoad(this);
ballPrefab = Resources.Load<GameObject>("Prefabs/Ball");
}
public override void OnStartServer()
{
Debug.Log("on server start called");
GameObject go = Instantiate(ballPrefab);
NetworkServer.Spawn(go);
}
}