Create Melee Weapons
After configuring the initial Combat Components, the first step in Ninja Combat is to prepare your character for Melee Attacks using a Melee Weapon, which must be registered with the Weapon Manager.
Create a sword
Create a new Actor extending from
NinjaCombatWeaponActor
. This will be our sword.Set
Inventory.Item.Type.Sword
to the Weapon Tags container.Add a Static Mesh to this Actor, set your sword mesh to it, and add the Component Tag
Combat.Component.MeleeScanSource
.Set the mesh's collision to Overlap All. The system uses traces to collect targets, and we do not want the weapon colliding with other objects.
Create a shield
Create a new Actor extending from
NinjaCombatWeaponActor
, or from your base Blueprint. This will be our shield.Set
Inventory.Item.Type.Shield
to the Weapon Tags container.Repeat the same steps as before, setting the Weapon Collision and tagging the Static Mesh Component.
Configure the Combat Components
In your Player Character, add the Combat Manager Component, Weapon Manager Component and implement the Combat System Interface.
In the Components tab, search for
combat manager
and select the Ninja Combat Manager component.In the Components tab, search for
weapon manager
and select the Ninja Combat Weapon Manager component.In the Class Settings view, add the Combat System Interface.
In the My Blueprint tab, under Interfaces, expand the Combat System Interface:
Double-click
GetCombatManagerComponent
and return the Combat Manager component.Double-click
GetWeaponManagerComponent
and return the Weapon Manager component.Double-click
GetCombatMesh
and return the Character Mesh.
Add
CombatSystemInterface
to your Player Character class.Create an instance of
UNinjaCombatManagerComponent
and return it fromGetCombatManager_Implementation
Create an instance of
UNinjaCombatWeaponManagerComponent
and return it fromGetWeaponManagerComponent_Implementation
Return the character's mesh from
GetCombatMesh_Implementation
#pragma once #include "CoreMinimal.h" #include "GameFramework/Character.h" #include "Interfaces/CombatSystemInterface.h" #include "PluginLabsCharacter.generated.h" class UNinjaCombatManagerComponent; class UNinjaCombatWeaponManagerComponent; UCLASS() class PLUGINLABS_API APluginLabsCharacter : public ANinjaGASPlayerCharacter, public ICombatSystemInterface { GENERATED_BODY() public: APluginLabsCharacter(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get()); // -- Begin Combat System Implementation. virtual USkeletalMeshComponent* GetCombatMesh_Implementation() const override; virtual UNinjaCombatManagerComponent* GetCombatManagerComponent_Implementation() const override; virtual UActorComponent* GetWeaponManagerComponent_Implementation() const override; // -- End Combat System Implementation. private: /** Main Manager for the Combat System. */ UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Components", meta = (AllowPrivateAccess = true)) TObjectPtr<UNinjaCombatManagerComponent> CombatManager; /** Weapon Manager component that will manage weapons for this character. */ UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Components", meta = (AllowPrivateAccess = true)) TObjectPtr<UNinjaCombatWeaponManagerComponent> WeaponManager; };#include "GameFramework/PluginLabsCharacter.h" #include "Components/NinjaCombatManagerComponent.h" #include "Components/NinjaCombatWeaponManagerComponent.h" APluginLabsCharacter::APluginLabsCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { static const FName CombatManagerName = TEXT("CombatManager"); CombatManager = CreateDefaultSubobject<UNinjaCombatManagerComponent>(CombatManagerName); static const FName WeaponManagerName = TEXT("WeaponManager"); WeaponManager = CreateDefaultSubobject<UNinjaCombatWeaponManagerComponent>(WeaponManagerName); } USkeletalMeshComponent* APluginLabsCharacter::GetCombatMesh_Implementation() const { return GetMesh(); } UNinjaCombatManagerComponent* APluginLabsCharacter::GetCombatManager_Implementation() const { return CombatManager; } UActorComponent* APluginLabsCharacter::GetWeaponManagerComponent_Implementation() const { return WeaponManager; }
Configure the Weapon Manager
Open your character's Skeleton and add sockets for the sword and shield.
Add your weapons to the Weapon Manager's Details Tab and configure them to the appropriate sockets in your Character's Mesh Skeleton.
Test everything
Press play, you should see your Player Character, as usual.
Your character should have a sword and a shield attacked to the correct sockets.