Easy Things to Add to Your Game Ue4

The Modular Game Feature system is a new addition to Unreal Engine 4.27 and Unreal Engine 5 that allow developers to author standalone features for their projects.

These standalone features help compartmentalize Unreal projects, thus keeping the codebase clean and readable. And due to the nature of a modular game feature, these will help avoid accidental dependencies.

The essential aspects of this system are —

  • Easily inject new content into an existing project
  • The core game is entirely unaware of its existence
  • Dynamically loadable and unloadable without breaking the game

In this article, I will be going over what you need to know to get up and running with the Modular Game Feature system in Unreal Engine.

Video

Prefer a this content in video format?

Requirements

The requirements to utilize the Modular Game Feature system —

Engine Version: 4.27+

Plugins:

  • Game Features
  • Modular Gameplay

Important notes

Here are critical aspects to know when you're implementing a new Game Feature —

  • Do not reference Game Features via the base game
  • Game Features should be self-contained
  • Games Features can require other plugins as dependencies if needed
  • Game Features should be loadable and un-loadable without issue
  • If you are cross-referencing between Game Features, consider moving those to the base game
  • Game Features can contain code; the default plugin template is just a content-only one
  • Game Features have to be placed under /<ProjectName>/Plugins/GameFeatures/*
  • Game Features can be found in the Plugins Window -> Project
  • Game Features will activate for everyone within a multiplayer session
  • Game Features can be done via Blueprints and C++
  • Be wary of over-utilizing Game Features

C++ Notes

Important notes that are C++ specific

  • GameFeatures must be included in the Build.cs file for the project or plugin
            using UnrealBuildTool;  public class UDR_ModularGameplay : ModuleRules { 	public UDR_ModularGameplay(ReadOnlyTargetRules Target) : base(Target) 	{ 		PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; 	 		PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "GameFeatures" });  		PrivateDependencyModuleNames.AddRange(new string[] {  }); 		 	} }                      
  • #include "GameFeaturesSubsystem.h" is the required include

Creating a Game Feature plugin

1. Enable the Required Plugins

Before you can create a Game Feature, you must enable the following two required plugins —

  • Game Features
  • Modular Gameplay

Once these two plugins have been enabled, restart the editor.

2. Add entry to PrimaryAssetTypesToScan

Once the editor has been restarted, you will receive a message in your message log stating the following —

Asset Manager settings do not include an entry for assets of type GameFeatureData, which is required for game features plugins to function. [Add entry to PrimaryAssetTypesToScan]

Adding this entry is required for the engine to acknowledge the Primary Asset Type associated with the Game Modules.

To fix this issue, follow either the automated or manual method below.

Note: If this message doesn't appear in your Message Log, you can skip this step

Automated Method

Click the link appended to the end of the message — Add entry to PrimaryAssetTypesToScan — to automatically fix that issue.

Manual Method

Required for Unreal Engine 4.27

  1. Navigate to — Project Settings -> Asset Manager
  2. Create a new Primary Asset Types to Scan Array Element
  3. Fill in the following 2 values —
  4. Primary Asset Type: GameFeatureData
  5. Asset Base Class: GameFeatureData
  6. Create a new Directory
  7. Add /Game/Unused In the newly created directory
  8. Everything is all set!

3. Creating the Plugin

Unreal Engine 5 Early Access

Creating a game feature plugin is done the same way you make other plugins. To create a new Game Feature plugin, follow these steps —

  1. Open the Plugins window — Edit → Plugins
  2. In the bottom right of the window, press the New Plugin button
  3. This will open a New Plugin window
  4. In the New Plugin window —
  5. Select Game Feature (Content Only) from the template list
  6. Enter a plugin name
  7. Enter descriptor data
  8. Once all of the information has been added, press the Create Plugin button in the lower right of the window
  9. The new Game Feature has now been added to your project and a configuration window will appear.
  10. You're all set to start implementing your own Modular Game Features!

The newly created Game Feature can be found in your projects plugins directory — */ProjectDir/Plugins/GameFeatures/*

Unreal Engine 4.27

Unfortunately, the template doesn't exist in Unreal Engine 4.27. Therefore, it requires a bit of manual labor.

I created a template that you can utilize; here are the instructions for that --

  1. Download the template
  2. Unzip the template and place its contents in your projects Game Features directory
    Example: <ProjectDir>/Plugins/GameFeatures/
  3. Open the project
  4. Edit the template to suit your needs

Additional Notes

  • You can edit the plugin itself in the Plugin Window
  • You can edit the game module itself via the ExampleFeature Data Asset located in the root of the game feature
  • If you come across any issues with the Data Asset, you can create a new one by Right Click Content Browser -> Miscellaneous -> Data Asset -> Game Feature Data and rename it to the game feature name
  • Enable/disable the game feature via the console commands, or via C++ outlined in the article
  • Editing the States isn't available in the Data Asset

Opening the Game Feature configuration window

The Game Feature configuration window automatically opens after it has been created. To find and open the configuration window manually —

  1. Open the content browser
  2. Key-bind: Ctrl + A
  3. Window → Content Browser → Content Browser (1, 2, 3, or 4)
  4. Enable Open the Source Panels
  5. Content Browser → Settings → Show Sources Panel
  6. Enable Show Plugin Content
  7. Content Browser → Settings → Show Plugin Content
  8. Navigate to the newly created Game Feature directory in your Content Browsers Source Panel
  9. Open the Game Feature Data Asset that has the same name as the new Game Feature
  10. The configuration window for the newly created Game Feature is now open!

Configuring the Game Feature

With the Game Feature configuration window opened, you will find three primary categories — Feature State, Actions, and Game Feature. Each of these plays a vital role in setting up and defining the game feature itself.

Feature State

The Feature State category controls the initial and current state of the Game Feature. The state of a Game Feature is divided into four options — Installed, Registered, Loaded, and Active.

Actions

The Actions category defines what actions occur when the Game Feature is enabled or disabled.

Here are the actions that are currently available as of Unreal Engine 5 Early Access 2 —

Add Cheats

The Add Cheats action allows developers to easily add their own debug commands via registering a Cheat Manager Extension with the game.

Cheats are purely for debugging and will not be included in shipping builds.

Add Components

The Add Components action will add a component to the designated actor class if it has been registered to receive components via the Game Framework Component Manager.

There are four options within the action —

Adding an actor as a Receiver

By default, actors have to be added as receivers to receive Game Feature Components. This step is generally done via BeginPlay.

Depending on the component and needs, consider utilizing C++ to add the receiver during an earlier phase.

Blueprint

Cpp

            if (UGameFrameworkComponentManager* ComponentManager = GetGameInstance()->GetSubsystem<UGameFrameworkComponentManager>()) {     ComponentManager->AddReceiver(this); }                      

Removing an actor as a Receiver

It is ideal to clean up and remove the actor from being a Game Feature Component receiver during the Destroyed or EndPlay events.

Note: When an actor is removed as being a receiver, it will automatically remove the Game Feature Components added. There is no need to do that manually.

Blueprint

CPP

            if (UGameFrameworkComponentManager* ComponentManager = GetGameInstance()->GetSubsystem<UGameFrameworkComponentManager>()){    ComponentManager->RemoveReceiver(this);}                      

Add Data Registry

The Add Data Registry Action will add a Data Registry to your project.

Add Data Registry source

The Add Data Registry Source will add a data source that will stream into a Data Registry.

  • Each configures the path to each data source must be configured

Custom Actions

An example of what other actions can be added manually via C++. Some, if not all, will be available when Unreal Engine 5 fully releases.

You can find these in the Valley of the Ancients demo.

  • Add Abilities
  • Add Attributes Defaults
  • Add Input Mapping
  • Add Level Instances
  • Add Spawned Actors
  • Add World Systems

Asset Manager

The Asset Manager category is utilized to tell the engine that new assets are available. For example, introducing new weapons or items to your game.

Setting a Game Feature state during runtime

Game Features can be dynamically enabled and disabled during a runtime session.

Blueprint

As of Unreal Engine 5 Early Access 2, there are no native blueprint nodes that allow you to toggle on or off Game Features. Thankfully, Epic has exposed that functionality through console commands. Simply utilize the following two commands with the Execute Console Command blueprint node.

Deactivate a game feature

DeactivateGameFeaturePlugin

Load & activate the game feature

Unload the game feature

Cpp

            // Get the Plugin URL based on the Game Features Name FString PluginURL; UGameFeaturesSubsystem::Get().GetPluginURLForBuiltInPluginByName(<GameFeatureName>, PluginURL);  // Deactivate the Game Feature UGameFeaturesSubsystem::Get().DeactivateGameFeaturePlugin(PluginURL);  // Activate the Game Feature UGameFeaturesSubsystem::Get().LoadAndActivateGameFeaturePlugin(PluginURL, FGameFeaturePluginLoadComplete());  // Unload the Game Feature UGameFeaturesSubsystem::Get().UnloadGameFeaturePlugin(PluginURL);  // Load the Game Feature UGameFeaturesSubsystem::Get().LoadGameFeaturePlugin(PluginURL, FGameFeaturePluginLoadComplete());                      

Example

For this example, I have a Coin Collection Game Feature. When the green button is stepped on, the feature is toggled on. When the red button is stepped on, the feature is cleaned up and toggled off.

The Coin Collection Feature spawns collectible coins randomly and attaches a coin counter to the player's viewport.

Frequently Asked Questions

A list of frequently asked questions regarding this feature, and their answers.

When should I use this feature?

Module Game Features should be utilized when you need to update or create new features over the life of your project without the project specifically depending on them.

What are some usage examples?

With Game Features not being referenced by core gameplay, they can be utilized to control aspects of gameplay, memory management, and more on the fly.

For example, the Fortnite dev team utilizes Game Features for their vehicles. This allows them to enable or disable them for the different game modes easily.

Here are some other example use cases —

  • Weapon Unlocks
  • Ability Unlocks
  • Level Instances
  • Items
  • NPCs
  • FX
  • Dialog
  • Weather Effects
  • Cutscenes

Just remember that Game Features should be self-contained, and disabling them should not affect the core game.

My game feature isn't activating; why is that?

Make sure that you set your Game Feature state to Active when you want to enable it. Likewise, make sure to put it to Loaded or Registered to disable it.

If it still doesn't activate, check your logs. There is likely a warning or error that will help you pinpoint the issue.

Why is it recommended not to have the core game depend on a Game Feature?

When you take away something the engine is expecting to be there, it can cause a whole host of issues, such as —

  • Game Crashes
  • Errors
  • Warnings
  • General bugs

smiththerecomed1949.blogspot.com

Source: https://www.unrealdirective.com/articles/modular-game-features-what-you-need-to-know

0 Response to "Easy Things to Add to Your Game Ue4"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel