I can’t get this to work for the life of me… I have a function in an actor class I created, I want to directly call it from a button. I exposed it with UFUNCTION() and tried calling it from OnClick event, but it’s not being called.
Can someone show how to do this? Thank you very much!
Did you specify that it’s callable from the blueprint?
// For a function that does not manipulate the class itself.
UFUNCTION(BlueprintPure, Category = "My Functions")
int GetSomeNumber() const;
// For a function that does manipulate the object in some way.
UFUNCTION(BlueprintCallable, Category = "My Functions")
void SetSomeNumber(int NewNumber);
I tried that, unfortuantely doesn’t work. Here’s what I have in the SomeActor.h
Now the SomeActor.cpp
GEngine->AddOnScreenDebugMessage(-1, 1000, FColor::Blue, FString::Printf(TEXT("It Works!")));
This is what I want to be called.
I created a Blueprint out of my C++ Class. Here’s what I have in the widget blueprint:
Inside my Blueprint of SomeActor I made a reference (to the blueprint actor) to be passed along to the Widget Blueprint:
However, OnClicked doesn’t call the SomePrintFunction. Perhaps someone can chime in the proper way to do this? I’m stuck and this is an important feature My guess it’s not getting the reference. What should I do? Thanks!
You’re calling a “Some Actor” actor to call ANOTHER “Some Actor” just to call the print function. There’s an anomaly in the way you setup your blueprints. Why not just call directly from the reference itself? Delete the “PrintMe” from the first “Some Actor”, and call the print function from there.
Also, you need to set the reference to something in the Widget. It does not have a reference set and you’re essentially calling from a NULL reference.
Is this a world actor or in the player character class?