Changing actor mesh material with UMG button click c++
I'm new to UE4 and find most of the help related to blueprints. I simply created a UI Widget Blueprint with one button and in Event Graph: Event BeginPlay->Create UserWidget->Add to Viewport. Then created an actor C++ class with a StaticMeshComponent. In constructor, finding mesh and material in contents folder and setting mesh component. Now material is found and saved, I have SetMaterial function which I want to be called using user widget button click. How to call a c++ actor function from UMG button? Should it be called from user widget event graph OnClick or from elsewhere? I couldn't figure out the casting and references.
Please give some pointers or material to study for this simple task and also the same task with drag n drop i.e. drag button material on a mesh to change material. Thanks
asked May 03 '18 at 08:39 PM in C++ Programming
In order for a C++ function to be called in Blueprint you need to put this macro just before declaring the function in your .h file:
If you do this, your function will be callable within blueprint.
Then, all you have to do is, in your OnClick event, use GetPlayerCharacter, then cast to your AMesh character (if you made a blueprint class of your AMesh character, use that instead), and simply call the SetMaterial1() function from there ;)
answered May 03 '18 at 08:57 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here