Shooter Game (Find game load and game update)

Hello everyone! I downloaded the Shooter Game example and I’m doing a sound replacement for it. I’m using a middleware software called Wwise and I want to implement all the audio in C++, but I have a few questions:

1- Wwise has a series of modules (SoundEngine, communications, memory manager, … ) that need to be initialized/terminated when the game loads/ends. I’ve been looking at the source and header files contained in this project and I’m having a tough time figuring out where the game loading/unloading is taking place. I saw some lines of code in the ShooterGameInstance.h related to start game session, init and shutdown. Would the corresponding .cpp file be a good place to initialize the soundengine modules?

2- The soundengine needs to be updated every frame at least, so that audio plays when it’s called in code, and other things. I need to find the place where game update is taking place and add the soundengine render function there. I’m essentialy looking for a place that has something related to the main game loop. Can anyone point me in the right direction?

3- How can I know which map is being loaded?

Thank you!

Hi! steinmann.

wwise has already integrated in UE4.10 by audiokinetic clone repo and build engine:

Hello! That’s not the problem. I have the integration done, but to use Wwise in a project I need to initialize its various modules in the C++ code (In the right places) and my question is about that. Would you know anything about that? Cheers!

I haven’t used Wwise, so take this with a grain of salt. Not knowing how wwise works in a multiplayer environment it is difficult to say if you want it to be ran on the server or the client, or to what extent as a combination of the two. If it does what I think it does (generate sounds that have a source and you can hear the direction), it needs some replication, but because I don’t know how it really works, you need to really think carefully how you implement it in multiplayer. As other players’ location is already replicated for you by the code, this might be enough so you might not need to replicate any of the sound generation elements.

Anyway, some answers regarding shootergame:

  1. ShooterGameInstance is not replicated (which is good for loading I’d say). If you place it here, it will be loaded separately for each client and the server. You can stop your modules loading on the server/clients by checking the authority flag (ShooterGame by default has a listen instead of a dedicated server, so the player playing on listen server wouldn’t have the sounds if you only load it for clients). ShooterGameInstance does all the state changes for the game and is present from start to finish. The Wwise documentation is fairly lacking for a non-registered customer, so I don’t know how the loading of these modules happens. Do you have to put in functions to initiate them or are they separate plugins that you need to load with the build? If they are the latter, you might need to load them in ShooterGame.Build.cs, but I don’t have any experience on that so you need to research it a bit.

  2. So you want a tick. Ticks are ran each frame. Again without knowing how Wwise works, I really have no absolute answers on where to put it. There is really no “main game loop” in the game, but a lot of ticks that run each frame and make the game function. ShooterGameInstance’s tick manages the game state, so that might be a place you want to check, in addition to the ShooterCharacter (this would mean when you die and unpossess your character, sounds would stop unless you did the same stuff for Spectator Pawn) and ShooterPlayerController (there are two controllers for the shootergame, one for menu and one for the game so you can have different setups for each). It is also possible to do some of the functions in a level blueprint (such as background audio) and only do footsteps and “kinetic” audio in c++ side (this method would suggest going with the controller). I can’t think of any good ticks in addition to these three, but there might be something I’m not familiar with, although I’ve been dabbling with ShooterGame modification quite a bit.

  3. GetWorld()->GetName() will return current level’s name.

Sorry, no :expressionless:

But I will try if give more information, example for you task.

Add like for you quastion +5

Thanks a lot for your detailed reply. As it turns out, when UE4 is built from source, including Wwise as a plugin, when a new project is created the sound modules from Wwise are already being initialized, without the necessity of adding that code. So I’m good there and everything is initialized.

I read that the game instance is always created, even when not running the actual game in standalone. The documentation says that it is also created when testing in PIE. I profiled the game in the Wwise application and everything seems to be working, however I’m not getting any sound yet. I wonder if my shooter game instance is really being created.

Do you know how I can debug this in C++? I would like to see if some lines of code are actually being executed. Is it possible to print this stuff to the editor when PIE?

You mean print a debug message on screen or to output log? Easiest is to add the following line to your code to see if your functions even run:

GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, “debug msg”);

You can check also Rama’s debug guide for other types of debugging (including onscreen messages that display variable values etc.):

For multiplayer debugging this might be a no brainer for you, but I’ll still write it:
With a multiplayer game, it’s best to always test as multiplayer - ie, put number of players to two and also run a test with the dedicated server ticked. I’ve found that most of my stuff usually works on either server or client, and about 50% of my issues that I’ve encountered with Shootergame has been me not doing replication correctly or not understanding who runs which code.