// Copyright William Antonio Pimentel-Tonche. All rights reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ConnEventFunction.h"
#include "Components/BoxComponent.h"
#include "ConnEvent.generated.h"
class AConnEventFunction;
class UBoxComponent;
/**
* Custom class that handles the backend of the events framework.
* To set up an event with an actor, you can do so in one of two ways:
* * Attach the event to the target actor in the editor (event should be child!) and set up your trigger settings
* * Create an actor derived from this class or reparent an existing one, integrating event functionality natively
*/
UCLASS( Blueprintable, meta = (DisplayName = "Event") )
class CONNEVENTFRAMEWORK_API AConnEvent : public AActor
{
GENERATED_BODY()
public:
/**
* TODO: Create a derived event class with triggers built-in, so developers can pick between them. [SOLVED: Put triggers here in this class.]
*/
/**
* Trigger settings for this event, such as component tags.
*/
/**
* Root component of this actor.
*/
UPROPERTY( Category = "Components", VisibleAnywhere, BlueprintReadWrite )
USceneComponent* Root;
/**
* Box collision component to serve as a trigger.
*/
UPROPERTY( Category = "Components", VisibleAnywhere, BlueprintReadWrite )
UBoxComponent* TriggerComponent;
/**
* This is the call stack container.
* Event functions should be listed in the order in which they should be called.
* ALL EVENT FUNCTIONS SHOULD BE CHILDREN OF THIS EVENT (for organization and optimization purposes)
*/
UPROPERTY( Category = "Event System", EditAnywhere, Replicated )
TArray<FConnEventCallStack> CallStacks;
AConnEvent();
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
/**
* Construction script functions.
*/
virtual void OnConstruction(const FTransform& Transform) override;
#if WITH_EDITOR
/**
* If your event and its functions don't need to know their own world transform (most of them won't), use this to center it.
* This sets the relative location and rotation to 0.0f on all axes, and the scale to 1.0f on all axes.
*/
UFUNCTION( Category = "Event System", CallInEditor )
void CenterEventFunction();
/**
* Tries to rename the event function to be compliant with framework standards as best as possible.
* If your name already complies you likely won't need this.
*
* @see Conniption Framework Documentation for more information.
*/
UFUNCTION( Category = "Event System", CallInEditor )
void ApplyReasonableEditorName();
#endif
protected:
/**
* Server RPC for StartEvent().
*/
UFUNCTION( Category = "Event System", Server, Reliable )
void Auth_StartEvent();
/**
* Called when the event call stack begins - in other words, when this event is triggered.
* This is called by Auth_StartEvent() in C++, a server RPC.
*/
UFUNCTION( Category = "Event System", BlueprintNativeEvent )
void StartEvent();
/**
* Server RPC for InitializeEvent().
*/
UFUNCTION( Category = "Event System", Server, Reliable )
void Auth_InitializeEvent();
/**
* Initializes the event by setting up triggers (such as collision and interaction queries) and binding event delegates.
* This is called by Auth_InitializeEvent() in C++, a server RPC.
*/
UFUNCTION( Category = "Event System", BlueprintNativeEvent )
void InitializeEvent();
/**
* Creates collision and interaction queries for the parent object.
* This is an automated process that calls some internal functions by default, but you can override it manually.
*/
UFUNCTION( Category = "Event System", BlueprintNativeEvent )
void CreateEventQueries();
/**
* Native version of CreateEventQueries(), overrideable in C++.
*
* Creates collision and interaction queries for the parent object.
* This is an automated process that calls some internal functions by default, but you can override it manually.
*/
UFUNCTION()
virtual void NativeCreateEventQueries();
/**
* Called when the game starts.
*/
virtual void BeginPlay() override;
};
// Copyright William Antonio Pimentel-Tonche. All rights reserved.
#include "ConnEvent.h"
#include "Components/BoxComponent.h"
#include "Editor/EditorEngine.h"
#include "Net/UnrealNetwork.h"
AConnEvent::AConnEvent()
{
bReplicates = true;
Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
Root->SetMobility(EComponentMobility::Movable);
SetRootComponent(Root);
TriggerComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("Event Trigger"));
TriggerComponent->SetupAttachment(GetRootComponent());
}
void AConnEvent::OnConstruction(const FTransform& Transform)
{
Super::OnConstruction(Transform);
SetActorRelativeLocation(FVector(0.0f));
SetActorRelativeRotation(FRotator(0.0f));
SetActorRelativeScale3D(FVector(1.0f));
}
void AConnEvent::BeginPlay()
{
Super::BeginPlay();
}
void AConnEvent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME( AConnEvent, CallStacks );
}
void AConnEvent::Auth_StartEvent_Implementation()
{
StartEvent();
}
void AConnEvent::StartEvent_Implementation()
{
if(HasAuthority())
{
}
}
void AConnEvent::Auth_InitializeEvent_Implementation()
{
InitializeEvent();
}
void AConnEvent::InitializeEvent_Implementation()
{
if(HasAuthority())
{
// Create event queries so that pawns (e.g. players) can trigger this event.
CreateEventQueries();
}
}
void AConnEvent::NativeCreateEventQueries()
{
// TODO: Add default event trigger components, e.g. box component, that the developers can then set up manually
}
void AConnEvent::CreateEventQueries_Implementation()
{
if(HasAuthority())
{
// Pass to C++ native function
NativeCreateEventQueries();
}
}
#if WITH_EDITOR
void AConnEvent::CenterEventFunction()
{
SetActorRelativeLocation(FVector(0.0f));
SetActorRelativeRotation(FRotator(0.0f));
SetActorRelativeScale3D(FVector(1.0f));
}
void AConnEvent::ApplyReasonableEditorName()
{
// Is owner valid
if(GetAttachParentActor())
{
// Get owner's editor name
const FString LocOwnerName = GetAttachParentActor()->GetActorLabel(false);
// Now we have a (starting point for a) reasonable name in compliance with our standards!
const FString LocFinalLabel = LocOwnerName + "_EVENT";
FActorLabelUtilities::SetActorLabelUnique(this, LocFinalLabel);
}
}
#endif
The problem is that this actor just won’t move in the editor. C++ or Blueprint class, it just refuses to move. I try to drag the transform widget and it just snaps back into place. I have been searching for answers all day and it just refuses to work, I even tried recreating the class and it won’t cooperate.
If anyone can find a solution that would be very helpful, thanks!