Trigger custom event on objects dynamically from Gamemode?

Hi!

I’m trying to get my blueprint communications sorted here, but I can’t for the life of me figure out how to achieve what I’m trying to do.

The two base concepts behind what I’m trying to achieve

  • I want things in the game to run on a specific interval (or multiples of that interval). That is, rather than running updates in the world every tick, I want to run them every 1/35th of a second. This is not a problem in itself, I have a working implementation. It does however require that every object placed or spawned implements the timer in their Event Tick.

  • I want to have most (if not all) of my map objects that aren’t map geometry to inherit most functionality from a master blueprint. I’m not gonna outline all functionality here, but two quick examples would be that the master has (amongst many others) two booleans, “Pickup” and “Floatbob”. If you check “Pickup” on the child blueprint, it implements the relevant behavior. If you toggle “Floatbob” for the child, the actor will float up and down in the air. Or for that matter, have a useless barrel map object, check a boolean for it being “Solid”, and have it do nothing else than being an obstacle.

The problem

The dealbreaker right now is that, essentially, every map object uses their own Event Tick to calculate (with the help of delta seconds) if a 1/35th cycle has occured and do stuff then. Sure, most modern computers could probably handle the load without problems, but it is still bad from an optimization perspective.

I eventually started wondering whether or not I could do this in the Gamemode’s Event Tick, and have it fire a custom event for any map object which “may care” so to speak. So, a map object with the “Floatbob” flag checked would care in order to sync its animation with the 1/35th cycle, however, the aforementioned barrel object wouldn’t recieve it… it doesn’t care. :stuck_out_tongue:

What should I do?

I’ve been looking at other questions, tutorials, etc., and it seems what I am looking for are Event Dispatchers. However, I am unclear on how I would be using them. Looking at the Content Examples (iirc, it was the Blueprints - Communication, 1.4) it uses the Get All Actors of Class function. Tying that up with the calculation in the Gamemode’s Event Tick would also seem expensive.

Is there any way to achieve what I’m trying to do? Could anyone walk me through the process?

One potential solution I’m looking at to alleviate the weight of “Get All Actors of Class” is to have each of the map object’s construction script (for preplaced objects) and spawn events (for objects spawned during play) add itself to an array in the Game Mode. Then use a foreach loop on the array to trigger a blueprint interface message. When the map object is destroyed, an event fires in the map object that removes itself from the array.

I.e., doing this in the gamemode’s graph, the loop body that triggers when a 1/35th cycle occurs:

http://i.imgur.com/RYPP1vo.png

Then, using the objects mentioned previously (the “Floatbobbing” one, and the useless barrel), the “Floatbobbing” object would add itself for the “MObjs Reacting to Game Tics” gamemode variable to have its animation synced with the 1/35th time), whilst the barrel would not at all bother adding itself.

That said, not the most elegant solution. Not gonna mark it as a best answer yet, as I am still looking for other solution. Do you have any better ideas?