How to Cast from Actor BP to Widget BP - Object pin error

Hello,

Having trouble with the Cast to function. Cant figure out what to connect Object Wildcard reference pin to. Trying to Cast to an Actor BP (where all my variables are) from a Widget BP. All tutiroals online say connect a Player Character function, but this is irrelevent to my situation as Im not cating to a player character, just an actor BP.

The pin is asking for a reference to the instance of the swap manager.

You need to tell the editor which one you mean as there might be many. If you are going to have 1 only, ever, you could Get Actor of Class (you even wouldn’t need to cast) but it’s generally bad practice if misused.

You will need to learn about references anyway as you will face this issue every single time you want 2 or more blueprints to communicate:

  • how and where is the swap manager created
  • how and where is this widget created

Thanks for reply,

I initially had everything working using ‘get all actor of class’, but I got put off by everytihng Im reading in regards to heavy memory use and I use it a lot.

The swap manager is just an actor which im using to store variables and as my min blueprint manager. I’ve dropped it into the scene which just renders as a white sphere by defult. (defult scene root?) There is only one, and will always remain in the scene.

The widget menu im trying to use tgeh cast function in is called from the swap manager at a certain point using the create widget function.

Would love to learn how to reference proplerly, seems pretty fundamental

Cheers

The widget menu im trying to use tgeh cast function in is called from the swap manager at a certain point using the create widget function.

To clarify:

  • the swap manager sits in the scene
  • the swap manager creates the widget with the Create Widget node and Adds it to the Viewport

The idea is to click a button in the widget and do something with the data the manager has access to.

Could you confirm?

Yes 100% thats whats happening

It’s this then:

We tell the widget to inform the swap manager whenever the button is clicked - this executes the custom event. Since we’re doing all of this in the manager itself, all the data is already here. No need to cast or reference anything else.

Event Dispatchers are perfect for this kind of communication - a component / widget talks back at the owning parent.

Avoid scripting / processing data in the widget - see if you can treat widgets as display elements only when possible, let the actor process data. Widgets can handle the way the data is displayed.

The above is set up for a single button, if you have 10 buttons, it should still be manageable (you’d need to Bind 10 buttons, though). If you have 20+ buttons, it will become cumbersome to manage manually - another method would be needed. Do tell.

Thanks! Very interesting, and good to know RE avoiding scripting inside widgets. I haven’t tried bindings yet, but ill try, I only have three widget buttons so it should work. I’ll let you know how I go :slight_smile:

If I had 10 or so buttons, I’d probably do this in the widget:

And then this in the manager:

Don’t know the official name for this. People have been referring to this as auto-bind. Less messy. There are other methods, too. You choose the right tool for the job, for the scope of task at hand.

Good luck!

get player pawn maybe :thinking:

Can you say exactly want you can. An Actor can hold a wiget component.
and you can store a reference of this actor in the widget.

actor BP in there i have a widget component

and then you are able to get all properties of the Actor in the widget.

Is this what you need?

Im trying, but my button reference doesnt want to connect to the Bind Event to On Click - I get a message saying ‘Button object reference not compatiable with Actor Object Reference’ I’m probably missing something :thinking:

is Canopy a widget button?

Yes

Blueprints are context sensitive, you generally want to drag a wire first and then search - this way you’ll get filtered results that make sense in this context.

plz show your widet. the new var is the button? how you call the event, how you defined the event?
But in general, dont make make the button public, and dont handle the click event in the actor. you mix everything.

1 Like

@Cissoid according to OP, they’re not using widget components. Creating hard references as you suggested is not the best practice around. You can do the binding without creating a hard reference. But it can be useful if you need to access the widget later on.

1 Like

Oh I see, working now, Thankyou so much