How it works...

In the CollectibleObject class's constructor, we make sure that our object is going to be replicated. After that, we create a sphere collider that we tell (via a listener) to call the OnBeginOverlap function when it collides with another object. To do that, we use the OnComponentBeginOverlap function.

For more information on the OnComponentBeginOverlap function and the function that needs to be given to it, refer to https://docs.unrealengine.com/latest/INT/API/ Runtime/Engine/Components/UPrimitiveComponent/ OnComponentBeginOverlap/index.html.

After this, inside our OnBeginOverlap function, we first check if we are currently on the server. We don't want things to get called multiple times, and we want the server to be the one that tells the other clients that we've increased our score.

We also call the UpdateScore function. This function has had the following function specifiers added to it:

For more information on the other function specifiers, such as Unreliable, check out https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/Reference/Functions#functionspecifiers.

Calling UpdateScore will, in turn, call the UpdateScore_Implementation function that we created and it will display a message, saying that we've collected the object by printing out some text like we used earlier.

Finally, the UpdateScore_Validate function is required and just tells the game that we should always run the implementation for the UpdateScore function.

For some recommendations on performance and bandwidth settings that may be useful for working with levels with a lot of replication, check out the following link: https://docs.unrealengine.com/en-US/Gameplay/Networking/Actors/ReplicationPerformance.