As a personal project, I wanted to try implementing a networked inventory in Unreal Engine 4, and compare how the built-in variable replication compares with an RPC approach (with respect to network activity) when the inventory gets large.
So, I created two ActorComponent
-derived classes in C++: ReplicationInventoryComponent
and RPCBasedInventoryComponent
. To make them as interchangeable and easy to use as possible, both of them implement a Blueprint-callable interface: IInventoryInterface
.
ReplicationInventoryComponent
internally uses an array of structs, with a map of item names to array positions for fast access (which gets rebuilt using RepNotify so it’s always up to date). RPCBasedInventoryComponent
uses a private Inventory
class, which just uses a map of item names to quantities.
See the related blog post for full details on the performance comparison, but surprisingly, in this case, replication used far less memory bandwidth than RPCs, even for inventories with thousands of components.