Problem with my flashlight to turn on and turn off

My flashlight is in another blueprint actor, for that reason I can’t insert the spotlight, pointlight, etc.

I created a custom event but it doesn’t leave me because I need cast to flaslight, and it doesn’t let me because the mesh is in another BP…
as you see in the picture
Do you have any idea how I can do it?

overall your explanation is pretty confusing.

“My flashlight is in another blueprint actor, for that reason I can’t insert the spotlight” your light component would usually be part of the flashlight bp (as you currently have it by the look of things).

“I need cast to flaslight, and it doesn’t let me because the mesh is in another BP” i think your confused as to how casting works and what its purpose is. usually for a cast you take a reference to another actor and the cast is used to identify it (it compares the class of the input object to a given class).

ok so what you need to do is to get a reference to the flashlight, then possibly do a cast, which will result in you being able to call your custom event. so for the reference you could get the reference when spawning the flashlight, or you could add it to the character and that would give you a easy reference, or theres many other ways to get a reference.

Something like that could be? but it doesn’t work for me, should I add something else for the reference or am I doing it wrong?

293406-cast-to.png

PD: Linterna is Flashlight

its hard to say whats wrong as you give so little information to work with. you say it doesnt work, how does it not work? as in what do you intend to do that it doesnt and or what does it do that its not meant to? where is the script that you show located (i assume in the character)? how are you setting the reference? what type / class is your new var 0? are you manually attaching the flashlight to the character or are you spawning it at runtime?

theres two reasons i would guess that your saying it doesnt work: first its probably not running the custom event, that issue is probably due to not setting your variables value to a valid actor. the second thing is youve probably noticed the warning on the cast, this warning likely just says that the cast is redundant (usually that would be a note however so it may say something different). if the warning is indeed saying the cast is redundant thats because you already know the class of the linterna so no need to cast.

I understand, sorry for the little information, when I return from my job I will better share the details,
I am short of time, I thank you a lot for these answers, tonight I will give you more info and better explanation :slight_smile:

the easiest way to setup the flashlight and access the script it contains would be like the following. first add the flashlight as a component of the character, next drag the flashlight from the my components section onto the event graph (this is now a reference to the flashlight), drag off the reference and search for your toggle lamp event.

the next easiest method is for the case of if you are spawning the flashlight during game-play. in this case you would have a button to spawn the flashlight say F, so you press F then have the spawn actor of class node, the return value of the spawn node is a reference to the flashlight that was spawned so you save that to a variable of type flashlight ( in your case Linterna object reference). then when you want to use the toggle lamp event you just need to get the variable that contains the needed reference, drag off and search for the event.

Hello friend, thanks for answering, I did differently but these answers also help me, thank you very much for helping :smiley: