Unity Troubleshooting Tips
Why is my Unity server vCPU usage unexpectedly high? / Unity job worker threads issue
Unity has an issue where it incorrectly determines the number of threads available to it when running in a container. The result is that vCPU usage becomes much higher than expected.
Try setting the job worker count to a lower number (e.g. 4):
- in a startup script:
JobsUtility.JobWorkerCount = 4;
- via command line argument
-job-worker-count 4
You may need to tweak the job worker count value to find teh optimal one for your use case.
Relevant Unity docs:
- https://docs.unity3d.com/ScriptReference/Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount.html
- https://docs.unity3d.com/ScriptReference/Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerMaximumCount.html
Can’t connect to server or connection failed, common causes
- Deployment configuration mismatch
- Port (in Hathora deployment config) doesn’t match port your server is listening on
- Transport type (in Hathora deployment config) doesn’t match the transport protocol your networking code expects
- Note: ws:// uses
TCP
, wss:// usesTLS
- Note: ws:// uses
- Server idle timeout
- By default, server processes in Hathora Cloud will spin down after 5 consecutive minutes of inactivity (no active connections)
- It is in our roadmap to support customization of the idle timeout
- By default, server processes in Hathora Cloud will spin down after 5 consecutive minutes of inactivity (no active connections)
- Client configuration
- Incorrect Hathora appId - If you are using multiple applications on Hathora, it’s possible that your appId is incorrect (this will usually lead to a 404 response from Hathora APIs
- Using hostname instead of IP address - some networking solutions (Mirror, Unity NGO) only support IP addresses rather than hostnames for connections. E.g. convert
1.proxy.hathora.dev
to one of a valid IP addressdig 1.proxy.hathora.dev
in your terminal is an easy way to get IP addresses for a hostname.
- Server isn't actually waiting for connections
- Your server build needs to be able to recognize when it is running in server mode, often this is achieved with a command line argument handler that allows you to pass an argument like
-mode server
to your server. - You should have your server log out when it starts in server mode, for our FishNet demo you should see the following in your process logs:
Local server is started for Tugboat.
- 2 things to double check (prior to deploying server):
- Your
NetworkManager
is set to "Tugboat" (as FishNet transport), Client Address set tolocalhost
, and Port is set to7777
- For Mirror,
NetworkManager
should be set to "KCP transport", Network Address set to127.0.0.1
, and Port is set to7777
- For Mirror,
- Your Build Settings has the correct scene at the top (for FishNet demo, should be
Assets/Hathora/Demos/1-FishNetDemo/HathoraDemoScene-FishNet.unity
)
- Your
- Your server build needs to be able to recognize when it is running in server mode, often this is achieved with a command line argument handler that allows you to pass an argument like
When a user connects, I see a temporary "Active Connection" in Hathora (for ~1 second), but then disconnects (client fails to connect)
This likely means that your server deployment isn't properly running in server mode. It could be that the connection transport is incorrectly configured. If you're testing our demos, it could be that your server is expecting FishNet connection, but you're trying to connect from a Mirror client.
See the above section for common solutions.
I tried copy+pasting a host name (not a pure IP address) into the NetworkManager's Address
property, but I'm instantly getting a timeout
-
Within the Hathora Console details page, ensure the logs parity with what you normally see in Unity to ensure !errors.
-
In the NetworkManager's
Tugboat
component (fromNetworkManager
GameObject), ensure theClient Address
andServer Port
match your room's server:port. -
Unity NGO and Mirror Networking require raw IP addresses (opposed to host names, like
proxy.hathora.dev
orlocalhost
). If you only have a host name, try converting to an IP address viadig <hostname>
in abash
orzsh
terminal. If you use Unity NGO or Mirror, you'll want to programmatically do this, eventually.
How do I get WebGL to work?
Check out our guide for setting up WebGL.
When I tried implementing this tutorial logic into my own game, both Player GameObjects move at the same time from 1 PC - how come?
For your player controller's Update()
, you may want to add if (!IsOwner) return
so only the owned network object can be controlled.
When using both the "Server" + "Client" buttons (Player1 'Host Mode'), both players spawn; Player1 can move their NetworkPlayer
and see the movement on Player2 when they pressed the Client
button (Player2). Why can I only move Player1 and not Player2?
Player2 needs **permission_ from the Server to move: If following another guide, you may be using the Network Transform
script. While this is server-authoritative and more-secure, the demo makes use of Client Network Transform
to give power to the Client for demo purposes and to keep code minimal.
Why does the other player look like his model isn't using animations; just "gliding" while moving?
Be sure to add a Network Transform
component to your Player! To save bandwidth, uncheck the syncing
options you don't need (such as Scale).
With Unity NGO: When I override OnNetworkSpawn() and check ownership of the Player (as a client), I'm the owner. The next time I call test ping, I'm not! What's going on?**
This seems to be a Unity NGO bug: The server appears to take ownership a few moments after the client spawns. You can async/await for !IsOwner. This is likely because clients can join before a server kicks in.