I can't use Delay within Functions as I designed. Now what?

Good evening ladies and gents.

I’m making a Space Shooter for a University assignment, I’m fairly new to Unreal.
I put a lot of work into planning the Design and Systems of this shooter prior to starting development as part of the University Course.

My initial Design was to have a GameController Actor that handles most systems in the game, like Score, Death, Spawning Enemies and the sort.
The problem I’ve encountered is within the Spawning Enemies Section.
Initially I wanted to have a SpawnEnemy function within the GameController that will take as input arrays of Enemies,
a float as a delay between spawning the enemies and a spline (which I use for movement) to assign to each enemy on Spawn.

This is what it looks like atm.

The idea is that I have multiple Enemy Types, like Enemy A, Enemy B, Enemy C.
I create an Enemy Group, like [ACBA] and
I assign the groups during the Construction Script of the GameController as well as a delay,
and the game controller will handle spawning each group automatically.

Problem is, that as I found out, I can’t use the Delay node inside a function,
so this really puts a wrench in my plans, since I need to space (hah, get it?) out the spawning of the enemies.

How would you guys go about fixing this? Is there some sort of workaround? I was pretty happy with the previous design,
but It doesn’t seem like it’s gonna work out. So I would really like some advice from some more experienced Unreal users.

Thanks alot for taking the time to read, any help is greatly appreciated!

You can turn your function into a custom event.

I might be mistaken, but all blueprint functions that do not have a return node are basically considered events anyways.

With it out in the event graph, you can use your delay node.

Another way if you are set on using functions is using a timer, but it might be more difficult to refactor your code to use a timer instead of a delay.

Yeah I considered using an event instead, but I assumed that calling functions is lighter for the game and much better.
And i’m gonna be using timers to set the time at which Enemy Waves spawn, but I wanted something that would give me more direct universal control over each enemy spawn especially when it comes to delay.
So I suppose I’ll make functions that call the EnemySpawn event after setting the enemy group, delay and spline to be used.

Does anybody know why Unreal doesn’t allow for delays within functions? My previous solution felt much more elegant, I guess I can work it out thanks to ToxinGaming over here.
But is there like a reason I’m missing?

Macros let you use a Delay. Could you use a Macro instead?

Put all the spawn code into a function then use a timer to call the function . SetTimerByFunctionName

You can do the exact same thing using a custom event with a delay node or even use a SetTimerByEvent function with the custom event (with looping checked and your SpawnInterval variable as the delay). You can’t use delay nodes in functions in UE4–my understanding for this is that functions can directly return variables while custom events can not, and delays would break that functionality if another function was dependent on a return variable.

Just use custom events when you need to use a delay in blueprints–it works fine and is by no means inefficient.

Ok! thanks for all your posts guys. You really helped clear some things up.
I’ll be using a Custom event. I guess I was kinda afraid of using one, since it felt like I was using a Go To command…
But apparently I was mistaken.
There’s no reason to not use a custom event, especially since I don’t need the Event to return me a variable in some way.