Device Registration System - Complete Documentation

Table of Contents

  1. Quick Start Guide
  2. File Structure
  3. Core Components
  4. Implementation Patterns
  5. Blueprint Integration
  6. Advanced Features

Quick Start Guide

5-Minute Setup

Step 1: Add Components to Your Actors

MyButton.h (Your header file)

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/SenderComponent.h"  // From: Components/SenderComponent.h
#include "Interfaces/RegistrationInterface.h"  // From: Interfaces/RegistrationInterface.h
#include "MyButton.generated.h"

UCLASS()
class YOURGAME_API AMyButton : public AActor, public IRegistrationInterface
{
    GENERATED_BODY()

public:
    AMyButton();

protected:
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Device")
    USenderComponent* SenderComponent;

    UFUNCTION(BlueprintCallable, Category = "Button")
    void ActivateButton();

    // IRegistrationInterface
    virtual void RegisterCallSent_Implementation(AActor* InstigatorActor) override;
    virtual void UnRegisterCallSent_Implementation(AActor* InstigatorActor) override;
};

MyButton.cpp (Your implementation file)

#include "MyButton.h"
#include "Data/EDeviceTypeEnum.h"  // From: Data/EDeviceTypeEnum.h

AMyButton::AMyButton()
{
    PrimaryActorTick.bCanEverTick = false;

    SenderComponent = CreateDefaultSubobject<USenderComponent>(TEXT("SenderComponent"));
    // Set Device ID in Blueprint or here
}

void AMyButton::ActivateButton()
{
    if (SenderComponent)
    {
        SenderComponent->SendGenericCalls(this);
    }
}

void AMyButton::RegisterCallSent_Implementation(AActor* InstigatorActor)
{
    UE_LOG(LogTemp, Log, TEXT("Button connected to device collector!"));
}

void AMyButton::UnRegisterCallSent_Implementation(AActor* InstigatorActor)
{
    UE_LOG(LogTemp, Log, TEXT("Button disconnected from device collector!"));
}

MyDoor.h (Your header file)

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/ReceiverComponent.h"  // From: Components/ReceiverComponent.h
#include "Interfaces/RegistrationInterface.h"  // From: Interfaces/RegistrationInterface.h
#include "MyDoor.generated.h"

UCLASS()
class YOURGAME_API AMyDoor : public AActor, public IRegistrationInterface
{
    GENERATED_BODY()

public:
    AMyDoor();

protected:
    virtual void BeginPlay() override;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Device")
    UReceiverComponent* ReceiverComponent;

    UFUNCTION()
    void OnSignalReceived(AActor* InstigatorActor);

    UFUNCTION(BlueprintImplementableEvent, Category = "Door")
    void OpenDoor();

    // IRegistrationInterface
    virtual void RegisterCallSent_Implementation(AActor* InstigatorActor) override;
    virtual void UnRegisterCallSent_Implementation(AActor* InstigatorActor) override;
};

MyDoor.cpp (Your implementation file)

#include "MyDoor.h"

AMyDoor::AMyDoor()
{
    PrimaryActorTick.bCanEverTick = false;

    ReceiverComponent = CreateDefaultSubobject<UReceiverComponent>(TEXT("ReceiverComponent"));
}

void AMyDoor::BeginPlay()
{
    Super::BeginPlay();
}

void AMyDoor::OnSignalReceived(AActor* InstigatorActor)
{
    OpenDoor(); // Blueprint implementable event
}

void AMyDoor::RegisterCallSent_Implementation(AActor* InstigatorActor)
{
    UE_LOG(LogTemp, Log, TEXT("Door connected to button system!"));
    
    // Bind to the OnCallReceived delegate
    if (ReceiverComponent)
    {
        ReceiverComponent->OnCallReceived.AddDynamic(this, &AMyDoor::OnSignalReceived);
    }
}

void AMyDoor::UnRegisterCallSent_Implementation(AActor* InstigatorActor)
{
    UE_LOG(LogTemp, Log, TEXT("Door disconnected from button system!"));
    
    // Unbind to the OnCallReceived delegate
    if (ReceiverComponent)
    {
        ReceiverComponent->OnCallReceived.RemoveDynamic(this, &AMyDoor::OnSignalReceived);
    }
}