My problem is the following:
I had one class wich was the base class for my character blueprint, but i wanted to add an enemy AI to the game wich had some behavior of the main character. So i created two new classes (EnemyCharacter and PlaybleCharacter) that inherit from a GeneralCharacter class.
I believe I have changed everything that referenced my previous player class to the new one.
- The problem:
On BeginPlay() function overwritten on my GenericCharacter Class i call a function to give a default weapon to my character. I copied the exact code of this function to the new class, wich was working before, but now it crashes when i hit the play button on the engine with the following error:
As you can see it points to line 232. Heres is the rest of the code wich may cause conflict, although it worked previously:
-
GenericCharacter.h
#include “GameFramework/Character.h”
#include “Weapon.h”
#include “GenericCharacter.generated.h”(…)
/** Weapon Spawned on character */
UPROPERTY(EditDefaultsOnly, Category = “Default Inventory”)
TSubclassOf DefaultWeapon;/** Current Weapon on Character */ UPROPERTY(VisibleAnywhere, Category = Weapon) AWeapon *CurrentWeapon; /** Create Inventory Array with Weapons */ UPROPERTY(VisibleAnywhere, Category = Inventory) TArray<class AWeapon*> Inventory;
-
GenericCharacter.cpp
#include “WeaponTest.h”
#include “GenericCharacter.h”
#include “Pistol.h”
#include “Shotgun.h”
#include “RocketLauncher.h”
#include “Engine/Blueprint.h”
#include “Engine.h”AGenericCharacter::AGenericCharacter()
{}
// Sets default values
AGenericCharacter::AGenericCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;// Set size of Inventory Array Inventory.SetNum(4, false); // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f); // Configure default character state and movement this->bDisableFiring = true; this->bIsAiming = false; this->bIsFiring = false; this->bIsSprinting = false; this->bIsReloading = false; this->SprintSpeed = 700.0f; // in centimeters / second this->JogSpeed = 450.0f; // in centimeters / second this->AimSpeed = 200.0f; // in centimeters / second this->GetCharacterMovement()->MaxWalkSpeed = this->JogSpeed; this->GetCharacterMovement()->bOrientRotationToMovement = true; this->GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // The character rotates at this rotation rate this->GetCharacterMovement()->JumpZVelocity = 350.0f; this->GetCharacterMovement()->AirControl = 0.2f; // 20% of the total control CollisionComp = ObjectInitializer.CreateDefaultSubobject<UBoxComponent>(this, "CollisionComp"); CollisionComp->AttachTo(RootComponent); CollisionComp->OnComponentBeginOverlap.AddDynamic(this, &AGenericCharacter::OnCollision);
}
// Called when the game starts or when spawned void AGenericCharacter::BeginPlay() { Super::BeginPlay(); this->GetCharacterMovement()->MaxWalkSpeed = this->JogSpeed; GiveDefaultWeapon(); } void AGenericCharacter::GiveDefaultWeapon() { AWeapon *Spawner = GetWorld()->SpawnActor<AWeapon>(this->DefaultWeapon->GetClass()); if (Spawner) { Inventory[Spawner->WeaponConfig.Slot] = Spawner; CurrentWeapon = Inventory[Spawner->WeaponConfig.Slot]; CurrentWeapon->SetOwningPawn(this); CurrentWeapon->OnEquip(); } }
Could the problem be the fact that i’m spawning the weapon on my base class (GenericCharacter) instead of the Playable character class wich is the base for my character blueprint? Any help would be realy apreciated, thanks