SteamVR

SteamVR

SteamVR Workshop
Customize your SteamVR experience by finding new backgrounds, 3D environments, controllers and base station models.
Learn More
Correct Way to Handle Deleting Huge Numbers Of Entities
I'm creating sets of entities (characters) that independently move/function but are also repeated x10 into a superset. Then that superset of 10 characters is repeated 10 times. This creates over 1000 individual Source 2 entities. To reduce the total entities, I gradually replace the original supersets of 10 characters with a single set of entities that appear the same as a group of 10 characters moving together in synchronization but are actually only one character and are 1/10th the number of entities of what they replace. So on completing the creation of what looks like 100 moving/functioning characters, there are in fact only 10 characters, each consisting of about the same number of entities as an original single character at the start.

The above setup works well as long as the player remains active in the map at least until all the replaced character entities have been killed. If the player's headset goes to sleep before the above replacement/kill cycle has completed and the player returns after it is complete then there is a frame time that is more than 2x longer than if the player never left. That's about a video killing 16ms average frame time verses 6ms.

So I'm using templates to create all this and I tried using the kill hierarchy commands but they would never remove any entities created by the templates. So I resorted to just making Logic Relays that destroy the entities in a hierarchy of least parenting first. That appears to work fine.

So while this issue does not stop the map from working it does prevent the player from leaving the map and expecting to return until this entity replacement completes. So am I causing this issue by not using the template kill hierarchy ?
< >
Showing 1-1 of 1 comments
Rectus 13 18 Jul, 2022 @ 3:47am 
It's hard to know for sure, since there isn't any information available on how the Source 2 engine handles entities.

The engine seems to use resource pooling for entities, which should help a lot when spawning an killing many entitites. I'm guessing the issue comes from when you spawn a lot of entities simutaneously, and then kill them. Spawning the entities would cause the engine to allocate a lot of memory to the entity pool, but killing them won't immediately release the memory. The engine probably does gradual reclamation of the unused resources to not produce hitches, and guessing it fails if it goes idle and does everything at once when it comes back.

Not sure if there is nay reliable way of preventing it. Generally trying to keep the number of entities in the world relatively constant might help.

If you are using a lot of utility entities, it might also help to use VScript instead. A lot of things like logic entities, sound and effects and be replaced with script functions.
< >
Showing 1-1 of 1 comments
Per page: 1530 50