Why do I have to include a subsytem in a Plugin?

Hi!

I’m reading the documentation about the subsystem and I don’t understand this:

Subsystems are particularly useful when creating plugins. You do not need to have instructions about the code needed to make the plugin work. The user can just add the plugin to the game, and you know exactly when the plugin will be instanced and initialised. As a result, you can focus on how to use the API and the functionality provided in UE4.

What do they mean with “you know exactly when the plugin will be instanced and initialised”?

And with “you can focus on how to use the API and the functionality provided in UE4”?

I don’t know if the documentation is suggestion to include a subsystem on every plugin I develop. If it is so, I don’t understand why.

Thanks!

No, it is not suggesting you add a subsystem to every plugin.

What it’s trying to get at is that the automated nature of subsystems allow you to write things in a plugin that are useful to the project without the project being required to do additional work.

If you create a world subsystem, then when the level starts it just exists and is usable. This is in contrast to making an Actor subtype in your plugin which the project now has to decide when and how to manually spawn.

In addition, a subsystem like UGameInstanceSubsystem allows you to extend functionality with the lifetime of the game instance without declaring a child of UGameInstance and expecting the project to derive from it. It becomes really messy if you are trying to use multiple thirdparty plugins which all want a specific base class from the game instance because you can’t satisfy them all. But multiple plugins can all contribute separate subsystems.

What’s confusing me here is the term ‘plugin’. When I read it, I thought a plugin referred to modular extensions that add new features, tools or asset integrations: Plugins in Unreal Engine | Unreal Engine 5.8 Documentation | Epic Developer Community .

re they talking about these kinds of extensions?

I’m not a native English speaker and I’m finding it harder to understand.

Yes, but subsystems aren’t just for plugins, although they were created to avoid a problem when you downloaded many things from the Marketplace that required overwriting the same class. Going back to the “GameInstance” example that MagForceSeven mentioned, let’s say a plugin you downloaded had a save system, another might have its own inventory system, and yet another might use it for seamless travel. A GameInstance is a singleton; in other words, only one can exist. So you had to choose one of the three functionalities or manually copy all the code to a single GameInstance. The subsystem—in this case, the GameInstance subsystem—works like a module or plugin of the GameInstance class, so now you can have different, separate functionalities without having to overwrite the original GameInstance.

Yes, they are talking about those kind of extensions (Plugin). Subsystems allow you to build systems within a plugin that follow the same scope and lifetime of it’s parent system, if you need to.

Yes. Subsystems are a type of class that you can write in code just like Actors. Code is organized into modules. Modules are grouped into plugins. Plugins are the collections of code that you use to share features between projects or with other people through GitHub or FAB (the Unreal Marketplace).