I’m using the first person template in C++.
I used to put the call to play sound in the projectile class, but it would get destroyed before it would play the sound.
I put a check for if the sound was playing before the call to destroy and that worked. I can hear the sound but the projectile sits around until it disappears.
I could use flags and override the Tick function. I’m not comfortable with that because it might slow down the projectile.
I would rather use message passing instead, something like delegate or events. It would be more flexible. Also the playing of the sound is not tied to the existence of the projectile.
My questions are:
- Where do I load the sounds so the sound handler class can use them?
Can I do it inside a gameinstance, or it needs to be done with something derived from AActor? I used a gameinstance because it lasts for the life of the game.
The sounds are loaded in a blueprint for the projectile.
I tried doing the loading in a gameinstance class, but I don’t think that worked because I got nullptr error when it was time to play the sound.
- How to do the messages/events - I can research that, but if you have suggestions, I’ll check them out.
If you need to see code, I’ll provide it. I wasn’t sure what code to show.
Thanks in advance.