Bannerlord 2

3 Advanced Bannerlord 2 Modding Guides & Tutorials

Modding Mount & Blade II: Bannerlord opens up a world of possibilities, allowing you to tailor the game to your exact preferences. While basic modding is well-documented, diving into more advanced techniques can seem daunting. This article addresses three key areas where aspiring modders often encounter challenges: complex dependency management, advanced scene editing, and custom AI behavior implementation. These are areas where existing tutorials often fall short, leaving ambitious modders struggling.

Understanding and managing dependencies is crucial for creating stable and compatible mods. Poorly managed dependencies are the number one cause of crashes and conflicts in Bannerlord mods. Many beginners simply copy files and folders without understanding the underlying structure, leading to a tangled mess that’s difficult to debug.

Versioning and Manifest Files: The Foundation

The first step is to understand versioning. Bannerlord uses a specific versioning system, and your mod needs to adhere to it. The file (the mod’s manifest) is where you declare your dependencies and their required versions. Don’t just guess; use the exact version numbers of the modules your mod relies on.

3 Advanced Bannerlord 2 Modding Guides & Tutorials

means your mod requires these modules to function. If you want to add compatibility (where your mod works with another mod, but doesn’t require it), set . This allows players to use your mod even if the optional dependency isn’t present. However, you’ll need to add checks in your code to ensure features dependent on the optional module don’t break if it’s missing. This technique is crucial for broad compatibility and reduces the likelihood of game crashes for users with different mod configurations.

Runtime Dependency Injection with Harmony

