Create a Melee Weapon
This how-to will show you how to create your first Melee Weapon and assign it to the default Weapon Manager.
Create your Sword Weapon actor
Create a new Actor extending from
NinjaCombatWeaponActor
and name itBP_Weapon_Sword
.Add
Inventory.Item.Type.Sword
to the Weapon Tags container.Create a Static Mesh Component and set the mesh for your Weapon.
Set the Weapon Collision to Overlap All, since the system uses traces to scan for targets.
Add the
Combat.Component.MeleeScanSource
tag to your Static Mesh Component, so the Weapon Actor will be able to find the Weapon Mesh.
Create your Shield Weapon actor
Create a new Actor extending from
NinjaCombatWeaponActor
and name itBP_Weapon_Shield
.Add
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 Weapon Manager
Implement the Combat System Interface along with the
GetCombatMesh
andGetWeaponManager
functions.In the Components tab, search for
weapon
and select the Ninja Combat Weapon Manager component.In the Class Settings view, add the Combat System Interface.
In the Blueprints tab, expand the Combat System Interface and double-click
Get Weapon Manager Component
. Implement it returning the Weapon Manager.Still in the Blueprints tab, double-click
Get Combat Mesh
. Implement it returning the main Character Mesh for your Blueprint.Add
CombatSystemInterface
to your header and create a pointer to the Weapon Manager.Override the
GetCombatMesh
andGetWeaponManagerComponent
functions.#pragma once #include "CoreMinimal.h" #include "GameFramework/Character.h" #include "Interfaces/CombatSystemInterface.h" #include "PluginLabsCharacter.generated.h" class UNinjaCombatWeaponManagerComponent; UCLASS() class PLUGINLABS_API APluginLabsCharacter : public ACharacter, public ICombatSystemInterface { GENERATED_BODY() public: APluginLabsCharacter(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get()); // -- Begin Combat System Implementation. virtual USkeletalMeshComponent* GetCombatMesh_Implementation() const override; virtual UActorComponent* GetWeaponManagerComponent_Implementation() const override; // -- End Combat System Implementation. private: /** Main character mesh following the hidden mannequin for animations. */ UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Components", meta = (AllowPrivateAccess = true)) TObjectPtr<USkeletalMeshComponent> LeaderMesh; /** Weapon Manager component that will manage weapons for this character. */ UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Components", meta = (AllowPrivateAccess = true)) TObjectPtr<UNinjaCombatWeaponManagerComponent> WeaponManager; };Initialize the Weapon Manager instance and return it from the appropriate function. Do the same for the Character Mesh.
#include "GameFramework/PluginLabsCharacter.h" #include "Components/NinjaCombatWeaponManagerComponent.h" APluginLabsCharacter::APluginLabsCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { static const FName LeaderMeshName = TEXT("LeaderMesh"); LeaderMesh = CreateDefaultSubobject<USkeletalMeshComponent>(LeaderMeshName); // ... static const FName WeaponManagerName = TEXT("WeaponManager"); WeaponManager = CreateDefaultSubobject<UNinjaCombatWeaponManagerComponent>(WeaponManagerName); } USkeletalMeshComponent* APluginLabsCharacter::GetCombatMesh_Implementation() const { return LeaderMesh; } UActorComponent* APluginLabsCharacter::GetWeaponManagerComponent_Implementation() const { return WeaponManager; }Add your weapons to the Weapon Manager's Details Tab and configure them to the correct sockets in your Character's Mesh Skeleton.
Check the Weapon Manager configuration
Click the Play button.
Your character should start with the both weapons attached to the correct sockets.