World Services

Our answer to subsystems in Blueprints

A common problem we encountered when trying to develop in Unreal without the use of C++ was how to achieve a system similar to "world subsystems". i.e. having a single actor/object in the world that can store state/pass events around without it needing to be an actor explicitly added to a given level. Our solution to this was introducing the "world service" system - allowing you to create objects that exist for the lifetime of the current world, and can easily be obtained globally.

Example usage of a world service. BPFL_UIModeHelpers interacts with the BP_UIModeService world service, creating it at the point of calling the function if it has not been made already

Note: If you need state to be replicated, you will need to instead use Singletons

How to make a world service

Make a blueprint class extending from the M2_WorldService class

Additional events

If you want to have logic that triggers when the service is spun up or spun down, you can override the NotifyRegistered and NotifyUnregistered events.

How to access your world service

Call the GetWorldService function, providing your WorldServiceClass created in the above step.

You can choose to set CreateIfMissing to true or false. If you want to dynamically create the service at the point that it is needed, set it to true. If you want the service to be created automatically at the start of the project, see Where to set up your world service

Where to set up your world service

Create If Missing

If your world service has no "setup" step (i.e. it doesn't need to do any initialization logic on NotifyRegistered, the easiest approach is to use CreateIfMissing. That way, the world service will be created lazily at the first point that the service is needed (i.e. the first time someone tries to call it or listen to it).

An example usage like this would be the BP_UIModeService, which just acts as an intermediary between classes that want to request "UI mode", and a handler class that listens to these requests and actions them.

In the World Settings

If you want your world service to be set up as the world is set up, e.g. if it has initialization logic in NotifyRegistered that must be run regardless of when other classes need to use the service, you can add the world service to your World Settings.

The web services are examples of this flow - since they need to connect at the start of the game, they register on begin play.

If this is a custom world service, add it to the AdditionalWorldServices array.

If you are updating one of the web services, you can override it in its corresponding dropdown.

Last updated

Was this helpful?