Cast from character bp to actor

I want to change the directional light with a widget thats inside the firstperson character bp
But when i cast to the directional light it asks for an object, what should that object be?

Kindly reguards

Just to make sure: the directional light is part of the first person character and you want to change it through a widget, right?

If so, you just need to get a reference to the first person character, then get a reference to the directional light component that is in it, then change the parameters of the directional light. This should not require a cast, but I can be more precise if you can show how you setup your character and the light within it.

Directional light is placed in the level

Where is this directional light? Placed manually in the persistent level or owned by an actor?

If you intend to accomplish this through the characterbp you need to get a reference to the directional light, to do this have two options that i can think of.

first you could create a variable of the type “directional light” and make it public then you could set the directional light via the details panel (this would only work if you placed your character in the level), another way to set the variable would be on begin play in the level blueprint where you would need to get a reference to the player via casting then set the variable from a reference.

The second method is also a bit messy. it would involve on begin play you would get all actors of class and set the class here to directional light. you would then need to come up with a way to get the right light from the array. Alternatively you could make a new blueprint actor that contains the directional light (and have it as the only one of its kind in the level) and get a reference to the light as mentioned previously.

There are probably other methods as well.

Thank you, it Helps alot

Directional light is placed in the
level

In case you ever revisit this topic in search for more answers.

Consider using [Event Dispatchers][1] for this, it’s one of the methods to communicate with the Level Blueprint. It does take some time to wrap one’s head around, though.

The most straightforward use scenario would look something like this:

Create a dispatcher In the Player Character (you can send any type of data this way):

228883-eventdispatcher.png

In the widget, you get access to the Player Character and call the dispatcher (Call ED_AdjustLight sending a float value)

In the Level Blueprint you bind the dispatcher to any Custom Event you desire (and you automatically get access to the data you sent):

Now, whenever you use a slider in the widget (pic 2), it asks the Player Character to dispatch a request. If anyone is listening to this request (and the Level Blueprint has a registered custom event just for that), the data will be sent to the Level Blueprint.