Broadcast update : what would be the smart way to do it

Hi All,

I’m working on a model in UE4; and for this I would like to use this concept (example)

  • every 15 minutes the Sun will broadcast it’s temperature
  • all the (BP) objects that “listen to this event” will set their “Active temperature variable” to the new temperature
  • a BP-object uses this Active variable in it’s internal logic
  • and on some other event this BP-object will also broadcast it’s own value (that other BP Objects will listen to)

I would like to avoid looping through lists of BP-objects.

In ActionScript3 I would have made an event and listeners; so every instance of an object would act on this event.

How would I do something like this in BP?

Any help and pointers in the right direction would be greatly appreciated

Thanks

EDIT : the 15 min. is an example; could be a lot faster / several events would fire in a sequence based on a thick event (delay)

imo, This is the more optime way. why dont wanna use it?

btw.
how many objets.
for what hardware system?

Ok. thanks.

Maybe I’m just stuck in “some way of thinking” :slight_smile:
… and I thought I read somewhere not to use “get all actors from class” too much.

I just liked the as3 way of just adding and event listener to an object; not thinking about ref-list, etc…

But again; maybe I just should re-think this

GTX 780 / i7 / 32GB

10.000 or more if possible (most can be invisible) … just when focus should they be rendered.
But the invisible object should be active in the model.

yes, it is true. But you can do it when the level start.

Ok; but I need to update a lot.
So the best way would be to put all the objects of a class in an Array and loop through them?
=xu1a9jFZc7g
(so instead of the “get all actors” like in the video. If I use my own array (filling it while building the level) this would be the preferred way of doing it)

Another option would be to pull the variable from the sun using a “Cast To”. In each blueprint you then just have something that fires every 15 minutes to pull the variable.

Would save you having to get each object in the level you want to update.

Ok, thanks;
would that be wise from a performance point of view ?
a clock of the “tick event” in every BP; to pull the variables (of several other BP’s)

in both cases need cast, but 10000 ticks events are not sure what can happen, you can try because is more easy to blueprontermaker.

Ok, thanks;
would that be wise from a performance point of view ?
a clock of the “tick event” in every BP; to pull the variables (of several other BP’s)
[/QUOTE]

I will suggest using timeline for each object. I think if the interval is same you need not listen to the event you can set the timeline to each actor and perform the update after the set interval.

Though the drawback is you might have to change the timeline value for each of the object if you want to set it to different interval. Link for timeline.

or add this timeline in level blueprint as unreal engine documentation suggests to use level blueprints

“A Level Blueprint is a specialized type of Blueprint that acts as a level-wide global event graph.”

Thank you all for your input.

I will start experimenting with all the options. :smiley:

There are a couple ways I think you could do this. You’ll probably want to check out the “Blueprint Communication Methods” section of this page: Specialized Node Groups | Unreal Engine Documentation (I think there are also some demo maps/videos, but not sure off the top of my head).

One way is the aforementioned looping over a collection of actors manually and acting on them that way. You could construct that list in different ways (looping through actors up front and putting them in a list, having actors register themselves into a list as they begin play, etc.). If you needed different types of actors to be usable, you could also look into blueprint interfaces and use them in conjuction: Implementing Blueprint Interfaces | Unreal Engine Documentation.

However, another way you could do this seems much closer to what you’re used to. I actually had to just try this out myself because I’ve not used it yet (I live mostly in C++, so this was a fun excuse to learn!): Event Dispatchers | Unreal Engine Documentation

To try out your example, here’s what I basically did:

  1. Created a blueprint that represented the sun.
  2. Made the sun easily globally accessible to other blueprints.
  • There are various ways to do this. I assumed in this example that the sun was an important gameplay element that there was probably only one of, so I actually spawned it and stored a variable reference to it inside my GameMode’s blueprint. Note this wouldn’t be accessible to clients in a networked game (would probably want it in the GameState for networked play).
  1. Added a float variable to the sun blueprint to represent current temperature.
  2. Added an event dispatcher to the sun blueprint that will be fired every time the sun should broadcast a temperature update.

  1. Added a float input to the event dispatcher representing temperature.

  1. Hooked up a timer to call a function that would update the sun’s temperature every second inside the sun’s blueprint.

  1. Made the update function just constantly add to the sun’s temperature (getting hot in here!). In each update, it also calls the event dispatcher so any listeners will get the update.
  • To call the dispatcher, just drag it from the variable pane into the event graph and you’ll get a context menu:

  1. Created another blueprint that would act as a listener for the sun updates. I cleverly called it SunListener! So creative! :stuck_out_tongue:

  2. Hooked the blueprint up to be a listener to the sun’s event dispatcher by:

  3. Accessing the game mode during BeginPlay in the listener’s blueprint, casting it to my custom GameMode blueprint, and then accessing the sun variable stored there.

  1. Pulling off of the sun variable node and selecting the corresponding Assign function.

  1. Hooking up whatever I wanted for the auto-generated event from the Assign function. In my case, I just made it output the name of the actor and the temperature it received to the screen so I could see it was working.

  1. Placed some of the listener actors in the world, ran the game to see what happened…and VOILA!

Hope this helps! I’m definitely not a blueprint expert, so there may still be some other better ways to do this too!

Hi Billy,

Thanks for this in depth reply. I will start building your example right away!

when finish, can you share the performance of the 10000 objets?, for shake of curiosity.

Yes; I will share ASAP

…need to figure out step 2. Global ref to my sun object

Must be doing something wrong. I crashed my Editor 3 times (did the auto report)

And I get this error:

Error Accessed None ‘MySunRef’ from node Construction Script in blueprint Shape_Cube

I not sure but events in Construction look to me rare.

As far as I can tell I did not put it in the Construction Tab of the listner object
(or did you mean the GameObject; I only put in the Ref to the SunObject)

But maybe I’m missing something with this “GameObject”

Uh oh! Ok, I’ll try to get someone from the blueprints team to come in here and make sure I didn’t steer you wrong! In the meanwhile, maybe there’s some diagnostic stuff we can do to see what’s going on:

  • Do you have any more information about the crash you remember? Logs? (I’ll see if someone can track down the report)
  • What does the construction script of the Shape_Cube look like?
  • How are you setting up the value of the sun ref variable in the game mode?
  • Which version are you on? I made mine at home yesterday on 4.2. Just want to make sure there isn’t a chance of some bug in a different version.

Apologies for the difficulties and hopefully we can figure out what’s going wrong, or if I accidentally misled you!

Hey NanoMind -

Can you post your crash logs, so we can try and help you out? Thanks!