Hey I am trying to create an unparented utility class and create a new object of this type in my player controller. I don’t trust the errors I get in visual studio, but I get a "This declaration has no storage class or type specifier on the UCLASS() tag of my controller class. I also get a LINK2019 unresolved external symbol SDSpellsUtil::SDSpellsUtil(void) on the line of code in my controller class where i attempt to invoke the SDSpellsUtil constructor.
I may have spent too long away from c++ and this is just some careless mistake on my end, but I think it’s got something to do with unreal. I’m going to include what I think the relevant pieces of code are but I’m happy to share more.
Utility header file
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "SDBaseSPell.h"
#include "SDDeveloperAngst.h"
#include "SDConstants.h"
/**
*
*/
class SOULDRIVE_API SDSpellUtils
{
public:
SDSpellUtils();
~SDSpellUtils();
ASDBaseSpell* LoadSpell(FName SpellName);
private:
TMap<FName, ASDBaseSpell*> AllSpellsMap;
};
Utility implementation file
// Fill out your copyright notice in the Description page of Project Settings.
#include "SoulDrive.h"
#include "SDSpellUtils.h"
SDSpellUtils::SDSpellUtils()
{
// AllSpellsMap.Add(SDConstants::DEVELOPER_ANGST, new ASDDeveloperAngst());
}
SDSpellUtils::~SDSpellUtils()
{
}
ASDBaseSpell* SDSpellUtils::LoadSpell(FName SpellName)
{
if (AllSpellsMap.Contains(SpellName))
{
return *AllSpellsMap.Find(SpellName);
}
return new ASDBaseSpell();
}
Controller header block, just included so you can double check headers and declaration of utils field.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/PlayerController.h"
#include "Blueprint/UserWidget.h"
#include "SDBaseSpell.h"
#include "SDSpellUtils.h"
#include "SDPlayerController.generated.h"
/**
*
*/
UCLASS()
class SOULDRIVE_API ASDPlayerController : public APlayerController
{
GENERATED_BODY()
protected:
bool bMoveToCursor;
virtual void PlayerTick(float DeltaTime) override;
virtual void SetupInputComponent() override;
void OnSetDestinationPressed();
void OnSetDestinationReleased();
void OnDebugActionPressed();
void OnDebugActionReleased();
void MoveToCursor();
public:
ASDPlayerController();
void BeginPlay() override;
UFUNCTION(BlueprintCallable, Category = "Input")
void OverrideHotkey(const FKey Key);
UFUNCTION(BlueprintCallable, Category = "Input")
void SetDebugOverride();
UFUNCTION(BlueprintCallable, Category = "Widgets")
void OnLaunchPlayerMenu();
void OnClosePlayerMenu();
void CastSpellSlot1();
UFUNCTION(BlueprintCallable, Category = "Widgets")
void SetMenuCanBeOpened(bool NewValue);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets")
TSubclassOf<class UUserWidget> wPlayerGameMenu;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets")
uint8 OverwritableAction;
private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Player, meta = (AllowPrivateAccess = "true"))
FString DebugActionAssignedKey;
FName SpellSlot1;
bool MenuCanBeOpened;
FInputModeUIOnly KeyRebindInput;
FInputModeGameAndUI StandardInput;
UUserWidget* PlayerGameMenu;
SDSpellUtils* SpellUtils;
};
controller’s beginplay method
void ASDPlayerController::BeginPlay()
{
Super::BeginPlay();
SpellUtils = new SDSpellUtils();
SpellSlot1 = SDConstants::DEVELOPER_ANGST;
if (wPlayerGameMenu)
{
PlayerGameMenu = CreateWidget<UUserWidget>(this, wPlayerGameMenu);
}
}