ConstructorHelpers: Cannot convert argument 1 from 't*' to 'UObject *'

Getting very weird error while trying to get my sprite from C++. My code as follows :

    UPaperSpriteComponent* BaseBonusSpriteComponent;
    BaseBonusSpriteComponent = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT("BaseBonusSpriteComponent"));
    ConstructorHelpers::FObjectFinder<UPaperSprite> DoublePoint(
        TEXT("PaperSprite'/Game/TexturesSprites/Collectables/Buff_2xPoint_Sprite.Buff_2xPoint_Sprite'"));
    int32 RandomBonusIndex = FMath::Rand() * 2;
    switch (RandomBonusIndex)
    {
    case 0:
        BaseBonusSpriteComponent->AttachTo(CollisionSphere);
        BaseBonusSpriteComponent->SetSprite(DoublePoint.Object);
        break;
     }

Getting error as:

void ConstructorHelpers::ValidateObject(UObject *,const FString &,const TCHAR *)’: cannot convert argument 1 from ‘T *’ to 'UObject *"

Anyone have solution for this?

You must include the header which defines UPaperSprite.

4 Likes

I think this is correct, because in order to use UPaperSpriteComponent you must include the header “PaperSpriteComponent.h” which at first I through included “PaperSprite.h”, but it only have a forward reference for the UPaperSprite class.