How can I change the variable in the actor blueprint with the button in the widget

Hello everyone How can I change the variable in the Actor blueprint with the button in the widget. I want to change the static mesh of the warrior’s sword in my game, I want to do this with a button on the widget, I assigned an interger value to the static mesh with a table and it works, but when I try to change this interger value with the widget interger value not change, I guess I can’t cast it.

You can get the actor with ‘get actor of class’ and then update it :slight_smile:

2 Likes

Not working :frowning: my codes
https://imgyukle.com/i/JLHhlx
https://imgyukle.com/i/JLHmIh

Blueprint Runtime Error: “Accessed None trying to read property CallFunc_GetActorOfClass_ReturnValue”. Node: Set Objectid Graph: EventGraph Function: Execute Ubergraph Market Blueprint: Market
Blueprint Runtime Error: “Attempted to assign to None”. Node: Set Objectid Graph: EventGraph Function: Execute Ubergraph Market Blueprint: Market

The construction script only runs when you place the actor in the level. If you want it to run again, you need the same code connected to a custom event, and call that.

Use the ‘get actor of class’ to get actor from the widget. You need an instance of the actor in the level.

1 Like

I did what you said, I used another event, but I still get the error in the picture

Clicking this

image

will take you to the offending node. If it’s your ‘get actor of class’, then you don’t have one in the level.

For the other, it’s no good putting it on begin play, because you will need to call that code after you’ve changed the sword index.

my game starts from the mainmenu map but the actor is in another map I guess that’s why

Could be. You can’t change an actor that’s in another map :slight_smile:

thank you very much for kindly helping me, i sent the variable in gameinstance and used event tick instead of begin play its done :slight_smile:

1 Like