Is it possible to reference 100s of actors without creating hard references?

Hi,

I’ve got a BP_DayNightCycle Blueprint. When it turns to night I want to tell hundreds of lights to turn on (might be less than this due to world partition, but ultimately there are lots of lights on a map).

I figured my best option here was to use an Event Dispatcher from my BP_DayNightCycle and then have my lighting BPs bind and listen to it. However, this means my lighting BPs will create a hard reference as the listener needs a reference to the BP_DayNightCycle object in order to listen to the event.

Is there a way to communicate with hundreds of actors like this without creating a hard reference? The lights really don’t need to reference the BP_DayNightCycle, they just need to know when to turn on/off.

Worth noting, as I’m using world partition, anytime a section of the map is loaded a light will need to know whether to set itself on or off.

The best option I can think of right now is to have another BP that has nothing in it other than the Event Dispatcher (so it’s super lightweight). I have my BP_DayNightCycle tell it via an interface function when to send it’s on/off event. Then my lights just reference this lightweight BP instead. I’m still not sure this will work with world partition yet though. But, I also want to see if there is a much more obvious (and better) way I should be looking at?

Thanks!!

An alternate approach might be to put a boolean or enum in GameInstance or any class that is normally reachable and may even already have a reference in all your agents (lights and daynight BP). The Daynight BP sets the variable and the light BPs query it. I’m not sure it would save much to do it that way other than the initial establishment of the references to the DayNightCycle blueprint.

Thanks for your response! The problem with a general bool is that I’d still have to have hundreds of lights constantly checking it for when it changes. Seems inefficient even if it is just a bool check.

I’ve found a number of event dispatcher alternatives that don’t use hard references on the Unreal Marketplace so may just give one of those a go, but just wondered if there was a simpler solution.

I agree. You would either have to have a delay event in each of the lights occasionally checking the variable, or if you use Tick for anything in the lights, a periodic check of the variable (not every frame of course). I’d be tempted just to use a delay event and have it fire infrequently (1 second or more).

Might also use an interface that the daynightcycle references and all of the lights implement such that the daynightcycle keeps the references and an implemented subroutine in each light turns them on and off.

It happens infrequently enough that it seems you could get by with iterating the world for the light actors and performing the on/off from the daynightcycle. I don’t think that would not be too inefficient considering it would only happen twice every “day” and on significant level location changes.

Thanks. Agreed, it’s very infrequent so could benefit from an interface call to all light actors. Might cause a stutter on that frame though if there’s a lot of them (although worst case I could batch them), but with world partition a lot of them won’t be loaded in memory so this might be fine. Thanks for your thoughts!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.