Can't access an Actor in Widget.

Hello,

Imagine this,

When i click the button, it will flow to the end in a normal way for an actor’s blueprint event.

But when it comes to a widget’s blueprint event, you can’t access neither a Game Instance or any Actor (Character, Actor, Pawn), as you can see in the image (It’s in a widget’s blueprint), when it’s CAST (Proyectar a TheGameInstance) the flow of the nodes stop at DoOnce.

I did tried to look if it’s working or not with two Print Text, one at the start (The one that is HELLO) and another one that is in the end of the flow. So when i click the button, it will only show the Print Text Hello but the one at the end do not.

So the problem is the CAST, i casted an Actor and the Game Instance and none doesn’t work.

1.What i want is to let me access my Actor or Game Instance (Preferly the Actor, that’s my character).

I have another question, slightly related with my main problem:

My widget is the main menu which is in the map 1, and if i activate a variable (Changing my variable) from my main menu and go to map 2 (WITHOUT leaving the Play Mode, i mean going to another map through a button of the main menu like a normal game), do i keep the changed variable when i go to another map or do i keep the default value of my variable? This is without the Game Instance.

EDIT: For the number 2 question, i have a solution for the number 1 that is making the variables in the widget and not in the actor because in an actor i can access the variables of the widget, but i really don’t want to use this way. But if i can’t do the first one, please tell me if the second one works or not.

EDIT2: Whatever… i found out that i still need to use the second one even if i have the solution for the first one.

Thanks for the answer.

[Facepalm] I’m so ashamed, i forgot to switch the GameInstance option in the proyect setting… now i can access it in the widget blueprint. But i still have a question, Do i need to do anything else on my Game Instance to save my variable’s value when i go to another map that is not the Main Menu or does it save alone? (This question is like the one above, Number 2 question).

Thanks for the answer.

you can access your character by using GetPlayerCharacter (or GetPlayerPawn depending on what your character is) then Cast that to the name of your character blueprint. you can also do this with GetPlayerController, GetGameMode, and pretty much anything else in the MapsAndModes section. If its not a player, To get another blueprint, you can use interfaces, which i personally found very confusing when starting out. Another alternative, depending on the situation, you can use GetAllActorsOfClass > ForEachLoop> then that blue pin will refer to the actor(This works perfectly if you only have One of this blueprint in the level or need to do something to all of them)