(ASC) - Setup on Player State

this choice ideal for multiplayer games where players can switch characters or where abilities need to persist between different avatars.

Creating your PlayerState class based on RoguePlayerState.

First, let's create our PlayerState class that derives from ARoguePlayerState, we'll use this class to place the AbilitySystemComponent and replicate it in its constructor.

  1. To create this class, navigate to the top left corner of the engine and look for Tools, then click on New C++ Class...

If you already have a class created, you can do this from the content browser as well.
  1. With the class creation window open, select All Classes and then search for ARoguePlayerState and click next.

  1. In this image, we are creating a new class called MyProjectNamePlayerState, which will be derived from ARoguePlayerState in your Unreal Engine 5 project. Here are some important points:

  • Make sure that the class is created as Public, as shown in the image. This ensures that the code is accessible from anywhere in the project.

  1. All you need to do now is call the default constructor of the ARoguePlayerState class to create your AbilitySystemComponent derived from URogueAbilitySystemComponent.

  1. Now, let's build your custom AbilitySystemComponent within the PlayerState.

AYourPlayerState.h
#include "CoreMinimal.h"
#include "Framework/RoguePlayerState.h"
#include "YourPlayerState.generated.h"

UCLASS()
class YOURPROJECT_API AYourPlayerState : public ARoguePlayerState
{
	GENERATED_BODY()

public:
	AYourPlayerState(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
};
  1. In your character class, you’ll need to override the InitAbilityActorInfo function to specify to your AbilitySystemComponent who the OwnerActor and AvatarActor are. Let’s do that now.

AYourCharacter.h
#include "CoreMinimal.h"
#include "Framework/RogueCharacter.h"
#include "YourCharacter.generated.h"

UCLASS()
class AYourCharacter : public ARogueCharacter
{
	GENERATED_BODY()
	
public:
	AYourCharacter(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

	// Override this function!
	virtual void InitAbilityActorInfo() override;
}

Note: If you don't have a character class derived from ARogueCharacter, create one so that this step can be completed correctly. Creating it is very simple; just repeat the process you followed to create the PlayerState.

  1. Now all you have to do is create your customized PlayerState with the AbilitySystemComponent and place it in your GameMode.

Bonus Hint: (Debug Console).

To debug and check if everything is working correctly, we will use the console panel to enter the command showdebug abilitysystem. This command allows us to visualize the AbilitySystemComponent on our character. Take a look

Atualizado