Integrating Simple Build System with Multiplayer Survival Game Template

Assets required for integration

Before you begin, please read the following!

  • START BY BACKING UP YOUR PROJECT BEFORE MIGRATING, I take NO responsibility if You or Unreal Engine mess up the Migration/Integration process.
  • The Multiplayer Survival Template doesn’t have a default definition of Resources such as Wood or Stone, therefor, if you want to enable the feature of removing resources from the Player’s inventory, you’ll need to edit the Str_SGT_InventoryItem struct, I will cover this process in a separate tutorial, reason being, it can mess up A LOT of references to the struct & the DT_SGT_Items DataTable, making your entire project a nightmare to fix. DO NOT ATTEMPT THIS UNLESS YOU KNOW WHAT YOU’RE DOING
  • Begin by Migrating the Simple Building System to your MSGT Installation

  • Open up the SurvivalController Blueprint (/SGT/Blueprints/Game/SurvivalController)

  • Add the C-Building Component to the SurvivalController Blueprint

  • Select the C-Building component in the SurvivalController Blueprint (where you just added the Component), on the right hand side, in the Details panel, UNCHECK/Disable the “Enable Line Trace”

  • Copy the Events from (/BuildingSystem/Blueprints/BP_PlayerController) to your SurvivalController

  • In the SurvivalController Blueprint, add the Branch checks shown below, to make sure we’re not in Building mode when using the number keys.

  • Open the Manager-HUD component Blueprint, add a reference to the Building Component as Shown below

  • In the Manager-HUD Component, open the function “Update” and use the Reference you just created “Building Component” to call the function “CL Line Trace on Client”.

That’s it!

Step 2 of the Integration process can be found here:

How to edit Blueprint USTRUCTS() in Unreal Engine

Simple Build System Settings

Simple Build system Settings Explained.

  • Enable Permissions
    If you want to enable the Permissions system, otherwise the system will not check Ownership of buildings
  • Placement Offset
    This is an offset used for building placement, when you spawn the build actor into the world it will inherit this offset, there are also in game functions to adjust the Z value of this offset (up and down)
  • Enable Socket Placement
    If you want to enable the sockets placement system
  • Trace Frequency
    This is how often the LineTrace will run, increase this value if, for whatever reason, you run into performance issues
  • Max Building Distance
    How far the player can build away from the Player’s character (or view)
  • Min ZOffset
    Minimum Z offset you can lower the “Placement Offset” to.
  • Min ZOffset
    Maximum Z offset you can increase the “Placement Offset” to.
  • Enable Line Trace
    You can disable the built in LineTrace timer if you are using a different/your own line trace.
  • Collision Precision
    How precise do you want the collision check to be when placing down buildings (if colliding with another building)
    1.0 = 1:1 scale of the building mesh (lower number is less precise)

If you disable “Enable Line Trace”, be sure to call this event in your own Tick/Looping event/function. “CL_LineTraceOnClient

Simple Build System Adding a new Building

What you need before continuing:

  • You must have imported your building Mesh that you want to use

Make a Child Blueprint Class of “BP_Master_Building” and name it whatever you want.

Add a new Row to the DataTable “DT_Buildings”

Fill in the information

It should look something like this when done:

In the player controller, select the DataTable “Row Name”.

That’s it!

Dedicated Server Bug with Interactive Foliage

If you are using regular Listen servers, then this does not apply to you!

It has come to my attention that running the Foliage System on Dedicated Servers causes the server to crash.

Assertion failed: Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:Runtime/Core/Public\Containers/Array.h] [Line: 634]
Array index out of bounds: 3530 from an array of size 0

I have a simple solution for this, all you need to do is change a few lines of Engine code to fix it, this is because the Dedicated Server doesn’t consider the Instance array valid since they are not being rendered on the server.

Open up “C:\UnrealEngine\Engine\Source\Runtime\Engine\Private\HierarchicalInstancedStaticMesh.cpp”

Go to line 2394 (UE Source 4.17.2)

Inside the function UHierarchicalInstancedStaticMeshComponent::BuildTreeAsync()

 

Old code

const bool bMeshIsValid =
// make sure we have instances
PerInstanceSMData.Num() > 0 &&
// make sure we have an actual staticmesh
GetStaticMesh() &&
GetStaticMesh()->HasValidRenderData() &&
// You really can’t use hardware instancing on the consoles with multiple elements because they share the same index buffer.
// @todo: Level error or something to let LDs know this
1;//GetStaticMesh()->LODModels(0).Elements.Num() == 1;
}

New code

// Verify that the mesh is valid before using it.
bool bMeshIsValid =
// make sure we have instances
PerInstanceSMData.Num() > 0 &&
// make sure we have an actual staticmesh
GetStaticMesh() &&
GetStaticMesh()->HasValidRenderData() &&
// You really can’t use hardware instancing on the consoles with multiple elements because they share the same index buffer.
// @todo: Level error or something to let LDs know this
1;//GetStaticMesh()->LODModels(0).Elements.Num() == 1;

if (GetNetMode() == NM_DedicatedServer)
{
bMeshIsValid =
// make sure we have instances
PerInstanceSMData.Num() > 0 &&
// make sure we have an actual staticmesh
GetStaticMesh() &&
// You really can’t use hardware instancing on the consoles with multiple elements because they share the same index buffer.
// @todo: Level error or something to let LDs know this
1;
}