-
Notifications
You must be signed in to change notification settings - Fork 2
ScenePatcher
Nathan Gill edited this page Sep 4, 2020
·
1 revision
Scene patchers are a special class that allows you to patch any scene (vanilla or modded) after it's been loaded. Useful for making quick modifications to existing scenes without needing to create an entirely new map.
Creating one of these is really simple. Make a new class anywhere in your project and have it derive from the ScenePatcher
class.
You'll also have to stick the ScenePatcher
attribute on it and give it the name of the scene you want to patch.
Lastly, override the PatchScene(Scene)
method and fill in your code.
That's it! WurstMod will automatically discover and apply your patches as long as your assembly is loaded.
Example:
// This line takes the scene name. It has to match exactly what's used in the game's code or else it won't work.
// In this case we're going to patch the main menu, it's code name is 'MainMenu3'
[ScenePatcher("MainMenu3")]
public class MainMenuScenePatcher : ScenePatcher
{
public override void PatchScene(Scene loaded)
{
// When a scene is loaded which matches the name written above, this function will be called!
// You can do whatever you want here. We're just going to find an object called 'FooBar' and delete it
foreach (var root in loaded.GetRootGameObjects())
{
var obj = root.transform.Find("FooBar");
if (obj == null) continue;
UnityEngine.Object.Destroy(obj);
break;
}
}
}
Quick Start
Step-by-step Mapping Guides
- Setting up your environment
- Creating your first map
- Creating custom scripts
- Creating in-game menus
Mapping References