Skip to content
Bannerlord Wiki
Share
Explore
Tutorials

Replace GameModel Objects

Credit goes to
Replacement Code for GameModels
protected void ReplaceModel<TBaseType, TChildType>(IGameStarter gameStarterObject)
where TBaseType : GameModel // Defining the Types of those Anything
where TChildType : TBaseType
{
// Checking if List of GameModels
if (!(gameStarterObject.Models is IList<GameModel> models)) // Is defining models this way!
{
return;
}


// Debounce
bool found = false;
for (int index = 0; index < models.Count; ++index) //Iteration
{
if (models[index] is TBaseType) // If TBaseType is found
{
found = true; //Sets debounce to true
if (models[index] is TChildType) // Checks if Child object
{
}
else
{
models[index] = Activator.CreateInstance<TChildType>(); //Creates an Instance of TChildType
// and sets it to the index
}
}
}


if (!found) // Checks if item wasn't found
{
gameStarterObject.AddModel(Activator.CreateInstance<TChildType>());
// Adds model to gameStarterObject
}


}


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.