Player Resources Component
Overview
The SimplePlayerResources component should be added to the PlayerState class of your project. This allows for it to be replicated in multiplayer, and keep it with your player data.
Starting Resources
During BeginPlay, all resources defined inside StartingResources will be added to the player's resources.
Methods
Get Resource Definition By Tag
Gets a single resource definition by its tag.
static USimpleResourceDefinition* GetResourceDefinition(
FGameplayTag Tag
);
FGameplayTag Tag = FGameplayTag::RequestGameplayTag(FName(TEXT("Resources.RawResource.Iron")));
USimpleResourceDefinition* Definition = USimpleResourcesSubsystem::GetResourceDefinition(Tag);
Set Resource Value
Sets the value of the specified resource.
bool Set(const FGameplayTag& Id, const int32 Value);
USimplePlayerResources::Get(Obj)->Set(FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre")), 10);
Set Resource Value (Pair)
Sets the value of the specified resource using a pair struct.
bool SetPair(
const FSimpleResourcePair& Pair
);
FSimpleResourcePair Pair;
Pair.ResourceType = FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre"));
Pair.Amount = 10;
USimplePlayerResources::Get(Obj)->SetPair(Pair);
Add Resource Amount
Adds the specified amount to the resource with the given ID.
bool Add(
const FGameplayTag& Id,
const int32 Value
);
USimplePlayerResources::Get(Obj)->Add(FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre")), 5);
Add Resource Amount (Pair)
Adds the specified amount to the resource using a pair struct.
bool AddPair(
const FSimpleResourcePair& Pair
);
FSimpleResourcePair Pair;
Pair.ResourceType = FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre"));
Pair.Amount = 5;
USimplePlayerResources::Get(Obj)->AddPair(Pair);
Subtract Resource Amount
Subtracts the specified amount from the resource with the given ID.
bool Sub(
const FGameplayTag& Id,
const int32 Value
);
USimplePlayerResources::Get(Obj)->Sub(FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre")), 3);
Subtract Resource Amount (Pair)
Subtracts the specified amount from the resource using a pair struct.
bool SubPair(
const FSimpleResourcePair& Pair
);
FSimpleResourcePair Pair;
Pair.ResourceType = FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre"));
Pair.Amount = 3;
USimplePlayerResources::Get(Obj)->SubPair(Pair);
Subtract Resource Amount (Checked)
Attempts to subtract the specified amount from the resource, returning the actual amount removed.
bool SubChecked(
const FGameplayTag& Id,
const int32 Value,
int& AmountRemoved
);
int AmountRemoved = 0;
bool bSuccess = USimplePlayerResources::Get(Obj)->SubChecked(
FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre")),
5,
AmountRemoved
);
Subtract Resource Amount (Checked, Pair)
Attempts to subtract the specified amount from the resource using a pair struct, returning the actual amount removed.
bool SubCheckedPair(
const FSimpleResourcePair& Pair,
int& AmountRemoved
);
FSimpleResourcePair Pair;
Pair.ResourceType = FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre"));
Pair.Amount = 5;
int AmountRemoved = 0;
bool bSuccess = USimplePlayerResources::Get(Obj)->SubCheckedPair(Pair, AmountRemoved);
Remove Resource
Removes the specified resource entirely from the container.
bool Remove(
const FGameplayTag& Id
);
USimplePlayerResources::Get(Obj)->Remove(FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre")));
Remove Resource (Pair)
Removes the specified resource entirely from the container using a pair struct.
bool RemovePair(
const FSimpleResourcePair& Pair
);
FSimpleResourcePair Pair;
Pair.ResourceType = FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre"));
USimplePlayerResources::Get(Obj)->RemovePair(Pair);
Check Resource Existence
Checks if the container has any amount of the specified resource.
bool Has(
const FGameplayTag& Id
) const;
if (USimplePlayerResources::Get(Obj)->Has(FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre")))
{
// Has some iron ore
}
Check Resource Amount
Checks if the container has at least the specified amount of a resource.
bool HasAmount(
const FGameplayTag& Id,
const int32 Value
) const;
if (USimplePlayerResources::Get(Obj)->HasAmount(FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre")), 10))
{
// Has at least 10 iron ore
}
Check Resource Amount (Pair)
Checks if the container has at least the amount specified in the pair.
bool HasPair(
const FSimpleResourcePair& Pair
);
FSimpleResourcePair Required;
Required.ResourceType = FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre"));
Required.Amount = 10;
if (USimplePlayerResources::Get(Obj)->HasPair(Required))
{
// Has at least 10 iron ore
}
Check Resource Existence (Branch)
Checks if the container has any amount of the specified resource, providing a True/False branch for Blueprints.
bool HasBranch(
const FGameplayTag& Id
) const;
USimplePlayerResources::Get(Obj)->HasBranch(FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre")));
Check Resource Amount (Branch)
Checks if the container has at least the specified amount of a resource, providing a True/False branch for Blueprints.
bool HasAmountBranch(
const FGameplayTag& Id,
const int32 Value
) const;
USimplePlayerResources::Get(Obj)->HasAmountBranch(FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre")), 10);
Check Resource Amount (Pair, Branch)
Checks if the container has at least the amount specified in the pair, providing a True/False branch for Blueprints.
bool HasPairBranch(
const FSimpleResourcePair& Pair
);
FSimpleResourcePair Pair;
Pair.ResourceType = FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre"));
Pair.Amount = 10;
USimplePlayerResources::Get(Obj)->HasPairBranch(Pair);
Check Resource with Comparison
Checks if the container has the provided amount of the resource, using the specified comparison type (e.g., ==, !=, >, >=, <, <=).
bool HasComparison(
const FGameplayTag& Id,
ESimpleResourceValueComparisonType Comparison,
const int32 Value
) const;
USimplePlayerResources::Get(Obj)->HasComparison(
FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre")),
ESimpleResourceValueComparisonType::Equal,
10
);
Get Resource Amount
Gets the current amount of the specified resource.
int GetValue(
const FGameplayTag& Id,
const int DefaultAmount = -1
) const;
int IronAmount = USimplePlayerResources::Get(Obj)->GetValue(
FGameplayTag::RequestGameplayTag("Resources.IronOre"),
0 // Default value if resource doesn't exist
);
Get Resource Data Reference
Gets a reference to the resource data for the specified resource ID.
FSimpleResourceData& Get(
const FGameplayTag& Id
);
FSimpleResourceData& IronData = USimplePlayerResources::Get(Obj)->Get(
FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre"))
);
Get Resource Data Pointer
Gets a pointer to the resource data for the specified resource ID.
FSimpleResourceData* GetPtr(
const FGameplayTag& Id
);
if (FSimpleResourceData* IronData = USimplePlayerResources::Get(Obj)->GetPtr(
FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre")))
{
// Resource exists
}
Get Resource Index
Gets the array index of the specified resource.
int32 GetIndex(
const FGameplayTag& Id
) const;
int32 Index = USimplePlayerResources::Get(Obj)->GetIndex(
FGameplayTag::RequestGameplayTag(TEXT("Resources.IronOre"))
);
Get All Resources
Gets a copy of all resource data in this container.
TArray<FSimpleResourceData> GetResources() const;
TArray<FSimpleResourceData> AllResources = USimplePlayerResources::Get(Obj)->GetResources();
for (const FSimpleResourceData& Resource : AllResources)
{
// Process each resource
}
Get Player Resources from Context
Gets the player resources component from a local player context.
static USimplePlayerResources* GetFromContext(
FLocalPlayerContext PlayerContext
);
if (USimplePlayerResources* Resources = USimplePlayerResources::GetFromContext(PlayerContext))
{
// Use the resources component
}
Get Player Resources Component
Gets the player resources component from various object types (Actors, PlayerControllers, Pawns, or UserWidgets).
static USimplePlayerResources* GetManager(UObject* Object);
if (USimplePlayerResources* Resources = USimplePlayerResources::GetManager(MyActor))
{
// Use the resources component
}
Events(Blueprints/C++)
Event listeners can be registered/deregistered in C++ or Blueprints with the following methods.
OnResourceAdded
void CallOrRegister_OnResourceAdded(const FGameplayTag& Id, FOnSimpleResourceAddedEvent Delegate, bool bForceCall = false)
void Deregister_OnResourceAdded(const FGameplayTag& Id, FOnSimpleResourceAddedEvent Delegate)
void DeregisterAll_OnResourceAdded(const FGameplayTag& Id, UObject* Object)
void Register_OnAnyResourceAdded(FOnSimpleResourceAddedEvent Delegate, bool bForceCall = false)
void Deregister_OnAnyResourceAdded(FOnSimpleResourceAddedEvent Delegate)
void DeregisterAll_OnAnyResourceAdded(UObject* Object)
OnResourceUpdated
void CallOrRegister_OnResourceUpdated(const FGameplayTag& Id, FOnSimpleResourceUpdatedEvent Delegate, bool bCallEvenIfAdded = false)
void Deregister_OnResourceUpdated(const FGameplayTag& Id, FOnSimpleResourceUpdatedEvent Delegate)
void DeregisterAll_OnResourceUpdated(const FGameplayTag& Id, UObject* Object)
void Register_OnAnyResourceUpdated(FOnSimpleResourceUpdatedEvent Delegate, bool bForceCall = false)
void Deregister_OnAnyResourceUpdated(FOnSimpleResourceUpdatedEvent Delegate)
void DeregisterAll_OnAnyResourceUpdated(UObject* Object)
OnResourceRemoved
void Register_OnResourceRemoved(const FGameplayTag& Id, FOnSimpleResourceRemovedEvent Delegate)
void Deregister_OnResourceRemoved(const FGameplayTag& Id, FOnSimpleResourceRemovedEvent Delegate)
void DeregisterAll_OnResourceRemoved(const FGameplayTag& Id, UObject* Object)
void Register_OnAnyResourceRemoved(FOnSimpleResourceRemovedEvent Delegate)
void Deregister_OnAnyResourceRemoved(FOnSimpleResourceRemovedEvent Delegate)
void DeregisterAll_OnAnyResourceRemoved(UObject* Object)
Last modified: 05 August 2025