I start with this quote:
Originally Posted by poosh
and few shots of how it realized in SCRNBalance:
In PlayerController:
simulated function ClientWeaponSpawned(class<Weapon> WClass, Inventory Inv)
call PreloadAssets for spawned weapon - it run DynamicLoadObject and load meshref to Mesh. by default Mesh==none
simulated function ClientWeaponDestroyed(class<Weapon> WClass)
unloads Mesh by setting it to none;
I want to talk about memory.
community make big amount of weapons and mods. each weapon eats memory. On most modded servers game start to crash on some clients because of not enough virtual memory. + 32bit memory limit.
1. As I understand, the Idea of replacement Mesh to MeshRef based on the problem: in weapon, even if weapon is not spawned in game, all meshes, sounds, textures are loaded in memory, cause they are statically written like Mesh=Mesh'MyMesh'. So even if this weapon will never be spawned, it will eat memory on server and on clients like if it is was spawned.
1. is it rigth?
next.
Garbage collector cant unload them from memory, because it can unload only not referenced(unreferenced) items. But Weapon.default.Mesh and default.Sounds and other defaults always reference to it so it cant be unloaded
2. is it right?
next.
if it right, then why TWI remove weapon pickups on ground and say that it will help to save memory? pickup.defaults, and weapon.defaults continue to reference on resourses and eat memory.
3. Why they think it will help? or I missed somethink?
The idea to avoid this is make default.Mesh default.Sounds default.Textures to none, and Load them only when weapon actually spawned. Apply them to Instance, not default class.
Does it right:
1. we set default.mesh = none - it dont eat memory
2. weapon spawned, on spawned weapon we set Mesh=WeaponMesh (we set mesh on exact instance of weapon, not on default.mesh of it class) - it start to eat memory
3. when weapon destroyed, Garbage collector will look that loaded in memorty Mesh not referenced by any objects (default.mesh we set to none before, and weapon instance is destroyed) - so Garbage collector unload it automatically
will it work?
What you think about this mutator idea?
- with config we specify dynamic array of "need-to-optimize-weapons"
- mutator look at each "need-to-optimize-weapon", and fill the struct for it:
var string WeaponClass
var string MeshRef
var string Skins
var string Sounds
var string anothersounds...
var string Pickup resources....
var string FireModes resources...
- so we have dynamic array with string representation of all weapon resouses, so we dont need to have it in defaults
- replicate this array to clients (yes, it is very big, but we replicate it initially once in game)
- on client and on server go through all this weapons list, and remove default meshes sounds skins of all this weapons - all this resourses will be unloaded from memory with garbage collector on client and server
here we have trouble when Weapon spawned, it will have no mesh and no skin and no sounds cause defaults are nulled
so:
- for weapons we can modify player controller and as poosh do use ClientWeaponSpawned ClientWeaponDestroyed
or another way not only for weapons:
- on server in CheckReplacement we hook when Weapon or WeaponPickup or other "need-to-optimize" object spawned, and on server fill VERY LIGHTWEIGHT array "InGameObjects" it will be replicated to clients.
- when client will receive new InGameObject from server, it will go througth our big array with string representation of all weapon resources. And will find this spawned ObjectClass in resources-refs-array. And will initialize this weapon/object by like this
Weapon.LinkMesh ( DynamicLoadObject ourarray.MeshRef ). And so on with skins sounds and other resources. the main thing here is that we apply it on instance, not default.class.
so. our weapon defaults are nulled. and if WeaponInstance destroyed - no references to that resources left, so it will be unloaded from memory with garbage collector.
to make it work need hooking and replicate to clients each spawned weapon or pickup object. because CheckReplacement not work on client side (as i know).
bad things:
- some lag because of replication delay. Weapon spawned but mesh and texture will be assigned only when client receive this InGameObject from server and initialize it.
well what you think can in work?
If this scheme can work...
Because of this lag I think this scheme can be used not for all weapons, but for weapons that not often used and eats memory....
AND it can be used everywhere for Sound resources, cause Sound lag is not so bad, it very rare when weapon spawned and start to fire simultaneoucly. Maybe few shots before InGameObject replicated, and SoundsRefs loaded.
----
UPD.
I found that
- Garbage collection starts only when mapchange.
- it can be started with console PlayerController.ConsoleCommand("OBJ GARBAGE")
- it freezes game for a short moment
http://wiki.beyondunreal.com/Legacy:Garbage_Collection
http://wiki.beyondunreal.com/Legacy:Destroying_Objects
http://wiki.beyondunreal.com/Legacy:Console_Commands/Stats_Console_Commands
-----
crosspost to epicgames the link
Originally Posted by poosh
All resources custom weapons use must be statically loaded into memory.
I rewrote Preload/Unload assets calls in ScrnBalance, so it now supports Refs instead of static links (e.g. MeshRef instead of Mesh etc.). But then every weapon's code must be rewritten too to use this. But if you do so, your weapon won't work without ScrnBalance anymore (its resources won't be loaded, if ScrnBalance isn't used).
Maybe I'll contact with Marco to make ServerPerks support refs of custom weapons by default.
and few shots of how it realized in SCRNBalance:
In PlayerController:
simulated function ClientWeaponSpawned(class<Weapon> WClass, Inventory Inv)
call PreloadAssets for spawned weapon - it run DynamicLoadObject and load meshref to Mesh. by default Mesh==none
simulated function ClientWeaponDestroyed(class<Weapon> WClass)
unloads Mesh by setting it to none;
I want to talk about memory.
community make big amount of weapons and mods. each weapon eats memory. On most modded servers game start to crash on some clients because of not enough virtual memory. + 32bit memory limit.
1. As I understand, the Idea of replacement Mesh to MeshRef based on the problem: in weapon, even if weapon is not spawned in game, all meshes, sounds, textures are loaded in memory, cause they are statically written like Mesh=Mesh'MyMesh'. So even if this weapon will never be spawned, it will eat memory on server and on clients like if it is was spawned.
1. is it rigth?
next.
Garbage collector cant unload them from memory, because it can unload only not referenced(unreferenced) items. But Weapon.default.Mesh and default.Sounds and other defaults always reference to it so it cant be unloaded
2. is it right?
next.
if it right, then why TWI remove weapon pickups on ground and say that it will help to save memory? pickup.defaults, and weapon.defaults continue to reference on resourses and eat memory.
3. Why they think it will help? or I missed somethink?
The idea to avoid this is make default.Mesh default.Sounds default.Textures to none, and Load them only when weapon actually spawned. Apply them to Instance, not default class.
Does it right:
1. we set default.mesh = none - it dont eat memory
2. weapon spawned, on spawned weapon we set Mesh=WeaponMesh (we set mesh on exact instance of weapon, not on default.mesh of it class) - it start to eat memory
3. when weapon destroyed, Garbage collector will look that loaded in memorty Mesh not referenced by any objects (default.mesh we set to none before, and weapon instance is destroyed) - so Garbage collector unload it automatically
will it work?
What you think about this mutator idea?
Spoiler!
- with config we specify dynamic array of "need-to-optimize-weapons"
- mutator look at each "need-to-optimize-weapon", and fill the struct for it:
var string WeaponClass
var string MeshRef
var string Skins
var string Sounds
var string anothersounds...
var string Pickup resources....
var string FireModes resources...
- so we have dynamic array with string representation of all weapon resouses, so we dont need to have it in defaults
- replicate this array to clients (yes, it is very big, but we replicate it initially once in game)
- on client and on server go through all this weapons list, and remove default meshes sounds skins of all this weapons - all this resourses will be unloaded from memory with garbage collector on client and server
here we have trouble when Weapon spawned, it will have no mesh and no skin and no sounds cause defaults are nulled
so:
- for weapons we can modify player controller and as poosh do use ClientWeaponSpawned ClientWeaponDestroyed
or another way not only for weapons:
- on server in CheckReplacement we hook when Weapon or WeaponPickup or other "need-to-optimize" object spawned, and on server fill VERY LIGHTWEIGHT array "InGameObjects" it will be replicated to clients.
- when client will receive new InGameObject from server, it will go througth our big array with string representation of all weapon resources. And will find this spawned ObjectClass in resources-refs-array. And will initialize this weapon/object by like this
Weapon.LinkMesh ( DynamicLoadObject ourarray.MeshRef ). And so on with skins sounds and other resources. the main thing here is that we apply it on instance, not default.class.
so. our weapon defaults are nulled. and if WeaponInstance destroyed - no references to that resources left, so it will be unloaded from memory with garbage collector.
to make it work need hooking and replicate to clients each spawned weapon or pickup object. because CheckReplacement not work on client side (as i know).
bad things:
- some lag because of replication delay. Weapon spawned but mesh and texture will be assigned only when client receive this InGameObject from server and initialize it.
well what you think can in work?
If this scheme can work...
Because of this lag I think this scheme can be used not for all weapons, but for weapons that not often used and eats memory....
AND it can be used everywhere for Sound resources, cause Sound lag is not so bad, it very rare when weapon spawned and start to fire simultaneoucly. Maybe few shots before InGameObject replicated, and SoundsRefs loaded.
----
UPD.
I found that
- Garbage collection starts only when mapchange.
- it can be started with console PlayerController.ConsoleCommand("OBJ GARBAGE")
- it freezes game for a short moment
http://wiki.beyondunreal.com/Legacy:Garbage_Collection
http://wiki.beyondunreal.com/Legacy:Destroying_Objects
http://wiki.beyondunreal.com/Legacy:Console_Commands/Stats_Console_Commands
-----
crosspost to epicgames the link
Last edited: