How to make USTRUCT member functions blueprint callable?

I was reading through the USTRUCT documentation here: Structs, USTRUCTS(), They're Awesome - UE4: Guidebook, and in the example it shows that USTRUCTs can have member functions or methods. But how can those be called in Blueprint?

USTRUCT(BlueprintType) exposes the USTRUCT to Blueprint and setting UPROPERTY macros on the variables can make those Blueprint accessible, but using a UFUNCTION macro on the member functions is not allowed. At least, I’ve gotten errors whenever I’ve tried.

1 Like

Ignore niyaleon. Probably some ChatGPT BS.

You can’t. The error message tells you exactly what the problem is, you can only have blueprint callable functions in classes and interfaces.

The solutions for this are 1) make your thing a UObject instead, 2) create a blueprint function library with the blueprint callable functions you want for your structure, 3) add static blueprint callable functions to some other UObject that you have that’s related to your structure.

5 Likes

If you didn’t say it, I was going to. I don’t know what’s worse, someone who answers but clearly didn’t read the OP or someone who responds with ChatGPT. Sometimes it’s accurate enough to work from, but I could have done that myself.

I appreciate the straight answer. Given the error, I was hoping there was another way – or maybe I had done something wrong.

Actually, I don’t even need it. When I saw that it was a possible option, I figured I’d try it. I was looking for a convenient way of setting Blueprint structs without having to split then drag 100 lines over and over whenever I want to set just one thing. Having a Set/Get method in the struct would have been a valuable time saver.

In the end, I’m just going to write a separate BlueprintCallable function in C++ that manages the struct data. It’s for a BP menu.

Thanks :+1:

If that’s the case, you’ll want to use the built-in set member in structure method. That does exactly what you want- just enable any of the pins you want to change.

Set members in structure does it by reference, so any changes will be saved to the variable you input.

ie for the PostProcessSettings struct:

Will that with a C++ struct?

It is automatically generated and will work with any blueprint exposed property.

Am I doing something wrong? I can’t seem to get the ustruct to appear… instead I get a returned coordinate even though the function returns void.

image

Please create your own post rather than piggy-backing off a tangentially related one. I promise you’ll get quicker responses there.

The & symbol after FAsmrTileCoordinate makes it a reference. Blueprints treat references as output even if they’re input.

To change this, add UPARAM(ref) just before FAsmrTileCoordinate& Coordinate
UPARAM(ref) FAsmrTileCoordinate& Coordinate

2 Likes

Thanks, perfect solution. I’ll also go ahead and make my own post in the future.

1 Like