-
-
Notifications
You must be signed in to change notification settings - Fork 305
Network Instantiation Flush
After creating or joining a server it is necessary to call NetworkObject.Flush on the related NetWorker. This is to notify Forge that unity is ready and it is possible to spawn NetworkBehaviors into the scene.
The function gets automatically called by the NetworkManager when you switch scenes if "Automatic Scenes" is ticked on said NetworkManager. (This is also what happens during the default MultiplayerMenu).
Note: Flush
needs to be called on both the server and the client
On the server:
int maxAllowedClients = 32;
UDPServer server = new UDPServer(maxAllowedClients);
server.Connect(port:8888);
NetworkManager.Instance.Initialize(server);
NetworkObject.Flush(server);
On the client when not switching scenes, or switching scenes manually:
//Networker client = new UDPClient();
client.serverAccepted += OnAccepted;
...
public void OnAccepted(NetWorker sender)
{
NetworkObject.Flush(sender);
}
If you are manually loading new scenes then Flush
needs to be called every time when the new scene loaded on both the server and the client. The easiest is to subscribe to Unity's SceneManager.sceneLoaded
event. Optionally you could use the NetworkManager.SceneReady
method just like it would be used when "Automatic Scenes" is turned on.
- Try turning off "Automatic Scenes" (NetworkManager) and "DontChangeScenesOnConnect" (MultiplayerMenu)
- Make sure you flush as shown above
If your networkObject is still null, the problem is likely that it exists before MultiplayerMenu (has created a server or client)
Try creating it locally, after MultiplayerMenu has executed to the point you have a network, or, if you want to be certain it works, simply Instantiate your networkObject when a connection is made.
Getting Started
Network Contract Wizard (NCW)
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
Master Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
-
Connection Cycle Events
-
Rewinding
-
Network Logging
-
Working with Multiple Sockets
-
Modify Master and Standalone servers
-
NAT Hole Punching
-
UDP LAN Discovery
-
Offline Mode
-
Ping Pong
-
Lobby System
-
Upgrading Forge Remastered to Develop branch or different version
-
Forge Networking Classic to Remastered Migration Guide
-
Script to easily use Forge Networking from sources
-
Run Two Unity Instances with Shared Assets for Easiest Dedicated Client Workflow