AndrewScheidecker / BrickGame

A demo of Minecraft-style voxel rendering in UE4
399 stars 145 forks source link

How to initialize project components #6

Closed StenBone closed 9 years ago

StenBone commented 9 years ago

I am trying to use UBrickGridComponent in my BrickGrid class which is based off of the BrickGrid blueprint.

In my header:

TSubobjectPtr<class UBrickGridComponent> BrickGridComp;

In the constructor of my source file:

BrickGridComp = ObjectInitializer.CreateDefaultSubobject<UBrickGridComponent>(this, TEXT("BrickGridComp"));

The project builds the header properly, but throws an error when trying to run the source file. I have other components in my project which compile fine, when using similar syntax. What do you think is the problem? Is there another way to initialize this component?

Error Message:

error LNK2019: unresolved external symbol "private: static class UClass * cdecl UBrickGridComponent::GetPrivateStaticClass(wchar_t const *)" (?GetPrivateStaticClass@UBrickGridComponent@@CAPEAVUClass@@PEB_W@Z) referenced in function "private: cdecl ABrickGrid::ABrickGrid(class FObjectInitializer const &)" (??0ABrickGrid@@AEAA@AEBVFObjectInitializer@@@Z) C:\Users\Ben\Desktop\BrickGame-master\BrickGame-master\Intermediate\ProjectFiles\BrickGrid.cpp.obj

StenBone commented 9 years ago

I changed the constructor, but still got the same error.

ABrickGrid::ABrickGrid(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
{
    PrimaryActorTick.bCanEverTick = true;
    BrickGridComp = PCIP.CreateDefaultSubobject<UBrickGridComponent>(this, TEXT("BrickGridComp"));
}

I am really confused as to what is wrong.

AndrewScheidecker commented 9 years ago

I think this is a case of the UBrickGridComponent definition missing the BRICKGRID_API qualifier. Try changing it to this: class BRICKGRID_API UBrickGridComponent : public USceneComponent Let me know if that works and I'll make the change in the master branch.

StenBone commented 9 years ago

Your instructions worked @AndrewScheidecker! I was beginning to think that I would never sort out that bug.

I put BRICKGRID_API in the right place just as you demonstrated in your reply above and removed BRICKGRID_API from the method declarations within the UBrickGridComponent class declaration in the header and now it works perfectly.

Thank you for the help @AndrewScheidecker and happy new year!