Skip to main content

Initialization & Teardown

Best practices

This guide describes the mod.io Unreal Engine plugin's basic event loop, intialization, and shutdown functions. Ideally, you should wrap these functions in a separate subsystem (e.g. ModioManagerSubsystem) which is responsible for managing the full initialization and authentication flow for your game.

For more information, see our User Authentication quick-start guide.

Calling RunPendingHandlers

Before initializing the plugin, ensure RunPendingHandlers is being continually called. You can do this yourself in your project’s main loop, or by setting Use Background Thread to true in the mod.io project settings. For best performance, RunPendingHandlers should be called at least once per frame. See Maintaining the plugin event loop for additional information.

Initialization

The mod.io Unreal Engine plugin is initialized by calling InitializeAsync, passing in a ModioInitializeOptions with the relevant information for the current session, and a callback containing a ModioErrorCode that will contain the result of the initialization on completion.

Use GetProjectInitializeOptionsForSessionId to initialize the plugin using the information entered in the mod.io project settings. On Windows, GetDefaultSessionIdWindows can be used as the Session ID. Some platforms also require additional parameters added to ModioInitializeOptions.ExtendedInitializationParameters. Refer to the relevant platform documentation for more information.

run_pending_handlers

initasync_getoptions

note
  • The error-handling in this sample has been omitted. See our Error Handling quick-start guide for more information.
  • InitializeAsync is a asynchronous function, therefore you must wait for the callback for confirmation that the initialization is complete.

Shutdown

The mod.io Unreal Engine plugin is shut down by calling ShutdownAsync in a similar fashion.

shutdownasync_runhandlers

note
  • You must continue to call RunPendingHandlers while shutdown is in progress to allow intermediate handlers to complete.
  • Any in-flight mod.io async calls will complete with an error code indicating cancellation.
  • You must not call ShutdownAsync from within another completion handler/callback. This may cause the application to deadlock.