The following are samples of code written by Shane Mitchell. For each example, there will be a paragraph explaining the context, and the problem that the code sample solves. Note that some variables and methods referenced in these samples are not defined here. Their purpose should be inferred by both their names, and by the context they are used in.
From profiling in Leviathan, our team found that Networked Rigidbody physics from agents and items were bottle-necking performance. Tackling this was a wide reaching endeavor, but the following was written to specifically optimize water interactions.
With Networked Rigidbodies removed on agents and items, we could no longer use OnTriggerEnter methods to trigger effects and change movement states for water interactions.
Considering the Space-Time Tradeoff, Shane created a Scriptable Object that could hold the height data of the water positions, so that water state checking could be achieved by comparing a position to the stored Scriptable Object data.
Using this code, physics methods were no longer necessary for checking water state on networked objects. The SO data is also relatively light, as each data point only takes 2 bytes to get sufficiently precise heights for the water. With a 2100x2000m scene like the one in Leviathan even with a resolution of 1m, this comes out to ~8MB.
Because bytes are used for the heights, the lowest standing position needs to be above 0m, and the highest water position needs to be less than 256m. This was not restrictive for Leviathan. Another limitation is that for places with slanted water, the surface position could be a little irregular. This was handled by averaging the 4 nearest heights for checks that required more precise water heights such as swimming.
Thank you for your interest in Shane's code samples. Please check back soon to see more. Thank you for your understanding! [10/4/2025]