I wrote a simple code and get an error, I can’t understand why there is no access
C:\Users\79215\Documents\Unreal Projects\HowTo_UMG\Source\HowTo_UMG\MyUserWidget.h(37): note: see declaration of 'UTextBlock'
C:\Users\79215\Documents\Unreal Projects\HowTo_UMG\Source\HowTo_UMG\MyUserWidget.cpp(15) : error C2027: use of undefined type 'UTextBlock'
MyUserWidget.h
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "MyUserWidget.generated.h"
/**
*
*/
UCLASS()
class HOWTO_UMG_API UMyUserWidget : public UUserWidget
{
GENERATED_BODY()
public:
virtual void NativeConstruct() override;
public:
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
class UTextBlock* ItemTitle;
};
MyUserWidget.cpp
#include "MyUserWidget.h"
void UMyUserWidget::NativeConstruct()
{
Super::NativeConstruct();
if(ItemTitle)
{
ItemTitle->SetText(TEXT("Name "));
}
}
I added #include "Components/TextBlock.h" and get another errors
C:\Users\79215\Documents\Unreal Projects\HowTo_UMG\Source\HowTo_UMG\MyUserWidget.cpp(13) : error C2664: 'void UTextBlock::SetText(FText)': cannot convert argument 1 from 'const char [1]' to 'FText'
C:\Users\79215\Documents\Unreal Projects\HowTo_UMG\Source\HowTo_UMG\MyUserWidget.cpp(13): note: No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Program Files\Epic Games\UE_4.24\Engine\Source\Runtime\UMG\Public\Components/TextBlock.h(162): note: see declaration of 'UTextBlock::SetText'
Components/TextBlock.h
. – Quentin Feb 12 '20 at 10:58