A Coding Perspective on Requested Features in Hitman (Eg. Ghost Mode Music)

Some disclaimers:

  1. I do not claim to be an expert in coding and none of this code has been officially tested and/or optimised. If anyone has suggestions for more optimised or better solutions, please let me know.

  2. All code here is written in C# for Unity. Code may look different for whatever language IO uses.

  3. For code that require a cloud database or some sort of connection to steam, I’ll be using example/placeholder functions as I am in no way experienced with using steam plugins.


I wanted to show how difficult some requested features are to implement in Hitman by giving some examples in coding. If you have a requested feature you want to see here, or you have more optimised code, please tell me so.


**READ FIRST** Music in Ghost Mode

Music in Ghost Mode

This seems pretty easy to implement right? A lot of people glance at this feature at first and think it would be easy: it’s just music right? But a lot more is actually needed just to play a soundtrack.

1:
In order to play the Audio, some object will have to be in the scene that can play the Audio. In Unity, we use AudioSources to play AudioClips.

One solution is to have an empty GameObject with the AudioSource script on it and trigger it via a script if a boolean is set to true.

public bool GMMusic = true/false;
private AudioSource musicSource;
...
if (GMMusic == true) {
musicSource.Play();
}


2:
You can optimise the code by finding the GameObject the first frame update of the scene.

void Start() {
musicSource = GameObject.Find("musicSource");
}
if (GMMusic == true) {
musicSource.Play();
}

This adds an instant at the start of the scene, removing the need to apply it in the editor.


3:
You can be even more efficient by instantiating the GameObject if the player has music turned on.

void Start() {
if (GMMusic == true) {
musicSource = Instantiate(Resources.Load("/Prefabs/musicSource", typeof GameObject), new Vector3(0, 0, 0), Quaternion.identity);
musicSource.Play();
}
}


Taking the GMMusic boolean into account, this will need to either be kept in a PlayerPrefs file or in the Steam cloud. For convenience sake, I’ll be using the Steam cloud, but also because this allows all PCs signed into the account to save this setting. whereas PlayerPrefs is stored locally on one computer.

First, let’s create the boolean.

public bool GMMusic = true/false;

Then, we’ll get the value of GMMusic from the Steam Cloud database (example function, not used in real code).

GMMusic = Steam.GetBoolFromCloud("GhostModeMusic");

Whenever we change this with a UI Button (OnClickEvent()), we can simply update the Cloud.

void OnClickEvent() {
if (GMMusic)
GMMusic = false;
Steam.UploadToCloud(GMMusic, "GhostModeMusic");
} else {
GMMusic = true;
Steam.UploadToCloud(GMMusic, "GhostModeMusic");
}


And that’s all! Hopefully that gives an insight into how complicated certain features are! Feel free to look at the others as well.


I’ll be adding more features in the future.

2 Likes

Well, this probably gives an insight into the work of IO Interactive. although…

…yet this is really cool.

1 Like

Tbh code will always look semi-similar no matter what language you’re using because the code will have the same information and requirements. It might just be written in a different way because of how the language works or detects certain code.

A lot of programmers learn languages other than their first easily because it’s relatively the same thing but written differently.

But yeah, just playing music is already really complex, I couldn’t imagine having to edit AI systems in order to match the NPCs. Especially in Mumbai where every character gets new accents and new voices, everything would’ve been changed.

So don’t take IO for granted, huehuehue

I stopped reading after “This seems pretty easy to implement right?”, because there already was music in Ghost mode from the November launch to Apr 30, it was already done, dude :sweat_smile:

4 Likes

Yeah, it was just to give an insight on how much work is actually needed, but thanks for the info, I didn’t know it was actually in the game at some point :hugs: