K2Node - Referencing the Components within specific Actor Blueprint?

Hey,

This is partially a follow up to - How to create K2Node that appears as multiple node entries per every Component/Property within Blueprint - basically, I created a node that behave in the way described in linked thread. The node “references” the component instance of specific type and does some stuff accordingly:

I intentionally typed “references” in such way as the node doesn’t really reference anything.
How I actually did this is a kinda nasty way - I’ve created a struct that contains the most important data about this component type, and the manager class (UEditorSubsystem) that stores the TSet with these structs.
So every time when the Component instance is created or edited, I make the call to the Manager, and the Manager decides if the Component instance is valid or not, searches for all Nodes and updates them accordingly.

This works quite well but I’m starting to regret such approach. Well I don’t know any different one but I could research more before starting to code.

The problem is that every call from Component to Manager works only if the component itself is loaded/created (obviously). So there are probably many edge-cases when the Component isn’t loaded yet but I already need to use its corresponding Node. e.g. Such case occurs when there is a compilation Error in Blueprint, then the component instance won’t be created until I start to edit this component, or until the compilation successes.


So my questions are:
Can I somehow make this logic work in a different way?
Is there any way to directly link the nodes with associated components / any way of directly referencing these components?
Is there any way of preloading these components to avoid such edge-cases?

I noticed that few K2Nodes use FMemberReference | Unreal Engine Documentation, probably to achieve something similar. However I’m not sure, if this is possible to use in my case. If yes, how?


Let me know if more context is needed. I can also paste the code that handles it right now.

I am studying K2Node recently. It is the same question I want to know.
There are something I have done,hope that can help.

Then,we work in Unreal Editor,code with Blueprint,the CPP object we need is not generate,whatever Actor or ActorComponent.All of setting is just recorded in UBluprint.Only the game began,it will be generated.So, if you want to find something,it should be find in UBlueprint.

My way is that(as my requirement):
First,to get the component pin and get the linked component’s name.
Because the component which the linked pin point to is not generate ,but it still can find the component name.(the reason I don’t know,if there is someone can explain for it?)

Second, search for UBlueprint to find the component.If the Blueprint is not inherit from another,the component will be at Blueprint’s SimpleConstructionScript,it is record as USCS_Node.
If Blueprint is inherit ,the compoennt will be at InheritableComponentHandler.
In there, the property "ComponentTemplate "is we need.It is the template that component will be ganerate after game start.

There are code.

UActorComponent* UK2Node_TestNode::GetLinkedAttributeComponent()
{
	UEdGraphPin* ComponentPin = GetTargetComponentPin();
	UBlueprint* Blueprint =GetBlueprint();

	if (ComponentPin&& ComponentPin->LinkedTo.Num() == 1)
	{
		FString LinkedComponentName = reinterpret_cast<UActorComponent*>(ComponentPin->LinkedTo[0])->GetName();
	if (Blueprint->InheritableComponentHandler)
					{
						FComponentKey Key = Blueprint->InheritableComponentHandler.Get()->FindKey(FName(LinkedComponentName ));

						if (Key.IsValid())
						{
							if (UActorComponent* TargetComponent = Cast<UActorComponent>(Blueprint->InheritableComponentHandler->GetOverridenComponentTemplate(Key)))
							{
								return TargetComponent ;
							}
							
						}
					}
				
		TArray<USCS_Node*>  SCS_Nodes = Blueprint->SimpleConstructionScript->GetAllNodes();

		for (auto it : SCS_Nodes)
		{
			if (it->GetVariableName().ToString() == LinkedComponentName )
			{
				if (UActorComponent* TargetComponent = Cast<UActorComponent>(it->ComponentTemplate))
				{
					return TargetComponent ;
				}
			}
		}
		
	}
	return nullptr;
}

It is take a detour.
It is know,a function be marked by“UFUNCTION(BlueprintCallable)”,it will create a node for blueprint.But how the node readding information form linked pin,that is I don’t know.If it can code the logic as that,it may be a more convenient way.
Welcome to communicate or tell me some paper to tall about it.