In the editor, every so often the NetCodeConfig scriptable object fails to load. I’ve noticed it seems to occur more often after a fresh boot of Unity, but sometimes it occurs at other times too. Stopping and Playing again usually fixes it. When it fails to load, the singleton ClientServerTickRate is not present in neither the server nor the client world.
I’m not sure of the best place to store it, but I keep the scriptable in Resources.
I just added logging, and the very first time after a fresh boot of Unity, NetcodeConfig.Global is null. On a second play, all is good. The scriptable is still in the preload list in the player settings, and is linked in the netcode tab. We have no special AssetDatabase shenanigans going on afaik. Nothing in the console.
It is probably because the first time you boot fresh (arguing eh) it is a classic egg/chicken problem. Something is not initialised in the right order and the config is not loading as expected.
Actually I tried to use NetcodeConfig.Global at authoring baker but it’s null when baking. Is that currently the known limitation? I would like official to support it since I dun want to put drag & drop this same NetcodeConfig to insane amount of authoring monobehavior.
I’ll take a look at the bug on Monday, but optimise I’m interested in why you’re adding the NetcodeConfig to any authoring components (nevermind multiple authorings).
I’ve reproed this with 2022.3.13f1 (haven’t tried your editor version yet), thanks for the report! And apologies! It seems like Preloaded assets are not preloaded in the Editor (lol), which means Resources.FindObjectsOfTypeAll will fail. It’s an assumption I made after seeing it work. I’ll check out how other assets (like Graphics / Scriptable Rendering Pipeline) get around this.
Reproed by clearing local Library & Temp directories, fresh open of Unity, with the ProjectSettings window closed. Code:
This was recently fixed, but didn’t land in time for 1.2. Aiming for 1.3 instead. Thanks again for the report!
I’m not sure what you’re trying to do, optimize. What do you mean by “expect to use NetCodeConfig.Global at authoring time”? NetCodeConfig.Global is a runtime API.
I would like to use it at authoring time too but from wat u say it’s designed for runtime only. Then I will need to go for regular authoring way instead of just call NetCodeConfig.Global API to get the required NetCodeConfig data to bake data.
Yeah, I understood what you mean optimise. Indeed there should be a clear distinguish in between the authoring (the scriptable) and the actually config data (entity only) and the application of that data too (that is a third step).
@NikiWalker seeing as the fix wasn’t in pre.12, and I presume the next release won’t be for another month or two, is the fix straightforward to implement? It’s a regular irritance here, but I don’t want to restructure the net config initialization only to revert it again when the fix lands.
@Richay The fix is a little involved (as we moved the NetCodeConfig out of PreloadedAssets, except in builds), but in the editor, a short term quick solution is adding this code into an Editor script (like NetCodeConfigEditor):
I experienced this same issue with Unity 6, using Netcode for entities 1.2.3 ( released on June 05, 2024 ).
The fix described in this thread worked wonders for me.
For posterity: Fixed in Changelog | Netcode for Entities | 1.3.0-pre.4 . * Issue where NetCodeConfig.Global did not load correctly on first boot, if not selected in the Project assets window. If you have a global NetCodeConfig set in your PreloadedAssets Project Setting, we'll also auto-upgrade your project, moving the save to Project Settings (via NetCodeClientAndServerSettings).