Skip to content

Recipes

Make the key never start in the same place

Section titled “Make the key never start in the same place”

Add the component to the key, place 4–6 Item Spawn Point actors across the level and reference them all. Turn Include Home Location off. Every playthrough the key is on one of the points.

Five collectibles, eight points, every collectible references all eight. The reservation guarantees that no two collectibles land on one point. If there are more items than free points, the leftovers stay home.

Leave Include Home Location on. The authored location is one more candidate, so a returning player can’t rule it out.

Make drawers and shelves behave differently

Section titled “Make drawers and shelves behave differently”

Tag points Spawn.Drawer and Spawn.Shelf. In the item’s Event BeginPlay:

Item Spawn Randomizer → Has Assigned Point Tag (Spawn.Drawer) → Branch → Set Simulate Physics (true)

The item slides when the drawer opens; on a shelf it stays static.

Lock a layout for a trailer or a demo build

Section titled “Lock a layout for a trailer or a demo build”

Play until you get a layout you like, read the seed from the LogItemSpawn summary line (or Get Session Seed), and set it as Global Seed in Project Settings → Game → Item Spawn Randomizer. Every session reproduces it.

When New Game+ starts, call Get ItemSpawnSubsystem → Reroll All. Items the player already collected (hidden) or is holding (attached) are skipped; everything else gets a fresh layout.

Bind a development-only input to Execute Console Command with ItemSpawn.Reroll and shuffle the level while play-testing.

The item’s pivot is at its centre, so it lands half inside whatever the point sits on. Set Location Offset Z to half the item’s height once. Every point can then sit on the surface, and the ghosts show the corrected placement.

MyKeyItem.h
#include "ItemSpawnRandomizerComponent.h"
UCLASS()
class AMyKeyItem : public AActor
{
GENERATED_BODY()
public:
AMyKeyItem();
protected:
virtual void BeginPlay() override;
UFUNCTION()
void HandleRelocated(UItemSpawnRandomizerComponent* Component, const FGameplayTagContainer& PointTags);
UPROPERTY(VisibleAnywhere)
TObjectPtr<UItemSpawnRandomizerComponent> SpawnRandomizer;
};
MyKeyItem.cpp
#include "MyKeyItem.h"
#include "GameplayTagContainer.h"
AMyKeyItem::AMyKeyItem()
{
SpawnRandomizer = CreateDefaultSubobject<UItemSpawnRandomizerComponent>(TEXT("SpawnRandomizer"));
SpawnRandomizer->bIncludeHomeLocation = false;
}
void AMyKeyItem::BeginPlay()
{
Super::BeginPlay();
// The initial assignment already happened before BeginPlay: pull the result.
if (SpawnRandomizer->WasRelocated())
{
HandleRelocated(SpawnRandomizer, SpawnRandomizer->GetAssignedPointTags());
}
// Catches later relocations (RerollAll / New Game+).
SpawnRandomizer->OnRelocated.AddDynamic(this, &AMyKeyItem::HandleRelocated);
}
void AMyKeyItem::HandleRelocated(UItemSpawnRandomizerComponent* Component, const FGameplayTagContainer& PointTags)
{
static const FGameplayTag DrawerTag = FGameplayTag::RequestGameplayTag(TEXT("Spawn.Drawer"));
if (PointTags.HasTag(DrawerTag))
{
// React to starting inside a drawer.
}
}
if (UItemSpawnSubsystem* ItemSpawn = GetWorld()->GetSubsystem<UItemSpawnSubsystem>())
{
ItemSpawn->RerollAll();
}