Can't get cast to, to work

i want to be able to turn on and off the light,
but the cast keeps failing

top is player, bot is the spotlight

Your trying to cast the Player Character. This will not work unless the player blueprint has the spotlight blueprint, which it probably doesent.
If im correct when you use cast to,
it gets and sets to components of a specific object. So if the object does not have the blueprint on it, it will not work.
So when you drag a object into the object section of cast to – it must have the blueprint.

Get a reference to spotlight blueprint, then pull the return value node into cast to spotlight.

Select the spotlight in your level, then go to the level blueprint and right click, if context sensitive is unchecked check it, then select get a reference to (spotlight object name)
Then drag it into the object to cast to.

I hope this helps.

Is it like this you mean ? How to reference

because I can’t get that to work either, (I am pretty new to unreal/blueprints)
i got it working on something else that i had no use for so deleted it, and I diden’t edit the level blueprint to get that to work.
but I can’t remember how i did it

You got the concept of casting wrong and also expect the game to do magic for you.
How should the game know that with “get player and set the brightness” you mean "set the brightness on this specific light, which certainly is not an player)?

About casting

Any object has multiple types. Your Ford Mustang is of type “Mustang”. More generic, it is also an “Ford”. it is also a “car”. it is also an “object” (everything is an object).

Because the game engine usually works on the most common parent type (car instead of Mustang), you often end up with a situation that YOU know what type an variable is, but the game does not! And that’s the situation where Cast to is meant to be used.

Cast to does not fetch things, it is just a way to tell the game “hey, you might not know but this object here is actually also of type XX”.

The “get current car” function would return an “car” and not an “Mustang”, because you might change to an “Ferrari”.
Now here is the thing: You cannot call “get current car” on the sun. I think you agree, that an Ford Mustang is not a “Sun”.

Likewise, “get player character” is a value of type “Character”. You know it is a “Player_01”. if you want to do stuff that is specific to you, you now need to cast this value to “Player_01”. But the character is NOT a spotlight. By now you should realize that you cannot cast a player to a spotlight.

.

Which leads us to “But where can I get the spotlight which the user wants to use???”

There are multiple ways to solve this

One is: Use an collision actor in front of the light switch, which does “get player character” and sets a variable on it (eg “thing to use”). You then use this variable when the user presses the Use-key.

Another one is to use an line trace, which is an geometrical lookup of what the player looks at and which returns an array of results.

In the map “Blueprints_Advanced”, the last example on platform 2.5 has one about picking up items (by walking over them) and casting.
There is also an car driving tutorial, which does the “use car” with an collision actor

The next answer posted is a lot better at explaining then myself.
But no.
try this.
select the object
go to the bye print
Right click on the event graph
look on the top corner and make sure context sensitive is checked
then scroll up to the top
the third or fourth option is get reference to (whatever object name)
Click that them plug it into cast to SpotLight_blueprint