Module Mounts

Module Mounts are places on a vehicle where modules are mounted onto a vehicle. A vehicle can have any number of Module Mounts.

Any number of modules can be added to a module mount, but only one may be mounted at any time. This means that you can add multiple modules to a single mount, and cycle between them during game play.

Creating A Module Mount

To create a module mount on a vehicle, add a new game object as a child of the vehicle, rename it to something relevant, and add a Module Mount component. Set the local position and rotation according to how you would like the module to be oriented when it is added to the vehicle.

Specifying Mountable Types

Let's say you want to add a module mount to a vehicle that can only be used to load gun weapons.

  1. Create a Module Type for gun weapons.

  2. Drag the Module Type you created in step 1 into the Mountable Types list in the inspector of the Module Mount component.

  3. Make sure all the gun weapon modules have their 'Module Type' set to the Module Type you created, in the inspector of their Module components.

Adding Module Prefabs

Let's say you have some module prefabs that you've created, and you want them all to be added to a module mount.

Drag all the prefabs to the Default Module Prefabs list in the inspector of the Module Mount component, and they will be created there when the scene starts.

Cycling Modules at a Module Mount

  1. Go to the Player and add a PlayerInput_InputSystem_ModuleMountControls component in its hierarchy.

  2. Go to the Module Mount you want to control and make sure its ID is the same as the 'Module Mount ID' value in the inspector of the PlayerInput_InputSystem_ModuleMountControls component from step 1.

  3. Now play the game. You can cycle forward and back through the modules at that module mount, when the player is controlling that vehicle. Open the General Input System asset to see/modify the inputs.

Alternatively, if you'd like to cycle modules at a module mount in our own code, use this code:

// Mount the next module
myModuleMount.Cycle(true);

// Mount the previous module
myModuleMount.Cycle(false);

Checking Module Compatibility

To check if a module is compatible with a module mount in code, use the following code:

// Check if a module is compatible with the module mount
if (myModuleMount.IsCompatible(someModule))
{
    // Some code
}

Adding/Removing Modules

A module is added to a module mount when it is placed there and ready to be mounted. But a module that is added still needs to be mounted - remember that while many modules can be added to a module mount, only one of them can be mounted.

To add or remove modules from a module mount during game play, use the following code:

// Add a module
myModuleMount.AddModule(someModule);

// Remove a module
myModuleMount.RemoveModule(someModule);

// Remove all modules from the module mount
myModuleMount.RemoveAllModules();

Accessing Added Modules

To access the modules added to a module mount, you can access the Modules list from a reference to the Module Mount component with the following code:

// Get a list of modules at a module mount
List<Module> modules = myModuleMount.Modules;

Mounting/Unmounting Modules

To mount the first module that is added to the module mount when the scene starts, check the Mount First Available Module At Start checkbox in the inspector of the Module Mount component.

To mount or unmount modules during game play, use the following code:

// Mount a module by direct module reference
myModuleMount.MountModule(someModule);

// Mount a module by the module's ID (string)
myModuleMount.MountModule(someModuleID);

// Mount a module by its index in the Modules list (int)
myModuleMount.MountModule(someIndex);

// Unmount the currently mounted module
myModuleMount.UnmountActiveModule();

Accessing The Currently Mounted Module

To access the module that is currently mounted at a module mount, use the following code:

// Get the currently mounted module - if none mounted, the result will be null
Module mountedModule = myModuleMount.MountedModule();

Last updated