First of all I am aware that there are several questions concerning this issue :
I still couldn’t figure it out so here I am with my question:
//in my constructor
static ConstructorHelpers::FObjectFinder<UFont> HUDFontOb(TEXT("Font'/Game/Fonts/NewFont.NewFont'"));
HUDFont = HUDFontOB.Object;
//in the header of my HUD class
The error I got is :
Error 12 error C2664: ‘void
*,const FString &,const TCHAR *)’ : cannot convert argument 1 from ‘UFont
*’ to ‘UObject *’ C:\Unreal Engine\4.4\Engine\Source\Runtime\CoreUObject\Public\UObject\ConstructorHelpers.h 92
I’ve got the Font in the ContentBrowser in a folder named Fonts.
It seems to me that this a Path problem in the TEXT(), I got the same error message whatever I write in TEXT(), still I can’t figure it out, I hope someone will be able to enlighten me on this issue.
August 18, 2014, 9:27am
First of all, aren’t you missing a ’ at the end of your Font Path? Just saw that, don’t know if it could cause an error.
The second thing is, you are assigning an UObject to an UFont Variable. You need to cast it.
For example like this:
HUDFont = (UFont*) HUDFontOB.Object->GeneratedClass;
I’m not so good in c++, but that’s how i cast my Blueprints after getting them with ObjectFinder.
Good catch for the missing " ’ " , still this not working, I still get the same error.
I edited the question to add it in the code.
For the casting part, it doesn’t come into play as the error is triggered at the FObjectFinder call =>
https://answers.unrealengine.com/questions/73913/ahud-drawtext-ufont-compile-error-c.html He didn’t seem to have any problem with the
Font = FontObject.Object;
Thanks anyway !
Get myself to simply use BluePrints to set the Default font to do that add into GameMode class :
//into your constructor
static ConstructorHelpers::FObjectFinder<UBlueprint> HUDBpClass(TEXT("Blueprint'/Game/Blueprints/BP_HUD.BP_HUD'"));
if (HUDBpClass.Object != NULL)
HUDClass = (UClass*) HUDBpClass.Object->GeneratedClass;
BP_HUD is a blueprint instance of your HUD class in C ++, don’t forget to change UPROPERTY to something like that:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrtie, Category = HUDFont)