Skip to content

Collectable Item

Introduction

An item that can be collected by an actor

Dependencies

The CollectableItem relies on other components of this plugin to work:

  • Logger: Used to log useful information to help you debug any issues you might experience
  • Audio: Used to play sound effects either 2D or at a specified location

Collision

The item requires an actor to overlap with the item before it can be collected. Make sure you have some collider on the actor and that the intended collector can overlap with the item/collider

API Reference

Properties

Property Description Type Default Value
DestroyOnCollected Should the item be destroyed after it has been collected bool true
AllowedCollector The type of actor that can collect the item EAllowedCollector EAllowedCollector::PossessedPawn
AllowedCollectorTypes The array of actor types that can collect the item TArray<TSubclassOf<AActor>>
CollectedSoundEffects An array of sound effects played when collecting the item TArray<USoundBase*>
CollectedParticleFx The particle effects spawned when collecting the item UNiagaraSystem* nullptr
CollectedParticleFxSpawnOffset The offset applied to the location of the collected particles when spawning FVector
bCompleteQuestPointAfterCollecting Should the quest point be completed after the item is collected? bool true

Functions

Name Description Params Return
CanCollectItem Check if the item can be collected Collector (AActor*)
A pointer to the actor that is trying to collect the item
bool
A boolean value indicating if the item can be collected
CollectItem Collect the item Collector (AActor*)
A pointer to the actor that collected the item
OnItemCollected Called after the item is collected Collector (AActor*)
A pointer to the actor that collected the item

Blueprint Usage

You can use the CollectableItem using Blueprints by adding one of the following nodes:

  • Ultimate Starter Kit > Item > Can Collect Item
  • Ultimate Starter Kit > Item > Collect Item
  • Ultimate Starter Kit > Item > On Item Collected

C++ Usage

Before you can use the plugin, you first need to enable the plugin in your Build.cs file:

PublicDependencyModuleNames.Add("USK");

The CollectableItem can now be used in any of your C++ files:

#include "USK/Items/CollectableItem.h"

void ATestActor::Test()
{
    // CollectableItem is a pointer to the ACollectableItem
    bool CanCollectItemValue = CollectableItem->CanCollectItem(Collector);
    CollectableItem->CollectItem(Collector);
    CollectableItem->OnItemCollected(Collector);
}