I created a custom actor:
BPTest.h:
#include "GameFramework/Actor.h"
#include "BPTest.generated.h"
UCLASS(Blueprintable, BlueprintType)
class ABPTest : public AActor
{
GENERATED_BODY()
public:
ABPTest();
virtual void BeginPlay() override;
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "Custom event"))
void CustomEvent(float Value);
void CustomEvent_Implementation(float Value);
};
BPTest.cpp:
#include "ProBuilderPrivatePCH.h"
#include "BPTest.h"
ABPTest::ABPTest()
{
PrimaryActorTick.bCanEverTick = true;
}
void ABPTest::BeginPlay()
{
Super::BeginPlay();
CustomEvent(0.f);
}
void ABPTest::CustomEvent_Implementation(float Value)
{
UE_LOG(LogTemp, Warning, TEXT("CustomEvent_Implementation: %f"), Value);
}
I then created a blueprint from this actor class.
I added an instance of this blueprint actor in my level.
I would like to call this custom event from c++ in the editor, not when the game is started.
I tried this in a custom editor mode (extending FEdMode):
bool FProBuilderEdMode::InputKey(FEditorViewportClient *ViewportClient, FViewport *Viewport, FKey Key, EInputEvent Event)
{
for (TActorIterator<ABPTest> ActorIterator(GWorld); ActorIterator; ++ActorIterator)
{
ActorIterator->CustomEvent(1.f);
}
return FEdMode::InputKey(ViewportClient, Viewport, Key, Event);
}
but it does not work. I assume the game has to be started (hit play) in order for the blueprint event to be taken into account. Is my assumption correct?
How can I call a blueprint function from c++ when the game is not started (Is it even possible)?
I have seen UObject::CallFunctionByNameWithArguments
but it seems dirty.