Hi Guys,
I’ve been trying to attach a weapon to my AI, I’ve created the socket on the skeletal mesh. The line where I attach the weapon to the AI’s hand is throwing an error.
**Goblin.cpp**
void AGoblin::PostInitializeComponents()
{
Super::PostInitializeComponents();
//instantiate the melee weapon if a bp was selected
if (BPMeleeWeapon)
{
MeleeWeapon = GetWorld()->SpawnActor<AMeleeWeapon>(BPMeleeWeapon, FVector(), FRotator());
if (MeleeWeapon)
{
const USkeletalMeshSocket *socket = Mesh->GetSocketByName("MeleeWeaponSocket");
------------> socket->AttachActor(MeleeWeapon, Mesh); //ERROR here
}
}
}
The error is:
**error C2227: left of ‘->AttachActor’ must point to class/struct/union/generic type **
error C2027: use of undefined type 'USkeletalMeshSocket’
My Weapon Actor code is as follows:
MeleeWeapon.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Magii.h"
#include "MeleeWeapon.h"
// Sets default values
AMeleeWeapon::AMeleeWeapon(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
AttackDamage = 1;
bSwinging = false;
WeaponHolder = NULL;
Mesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("Mesh"));
RootComponent = Mesh;
ProxBox = ObjectInitializer.CreateDefaultSubobject<UBoxComponent>(this, TEXT("ProxBox"));
ProxBox->OnComponentBeginOverlap.AddDynamic(this, &AMeleeWeapon::Prox);
ProxBox->AttachTo(RootComponent);
}
// Called when the game starts or when spawned
void AMeleeWeapon::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMeleeWeapon::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
void AMeleeWeapon::Prox_Implementation(AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
{
//dont hit non root components
if (OtherComp != OtherActor->GetRootComponent())
{
return;
}
//avoid hitting things while sword isnt swinging
//avoid hitting yourself
//avoid hitting OtherActor twice
if (bSwinging && OtherActor != WeaponHolder && !ThingsHit.Contains(OtherActor))
{
OtherActor->TakeDamage(AttackDamage + WeaponHolder->BaseAttackDamage, FDamageEvent(), NULL, this);
ThingsHit.Add(OtherActor);
}
}
void AMeleeWeapon::Swing()
{
ThingsHit.Empty();
bSwinging = true;
}
void AMeleeWeapon::Rest()
{
ThingsHit.Empty();
bSwinging = false;
}
Has anyone encountered this before or has a possible alternative?
Thank you