I have always been able to call a cast to player character node and also a cast to game mode node in blueprints and everything worked well. I have a basic understanding that the cast nodes are like portals to access variables and functions from within another blueprint.
I have 2 questions:
(For both of these questions, none of the actors mentioned are the player characters or player pawns)
My first question is, how does one cast a normal actor to another actor without getting that wildcard error?
I have looked online for a straight answer, but I don’t understand a lot of peoples answers. What do you plug into the Object pin if you are just referencing another actor that is not in the world yet?
My second question is, how does one cast a normal actor to a widget blueprint without getting that wildcard error?
As you know, there are a lot of different classes of object in UE, a lot of them inherit from each other. In other words, the functionality of object B is an extension of object A. B does everything A does, and more.
Casting is a way of doing two things:
Checking a reference you have to an object is really a reference to that kind of object ( hence the fail pin on the cast ). Do I really have an A here?
Telling the system at which point in the class hierarchy you want to focus on. ( I know I started with a reference to an A here, but now I want to talk to the B part of that. Hence the cast ).
If you want to just talk from one blueprint to another, you don’t have to cast, you can just use references. Here’s a good vid on that:
Also, between widgets and actors: Talking from widget to actor, no problem, for instance use GetAllActorsOfClass or GetAllActorsWithTag, and find the one you want talk to.
As far as getting from actors to widgets goes. Off the top of my head, not sure, might be a bit more of a fiddle, I’ve never had to do it.
Casts are not portals to acces variables from another blueprint.
Casting to blueprint A is like asking the game if the object you inputed as the wildcard was spawned from the blueprint A. (Or from something it inherits from).
If you want your actor to communicate with the widget, you need a refference to that widget.
When you create the widget and add it to the viewport, you get a refference. Drag the output of “create widget” node and promote it to a variable. Name it “WidgetVar” or whatever you want, and then cast to the blueprint where the widget was spawned (assuming the blueprint you spawned the widget inside is the player, GetPlayerCharacter should do the trick for the wildcard) . Then cast to the widget using WidgetVar.
I think this is the easyest way to do this. You could use get all actors of class but i do not recommend it because of the poor performace of the node.