I had an old system where if my character overlaps with a lets say gold piece i add 1 more gold to my total gold variable in my character bp and then that gold piece would disappear. I was doing these kind of interactions with “cast” but because it is bad to the performance i want to do it with interfaces. My question is how can my character bp know which blueprint send me the interface event. For now i added a box collision to the gold piece and i check if the overlapper actor has interface. If i only have 1 blueprint like this there wont any issues but if i have another silver piece how will i manage it?
There are two problems with casting
-
The class gets loaded. This doesn’t matter for you, because you have coins all over the map, so it’s already loaded.
-
There is a very slight performance hit. Again, in your case, you’re not doing it on tick, so it doesn’t matter.
So you can just use casting if you want.
If you specifically want to use an interface:
To make things work, you need the collision box in the coin, not the player. When anything overlaps the coin, it doesn’t check it’s type, it just sends the message ‘I’m a coin’ to the actor ( it also sends an actor reference to itself as a parameter ).
The player implements the interface call by adding 1 to the coin count, and destroys the coin actor.
You can get it a little cleaner, by having another interface message going back to the coin to destroy itself, but it doesn’t really matter.
Coin
Player
I was doing that actually.
Also can i ask how you do this? Can you convert interface events to functions?
When i implement it comes as an event