https://metaplay.io logo
Creating some Entities on server startups
# questions-and-feedback
d
Hi, I am creating a Leaderboard feature and i'd like to eagerly create a Leaderboard Entity. Is there a server startup hook I can plug into? Thanks Andre
a
The usual approach for simple entity initialization is to rely on the framework for creating and initializing the entity upon being sent a message or entity ask. If your leaderboard entity doesn't require any "global" setup you could potentially just have it initialized on first use. This has the nice property of side-stepping race conditions on entity creation. You will likely need some system for managing the entity IDs of your leaderboards, however. Player entities are created simply by generating random entity IDs and checking if they are already in use. For something like a leaderboard, you may wish to employ a "manager" actor of sorts, which then would also give you the startup hook for pre-creating entities. A manager entity would simply be a
EntityActor
that declares
EntityConfig.ShardingStrategy
to be
ShardingStrategies.CreateSingletonService()
. The entity will be started automatically on cluster start and there will be only a single instance of it cluster-wide. Leaderboard entity pre-creation could then happen in the
Initialize()
method of the manager actor. There's documentation on the basics of entity actors here: https://docs.metaplay.io/game-server-programming/introduction-to-entities-and-actors.html.
d
I am using the "auto" setup but i wanted to be able to pass it some config like sort order and max size via an initializer. The Singleton Actor sounds like what i need. Thanks