blueprint interface help: trying to consolidate incoming data from multiple actors of same blueprint

Hi folks, been struggling with this issue and haven’t managed to find a solution on the forums.

So basically, I’m creating an adaptive music system and one of the FMOD parameters is set based on how far away the zombie NPC is from the player.

I’ve got this set up no problem; The distance value is calculated (and normalized) in the NPC blueprint and is sent to a ‘Music Manager’ blueprint I have set up that receives data to change parameter values.

This is the data getting sent from NPC (via a blueprint interface function):

And this is the music manager receiving the data and setting parameter value

This system works great when I am only dealing with 1 NPC. The issue arises when I have multiple zombies all sending their distance values into the set parameter node.

What I am trying to achieve is for my Music Manager blueprint to identify these values as coming from different sources, and to pick the lowest value to set the parameter. I have a feeling it involves consolidating all these separate values into an array but I am at a loss as to how I do that. especially as the size of the array would be changing frequently as NPCs die/come in or out the distance cut off.

This is also getting updated multiple times a second so I’m a bit cautious of using for loops or anything like that if using arrays.

Any help greatly appreciated! I have no formal training in Unreal/Comp Sci so please forgive me if my terminology is a bit off lol. Happy to provide more screenshots if needed

1 Like

You do have a variety of problems here, apart from how to implement this :wink:

The yellow pin on your initial call, show you’re not actually sending an interface call from the NPC. If you were, the node would have an envelope on it. If you just search for the node again, you’ll there are several, just choose the right one. At the moment, you’re doing a strange sort of custom event call.

One of the whole point of interfaces, is decoupling. What that means, is BPa send an interface call to BPb, and BPa, and neither of them should know anything about each other. But you’re getting the class of the calling actor in BPb, game over :slight_smile:

Either, you need only NPCs to make this call, or pass something else to let the receiving BP know what kind of call it is.

All that aside, a good way to do this, would be to use a map, also know as a dictionary. You can use that to do a lookup on the actor reference, and set/get it’s last known float value. It’s also a good idea for the NPCs to send an ‘I’ve died’ call to the hub, so they can be removed from the map.

I hope this is making sense :slight_smile:

Interesting! Yea I’m still not fully sure on how to properly use blueprint interfaces and whether they are even the right tool to use for this job.

Im not familiar with maps/dictionaries but that sounds more like what im after, I’ll look into it

Thanks!

1 Like

Sounds good :smiley:

The only way an interface is a tool, is to decouple actors.

not finding the call function node with the envelope. i do know the one that you’re referring to as ive seen it in tutorials but im not seeing it anywhere for me.

I guess one thing im confused about blueprint interfaces is how to tell Unreal where to send the call functions. For instance, in my first screen shot, the ‘Target’ is a reference to the Music Manager BP. I made that reference by doing a ‘Get actor of Class’ on Begin Play. But is this not a hard reference? does this defeat the purpose of using an interface? Whats the proper way to tell Unreal ‘send this stuff from this blueprint to this blueprint’?

I guess im mostly confused as to how to properly use interfaces for BPs to communicate/when it is even worth using them

1 Like

Interfaces are for talking from actor A to actor B, never any types involved. All variables should be ‘reference to actor’.

Assuming you’re not somewhere strange, like in a function or a widget, you should be able to drag from an actor reference and call your interface on it.

You’re right about using types ( classes ) defeating the whole point. All decoupling is out of the window at that stage.

If you can set the correct actor with the dropper tool in the level, then you’re done. Otherwise ‘get all actors with tag’ or something like that is a good way of doing things ( only on begin play ), and you need to tag the actor, or course.

Watch out: actor tag. You can set it in the blueprint details, so any copy of your BP will have the tag.

1 Like

interesting! this is very helpful, will look into this.

Thanks!

1 Like

Hey, you were very helpful yesterday so I thought I’d give you an update.

I decided to scrap the whole system and start again. I realised my mistake was taking the distance measurements from the NPCs then trying to send all the individual distance measurements to the MusicManager BP, which was a total mess tbh.

What I have now done is take the distance measurement from the PlayerCharacter after finding the nearest NPC. I did this by adding all nearby zombie NPCs into an array.
It works perfectly and was a lot easier to implement, and doesnt seem too expensive either. Its funny how just sitting down with a pen and paper for like 5 minutes can make you realise what you actually need to do lol.

heres the system

1 Like

Yes, this looks good. Glad to help :sunglasses:

1 Like