Harmony (a .NET patching library https://harmony.pardeike.net/) is a powerful tool for modifying game behavior without directly altering the core game files. This is invaluable for avoiding conflicts with other mods.

My personal experience has shown that using Harmony for dependency injection is far more robust than relying solely on declarations. I once spent days debugging a crash caused by a conflicting transpiler from another mod. Switching to Harmony-based checks resolved the issue immediately.

Consider this scenario: you want to add a new dialogue option when interacting with a lord, but only if a specific mod (e.g., a diplomacy mod) is loaded. Instead of directly patching the dialogue system, you can use Harmony to check if the dependency mod’s assembly is loaded and only inject your dialogue option if it is.

csharp
using HarmonyLib;
using System.Reflection;

namespace MyMod
{
public class MyPatches
{
public static void Apply(Harmony harmony)
{
// Check if the diplomacy mod assembly is loaded
Assembly diplomacyAssembly = Assembly.Load(); // Replace with the actual assembly name

}
}

This code snippet demonstrates how to conditionally apply patches based on the presence of another mod. This approach significantly reduces the risk of conflicts and improves compatibility across a wider range of mod setups. Remember to replace with the actual assembly name of the dependency mod.

Practical Example: Resolving Conflicts with Overlapping Patches

One of the trickiest dependency issues arises when multiple mods attempt to patch the same game method. Here’s a structured approach to resolving such conflicts:

StepActionDescription
1Identify Conflicting PatchesUse Harmony’s logging to trace the execution order of patches and identify which mods are patching the same methods.
2Adjust Patch OrderUtilize Harmony’s attribute to control the order in which patches are applied. Higher priority patches are applied first.
3Conditional PatchingImplement checks within your patches to ensure they only execute under specific conditions, avoiding overlap with other mods’ logic.
4CollaborationReach out to the authors of conflicting mods to discuss potential solutions and collaborate on a shared patch.

The Bannerlord scene editor is powerful, but its interface can be clunky and unintuitive. Moving beyond the basic Module System requires understanding the underlying scene format and leveraging external tools.

Working with Blender and the BRF Format

Bannerlord uses the BRF (Bannerlord Resource File) format for storing scene data. While you can edit scenes directly within the Bannerlord editor, using a 3D modeling program like Blender allows for far greater precision and control.

First, you’ll need the BRF import/export plugin for Blender. These are often available on modding forums. Install the plugin, then import the BRF file of the scene you want to modify. Make your changes in Blender (adding objects, adjusting terrain, etc.), and then export the scene back to BRF format.

Remember to pay close attention to the scaling and coordinate system when working between Blender and the Bannerlord scene editor. Discrepancies can lead to objects appearing in the wrong location or being the wrong size. I often create a simple reference object in Bannerlord, export it to Blender, and then use it as a guide to ensure my scales are correct.

Optimizing Scene Performance

Detailed scenes can significantly impact performance. Here are a few techniques for optimization:

  • Level of Detail (LOD) Models: Create lower-poly versions of your models that are displayed when the player is further away. This significantly reduces the rendering load.
  • Occlusion Culling: Block off areas that are not visible from certain viewpoints. The game won’t render these hidden areas, improving performance.
  • Texture Optimization: Use compressed textures and minimize the number of different textures used in your scene.
  • Static vs. Dynamic Objects: Mark objects that don’t move as static. This allows the game to optimize rendering for these objects.

Using the NavMesh Effectively

The NavMesh is a crucial component of any scene where NPCs need to move around. It defines the walkable areas and allows the AI to navigate the scene effectively. A poorly configured NavMesh can lead to NPCs getting stuck, taking illogical routes, or simply standing still.

You can edit the NavMesh directly in the Bannerlord scene editor. Ensure that the NavMesh covers all walkable areas and that there are no gaps or discontinuities. You can also create separate NavMesh areas with different properties (e.g., a “combat zone” with higher NPC density). Experiment with different NavMesh settings to find the optimal balance between NPC movement and performance.

Beyond simple patrol routes, creating compelling AI behavior requires understanding Bannerlord‘s AI system and using its tools effectively.

Behavior Trees and Blackboard Systems

Bannerlord uses a behavior tree system for controlling NPC actions. A behavior tree is a hierarchical structure that defines the decision-making process of an AI agent. Each node in the tree represents a specific action or condition.

The blackboard system is a shared memory space that allows different parts of the behavior tree to communicate with each other. This is where the AI stores information about the environment, the player, and its own internal state.

Understanding these concepts is crucial for creating complex AI behaviors. Start by examining the existing behavior trees in the game files. This will give you a sense of how they are structured and how they interact with the blackboard system.

Creating Custom AI Tasks

You can create your own custom AI tasks to implement specific behaviors. These tasks can range from simple actions (e.g., playing an animation) to complex decision-making processes (e.g., choosing the best target to attack).

To create a custom AI task, you’ll need to inherit from the class and override its method. This method is called every frame, and it’s where you’ll implement the logic for your task. You’ll also need to define the input and output parameters for your task, which will allow it to communicate with other parts of the behavior tree.

For example, you could create an AI task that causes an NPC to flee when their health is low. This task would check the NPC’s health, and if it falls below a certain threshold, it would set the “flee” flag on the blackboard. Another task would then be responsible for actually moving the NPC away from danger.

Using Factions and Relationships

Bannerlord‘s faction and relationship systems offer powerful tools for influencing AI behavior. You can create custom factions with unique traits and behaviors, and you can use relationships to define how different NPCs interact with each other.

For example, you could create a faction of bandits who are hostile towards all other factions. You could then create a relationship between these bandits and the player, making them more likely to attack the player on sight.

By combining behavior trees, custom AI tasks, and the faction/relationship systems, you can create truly unique and engaging AI behaviors. This is where Bannerlord modding truly shines.

In conclusion, mastering complex dependency management, advanced scene editing, and custom AI behavior implementation opens up possibilities for creating truly transformative mods for Bannerlord 2. These three areas often challenge aspiring modders, but by understanding the underlying principles and applying the techniques described above, you can overcome these hurdles and bring your vision to life.

json { "@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [ { "@type": "Question", "name": "How do I manage dependencies in Bannerlord 2 mods effectively?", "acceptedAnswer": { "@type": "Answer", "text": "Effectively managing dependencies involves using the correct versioning in the file, employing Harmony for runtime dependency injection, and resolving conflicts by adjusting patch orders and collaborating with other mod authors." } }, { "@type": "Question", "name": "What is the BRF format and how can I use it in Bannerlord 2 scene editing?", "acceptedAnswer": { "@type": "Answer", "text": "The BRF (Bannerlord Resource File) format stores scene data. You can use Blender with a BRF import/export plugin to edit scenes with greater precision, ensuring correct scaling and coordinate systems. Optimize scene performance with LOD models, occlusion culling, and texture optimization." } }, { "@type": "Question", "name": "How can I implement custom AI behavior in Bannerlord 2?", "acceptedAnswer": { "@type": "Answer", "text": "Implement custom AI behavior by understanding behavior trees and blackboard systems. Create custom AI tasks by inheriting from the class and using factions and relationships to influence NPC interactions. This allows for complex and engaging AI." } }, { "@type": "Question", "name": "Why does my Bannerlord mod crash when another mod is installed?", "acceptedAnswer": { "@type": "Answer", "text": "This is often due to conflicting dependencies or overlapping patches. Ensure your accurately declares dependencies, use Harmony for runtime dependency injection, and adjust patch priorities to avoid conflicts." } }, { "@type": "Question", "name": "How can I improve the performance of my custom Bannerlord scenes?", "acceptedAnswer": { "@type": "Answer", "text": "Improve scene performance by using Level of Detail (LOD) models, enabling occlusion culling, optimizing textures, and marking static objects as static. Proper NavMesh configuration also helps with NPC navigation and performance." } } ] }