Hi,
I’m guessing you have found another way to do things by now but I was just confronted to the same problem and here is a pretty good bypass suggested to me by Rudy from Epic’s staff :
Instead of using a delegate you spawn a custom event in the blueprint and use PlayerController::ConsoleCommand(“ce evetname”) to call it. I don’t know if you have a way to easily handle parameters and/or return values as i did not need any for now but I guess you can find out easily by investigating this “ce” command.
Here is what my code looks like :
in your component’s header you add :
void Interact(class APlayerController* Player) const;
UFUNCTION(CallInEditor, Category = Interaction)
void GenerateEvent();
FString UVampireInteraction::GetEventName() const // handle your name generation as you see fit, here's mine
{
return FString::Printf(TEXT("%s_%s_Interact"), *GetOwner()->GetName(), *GetName());
}
and in the cpp:
#include "Kismet2/KismetEditorUtilities.h"
#include "Kismet2/BlueprintEditorUtils.h"
#include "EdGraphSchema_K2_Actions.h"
#include "K2Node_CustomEvent.h"
#include "Gameframework/PlayerController.h"
#include "Engine/LevelScriptBlueprint.h"
void UMyInteractionComponent::Interact(APlayerController* Player) const
{
Player->ConsoleCommand("ce " + GetEventName());
}
void UMyInteractionComponent::GenerateEvent()
{
UBlueprint* Blueprint = GetOwner()->GetLevel()->GetLevelScriptBlueprint();
FString EventName = GetEventName();
UEdGraph* TargetGraph = Blueprint->GetLastEditedUberGraph();
if (TargetGraph != nullptr)
{
TArray<UK2Node_CustomEvent*> EventNodes;
FBlueprintEditorUtils::GetAllNodesOfClass(Blueprint, EventNodes);
for (auto NodeIter = EventNodes.CreateIterator(); NodeIter; ++NodeIter)
{
UK2Node_CustomEvent* BoundEvent = *NodeIter;
if (BoundEvent->CustomFunctionName.Compare(*EventName) == 0)
return;
}
// Figure out a decent place to stick the node
const FVector2D NewNodePos = TargetGraph->GetGoodPlaceForNewNode();
// Create a new event node
UK2Node_CustomEvent* EventNode = FEdGraphSchemaAction_K2NewNode::SpawnNode<UK2Node_CustomEvent>(
TargetGraph,
NewNodePos,
EK2NewNodeFlags::SelectNewNode
);
if (EventNode->Rename(*EventName, EventNode->GetOuter(), REN_Test))
{
EventNode->CustomFunctionName = *EventName;
EventNode->Rename(*EventName, EventNode->GetOuter(), REN_ForceNoResetLoaders | REN_DontCreateRedirectors);
}
else
{
// You might want to handle the error here
}
// Finally, bring up kismet and jump to the new node
if (EventNode != nullptr)
{
FKismetEditorUtilities::BringKismetToFocusAttentionOnObject(EventNode);
}
}
}