Setting CallFunctionByNameWithArguments argument in c++

Hi, i know this question ha been touched upon before but im getting mixed messages so would like it cleared up.

My problem:
I have a C++ file which is spawning a bunch of ‘AStar’ actors which are also in C++.

In the AStar constructor im constructing a UMG widget, created in the editor.

static ConstructorHelpers::FClassFinder<UUserWidget> StarBilBoardFinder(TEXT("/Game/UI/StarBilBoard"));
vStarBilboard = StarBilBoardFinder.Class;

This UMG widget has a bunch of nodes in the event graph which makes sure its facing the player however i need to make sure this UMG widget has a reference to the ‘AStar’ actor that its supposed to be associated with.

In order to do that i need to set that AStar variable in the UMG blueprint from the AStar actor class in C++.
Now i know i cant set the variables directly well ive pretty much exhausted all options to try and do this none of which work.

So i was thinking of using the CallFunctionByNameWithArguments
[link text][2]
So i created a function in the UMG Blueprint like so

Then called the function from the AStar c++ class

FOutputDeviceNull ar;
const FString command = FString::Printf(TEXT("SetAStar %s"), this);
StarBilboard->CallFunctionByNameWithArguments(*command, ar, NULL, true);

The function gets called in the blue print but the value on the node is alway none.

I need to pass over the AStar object and i cant figure out how to do it. Is it even possible?

Many thanks in advance

2 simple ways of solving this easy:

  1. Create a blueprint child of AStart Actor, and spawn the widget in blueprints, set the variable there.

Then you could spawn a static blueprint class by name or the class that creates the AStart actor can also have a blueprint version where you set which class to spawn. So the C++ spawner just spawns “that class”

  1. Create a C++ parent for the widget so you can crate and access its variables in C++, then just parent your widget to it’s new C++ parent (the parent class should be of type: UUserWidget)

Then spawn the blueprint version, but with a reference you can still access its C++ parameters. as long as you cast to it parent.

Thanks for the help could you explain option 2 in a little more detail?

I have created a new C++ class ‘StarBilboardWidget’ with its parent ‘UUserWidget’ i then changed the UMG widget parent class to ‘StarBilboardWidget’.

Then you lost me :slight_smile: any further help is greatly appreciated.

you could do something like:

UStarBilboardWidget* CreatedWidget = Cast<UStarBilboardWidget>(TheWidgetYouCreatedInTheFirstPlace);

adjust yo your names though.

Perfect thanks.
I now have access to the AStar actor inside the blueprint.
Different issues now… yay!

Thanks again.