Receiving data from state not working when sent from headless server

Hello all, I'm new-ish to Bolt but I seem to have it figured out pretty well.

I've come across a really strange issue that appears to only be happening while running the server in Unity headless mode.

The situation is this:

The server spawns the player prefab, which has an PlayerState attached. Bolt instantiates the player prefab on both the client and the server. There is a "Gun" component, which derives from "Weapon", attached to the player prefab somewhere down the hierarchy. Weapon has an "Initialize" method, which on the server, calculates the total and current ammo for the weapon (i.e. the weapon has a property for how much ammo in a clip and another for how much ammo it has in total).

The PlayerState has an array of WeaponObjects, and of course there is a WeaponObject Bolt object to fill the array on the PlayerState. WeaponObject has TotalAmmo and Ammo as properties, as well as a Reload trigger and an Update trigger. The Update trigger is used by the server to tell the PlayerState that a weapon's ammo count has been updated. This is because there could be a mismatch between the client's ammo and the server ammo, and the client needs to display the correct amount on the HUD.

So when the Weapon's Initialize method is called, Gun overrides it, and if the server is running the code, it will set the properties on the state that's passed in.

Something like weaponObject[weaponId].Ammo = AmmoPerClip * 4;
The server (only) then calls weaponObject.Update(); - Which is the trigger.

The result is, the client gets the correct ammo count and is able to shoot. This all works perfectly fine when either the Unity Editor is the server, or the built .exe is the server and not in headless mode.

However, when the built .exe runs in headless mode, this does not work. It appears the state is not being updated correctly, and when the client spawns in, the ammo count is either zero, or sometimes it does set the ammo but disconnects due to a "BOLT ASSERT FAILED - Exception while unpacking data from [ip]" which gives little information.

So, I'm really lost and confused as far as what could be causing this. If a dev or anyone who's experienced this has any idea, I would greatly appreciate the information.

Thanks.

Comments

  • Did some more digging in my menu code, which checks if Unity is headless and starts the server... I removed the BoltConfig I was passing into the BoltNetwork.StartServer call and now it looks like it works? Is there a certain property in the blank config that could be causing this problem?
  • Looks like I've found the issue. I had set the Network Rate in the Bolt Settings in Unity to 2 (30 packets per second), while the default was 3 (20 packets per second), and I'd assume that the default value when instantiating a new BoltConfig is 3. So there was a mismatch in serverSendRate between the built client and the headless server client (since the headless server start code was the only code to use a new BoltConfig).

    Frustrating because the error I was getting from Bolt didn't point in that direction at all. I will leave this up in case anyone else has this problem.