Download

Invoke Default Event Node

Hi,

I created a default event node in a custom subgraph of a blueprint editor. I wanted this event to auto generated within a graph i inherited from UEdGraph. I implemented this behaviour
in MySubGraphCustomSchema::CreateDefaultNodesForGraph(UEdGraph& Graph)const.



void MySubGraphCustomSchema::CreateDefaultNodesForGraph(UEdGraph& Graph) const
{
	UBlueprint* const Blueprint = FBlueprintEditorUtils::FindBlueprintForGraphChecked(&Graph);

	int32 NodePosY;
	auto pEventNode = FKismetEditorUtilities::AddDefaultEventNode(Blueprint, &Graph, FName(TEXT("Sequence Begin")), UStorySubGraph::StaticClass(), NodePosY);



0204ce9fa8d37fc3e37a8d29aaab7032f7e3de94.png

Is there a better way? How defaulted event nodes like BeginPlay, OnComponentHit are auto generated? I know they are declared as ‘UFUNCTION(BlueprintImplementableEvent)’ but what i’m asking is
how these nodes spawned automatically when you create a blueprint etc. I’m triying to is implement this kind of behaivour without using UFUNCTION() declarations.

Also how can i invoke these K2Node_Event node i just created?

I found out that KismetEditorUtilities class has a static member called AutoGeneratedDefaultEventsMap.



/** Mapping of classes to names of Events that should be automatically spawned */
	static TMultiMap<void*, FDefaultEventNodeData> AutoGeneratedDefaultEventsMap;


It’s used inside the FKismetEditorUtilities::CreateBlueprint function.




/*inside the CreateBlueprint function*/

// Spawn any defined auto generated default events for the class.  Only do this for the most senior class specified, 
// that subclasses may have an entirely different set of default nodes if they wish.
for ( TMultiMap<void*, FDefaultEventNodeData>::TIterator DataIt(AutoGeneratedDefaultEventsMap); DataIt; ++DataIt )
{
      FDefaultEventNodeData Data = DataIt.Value();
	if ( DefaultNodesClass == Data.TargetClass )
	{
		bFoundDefaultNodes = true;
		FKismetEditorUtilities::AddDefaultEventNode(NewBP, NewBP->UbergraphPages[0], Data.EventName, Data.TargetClass, NodePositionY);
	}
}


AutoGeneratedDefaultEventsMap maps void* pointers to FDefaultEventNodeData. Why is DataIt.Key() not used?

But these events are created with the blueprint editor inside the FKismetEditorUtilities::CreateBlueprint function.
I want these event to be auto generated with the graph itself.

I still don’t know how to invoke an event node created with AddDefaultEventNode.

I have another problem.
This is what my graph looks like with the event node.

After clicking compile button event node just vanishes.
This is what it looks like after clicking compile button.


You can see the name of it in the left side of the editor but node itself is vanished.

So i click the name of node and it’s visible again. But it’s different. It looks like an ordinary custom event.
And i can’t drag anything from it.