Wobbly Life Mod SDK
 
Loading...
Searching...
No Matches
Custom Player Controller Example

Custom ModPlayerController/ModPlayerCharacter

Note: Everything mentioned here is the same for PlayerCharacter.cs

The ModPlayerController.cs is the unique identifer for a player who joins your game. It is sometimes useful to have custom ModPlayerController if you wanted to do something unique. For example in the Trash Zone/Hide and Seek example we have made a custom ModPlayerController.cs so that we can easily show/hide UI and to do other unique things like identifying who is the Seeker/Trasher.

Step 1: Creating the custom controller script

In your mod directory, you will want to create a script for your custom ModPlayerController. In this case I'm going to call it CustomPlayerController.

Now open that script, I will be using Visual Studio. I assume you have a decent understanding on how C# works. But in short all you need to do is derive from ModPlayerController.cs

Like so

using ModWobblyLife;
public class CustomPlayerController : ModPlayerController
{
protected override void ModReady()
{
base.ModReady();
// This is where you should write your initalize code
}
}

Note: Any initalize code should go directly into ModReady

Step 2: Creating and assigning the prefab

In order to use this new CustomPlayerController you will need to create a prefab with it.

To do so, in the scene create a GameObject, you can call this GameObject whatever you like but to keep things neat I usually call it the name of the script for example CustomPlayerController

Then you just need to make it a prefab by dragging into you mod directory like so Note: You should probably make a new folder called Prefabs to keep things neat

Once you have the prefab you will need to register it with the network manager.

The reason why you need to do this is because ModPlayerController.cs is a ModNetworkBehaviour.cs meaning that you can send network data to other players using it and the only way that other players know about it is if you register it with the ModNetworkManager.cs

So lets do this.

If you don't already have a ModNetworkManager, create a GameObject call it "NetworkManager" and add the script ModNetworkManager.cs on it.

You can then drag your newely create custom player controller prefab into the NetworkManager (Under Registered Behaviours)

Assigning it to the gamemode

In order for the game to know which ModPlayerController.cs you want to use, you will need to tell it.

If you don't have a gamemode object in your scene I highly suggest looking at \creatingmodpage

Click on your gamemode and then assign the custom player controller prefab into the slot which says ModPlayerController.

Like so.

That's all, give that a test and all should work.