This will not follow a bug template. It is not necessarily a bug, the logic flow is native so this is merely my assumptions and discussion of a potential bugged system.
Hitching occurs when players buy weapons from the trader or players spawn in. This is often hidden by being in the trader menu at the time of hitching. For mods where players can use the trader mid-wave this is a real issue - especially for servers on HDDs as opposed to SSDs. Players can desync for seconds at a time.
I tried pre-loading all weapon content using the following:
Which I can only assume 'works' as it takes 3 seconds to complete on my HDD server. Unfortunately, the hitching persisted. So I logged occurrences of KFPlayerController.TriggerWeaponContentLoad and KFPlayerController.OnWeaponAsyncContentLoaded, where the former calls the latter, and the latter is apparently "called when content is done loading via TriggerAsyncContentLoad". Thus, any such logged event signifies weapon content being loaded. Note the expensive loops in OnWeaponAsyncLoaded:
Even if TriggerAsyncContentLoad being called multiple times for the same weapon (which it is) doesn't result in the actual content being loaded from the disk multiple times, these loops will run each time. I believe this should only ever need to happen once per weapon.
The logs show that these two functions are executed each time a weapon is given to the player. That is, when a player buys or picks up a weapon. This happens quite often. Multiple weapons are given when a player (re)spawns, hence the hitching at the start of trader time.
The hitching is for the most part barely noticeable if the game and server are both on SSDs. But many community-hosted servers are not on high-end machines. Perhaps the system is working as intended. I would like to point out that if this is intentional, it is highly inefficient. Unfortunately, almost all of the code for this async loading and events surrounding that is native so I have no idea how to circumvent the hitching issues.
Finally, I wonder why this content is loaded during the match in the first place. Isn't the long load time for KF2 attributed to loading content prior to the match, specifically to avoid these hitches?
Hitching occurs when players buy weapons from the trader or players spawn in. This is often hidden by being in the trader menu at the time of hitching. For mods where players can use the trader mid-wave this is a real issue - especially for servers on HDDs as opposed to SSDs. Players can desync for seconds at a time.
I tried pre-loading all weapon content using the following:
Spoiler!
Code:
static function PreloadWeaponContent(KFGameReplicationInfo KFGRI)
{
local KFGFxObject_TraderItems.STraderItem Item;
local class<KFWeapon> Weapon;
foreach KFGRI.TraderItems.SaleItems(Item)
{
Weapon = class<KFWeapon>(DynamicLoadObject(Item.WeaponDef.default.WeaponClassPath, class'Class'));
if(Weapon != None)
{
class'KFWeapon'.static.TriggerAsyncContentLoad(Weapon);
}
}
}
Spoiler!
Code:
simulated event OnWeaponAsyncContentLoaded(class<KFWeapon> WeaponClass)
{
// This event is called when content is done loading via TriggerAsyncContentLoad.
local KFPawn_Human KFPH;
local KFDroppedPickup KFDP;
// Attempt to set the weapon attachment for any player than might need theirs set. This is a backup
// for when content isn't quite ready when WeaponClassForAttachmentTemplate is replicated.
foreach WorldInfo.Allpawns(class'KFPawn_Human', KFPH)
{
if (WeaponClass == KFPH.WeaponClassForAttachmentTemplate)
{
KFPH.SetWeaponAttachmentFromWeaponClass(WeaponClass);
}
}
// The pickup's mesh is set on the client when it receives its InventoryClass via replication. If
// that happens before the content is done loading, we need to make sure to set the pickup's mesh
// after loading completes. This is probably a very unusual edge case.
foreach WorldInfo.AllActors(class'KFDroppedPickup', KFDP)
{
if (WeaponClass == KFDP.InventoryClass && KFDP.MyMeshComp == none)
{
KFDP.SetPickupMesh(WeaponClass.default.DroppedPickupMesh);
}
}
}
The logs show that these two functions are executed each time a weapon is given to the player. That is, when a player buys or picks up a weapon. This happens quite often. Multiple weapons are given when a player (re)spawns, hence the hitching at the start of trader time.
The hitching is for the most part barely noticeable if the game and server are both on SSDs. But many community-hosted servers are not on high-end machines. Perhaps the system is working as intended. I would like to point out that if this is intentional, it is highly inefficient. Unfortunately, almost all of the code for this async loading and events surrounding that is native so I have no idea how to circumvent the hitching issues.
Finally, I wonder why this content is loaded during the match in the first place. Isn't the long load time for KF2 attributed to loading content prior to the match, specifically to avoid these hitches?