Hi,
I tried to add a weapon to my character in C++.
Now I’ve added 2 weapons as simple mesh linked to a socket, and it moves with the character. Great.
But now I want to create a weapon.h and weapon.cpp, and add it to my player.
Today I have this files, and I’ve added the file into the blueprint of my character.
In the viewport, the weapon is showing vertically. But it wont be added nor visible in game.
so, this is my baseweapon.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "Engine/StaticMeshActor.h"
#include "BaseWeapon.generated.h"
/**
*
*/
UCLASS()
class MYPROJECT2_API ABaseWeapon : public AStaticMeshActor
{
GENERATED_BODY()
UStaticMeshComponent* mStaticMeshComponent;
UStaticMesh* mStaticMesh;
ABaseWeapon();
};
and my baseweapon.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyProject2.h"
#include "BaseWeapon.h"
ABaseWeapon::ABaseWeapon()
{
mStaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseWeapon1start"));
static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMeshOb_AW2(TEXT("StaticMesh'/Game/SWORD_START.SWORD_START'"));
mStaticMesh = StaticMeshOb_AW2.Object;
mStaticMeshComponent->SetStaticMesh(mStaticMesh);
mStaticMeshComponent->SetCollisionProfileName(TEXT("h_weapon"));
mStaticMeshComponent->Mobility = EComponentMobility::Movable;
mStaticMeshComponent->RegisterComponent();
mStaticMeshComponent->OnComponentBeginOverlap.AddDynamic(this, &ABaseWeapon::OnBeginOverlap);
mStaticMeshComponent->bGenerateOverlapEvents = true;
mStaticMeshComponent->AttachToComponent(GetRootComponent(), FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true), "Hand_RSocket"); // Probably useless because it's already added in the blueprint of the character !?
}
and in my character blueprint :
137977-
So, then, as you we see the weapon is showing in the viewport, and the socket is respected.
However I can’t see this in the game…
Any idea ?