Firing event randomly - problem

Hi there,

Fairly new to BP scripting but just when I think I’m getting somewhere, I get stuck!
I am trying to do a fairly simple thing - to make a random sound (from a possible 3) fire on a random timed trigger.

tried many things but the example I am posting is after a fair bit of time has passed and I’ve gotten more and more convoluted, so apologies for the no doubt awful logic!

In summary, I am firing a custom event on Begin Play that runs a function. That function has a timer in it that fires randomly between 1 and 5 seconds (for testing). I can see at runtime that this happens, but in-game the event only fire once (plays one sound, once) and then not again, despite the function appearing to fire internally over and over correctly.

Can somebody tell me what I’m dong wrong and perhaps post a fix of my current logic or show me a simpler way of doing what I want to do please? Don’t get too complex without visual aids because I’m not mega experienced as yet and it’ll go over my head - probably :slight_smile:

Thanks!

i think the problem youre having is that youre using event begin play, so it will function how you want to Once at the beginning of your game, and thats it. I would use event tick(which is similar to the update function in unity) and use a delay node that goes between 1 and five seconds. Im not quite sure exactly how to lay that out but i hope that helps

Ok for starters BeginPlay only fires ONCE when the map has loaded and gameplay has begun.

So you should put your random sound logic in a FUNCTION then fire that off with a SetTimer.

So connection should be BeginPlay-> SetTimer (Function->yourfunction/ Timer-> your choice or random/ Looping-> checked)

Hmm, I thought that’s what I’d done?
I have the Function fire once, then inside that it is the timer which keeps firing (and i watch it keep firing every x seconds (randomised). The problem is, that function doesn’t seem to actually kick out a pulse re-firing the audio in the next leg of its journey - except for the first time.

Maybe the timer goes before the function. I’ll check it/
thx

Okay putting the random sound stuff in the function, with a timer before that worked nicely. thanks man

Great please mark as solved so other users will know