Hi beginner here! I have a blueprint that is a street light. It contains a box collision that detects if the player is in it. If it is, the player can press e to make the spotlight go on. The problem is is that I have a lot of those street lights in my scene. I’m trying to only turn the spotlight on from the street light that te player is standing under. How can I go about this? I’ve already tried using ‘get all actors of class’, but I just couldn’t find what i was looking for.
The easiest is probably to implement an interface, something like “action receiver,” that has two functions: “Add Action Receiver” and “Remove Action Receiver.” The argument to those functions, in turn, is another interface (say Action Runner) with a “Perform Action” method.
Lamp implements Action Runner. Player Pawn implements Action Receiver.
Then, in begin overlap for the streetlamp, the lamp calls Add Action Receiver on the Pawn that overlaps it. (You’ll want to turn off other kinds of overlap.) And in on end overlap, the lamp calls Remove Action Receiver.
In the player, implement the Action Receiver interface. You have a “current action receiver” variable, and in the “add action receiver” function, set that variable to the Action Runner passed in (which will be the lamp passing itself) and in remove action receiver, clear this variable to none.
When the player presses “turn on light” then call Perform Action on the current Action Receiver inside the Pawn.
Many ways. Here’s one:
- create a blueprint interface and add functions:
- implement it in the lamp actor (or any other actor we need to interact with):
- in the player:
We Use every actor 2 meters away from us. What Use means is dictated by the implementation in the target actor. A lamp will switch on / off. But a door could play an opening animation.
Cross posted with the gent above.
This is so simple to understand I had to save this page for when I implement “Interact/Use” functions in my game! Thank you for your knowledge!!!
Thank you so much! Exactly what I needed.