Hello and good afternoon everybody,
I have been messing with unreal for a while already, and I am trying to make a simple HUD for my game, which will use textures, I am using a class of my own which is inherits from AHUD, no changes in constructors or destructors, just custom methods to draw the heads up display, however, I am still struggling on on how I can get a texture and draw it to the screen using the method “DrawTextureSimple”, I succeeded in doing so by setting the texture in blueprints through a blueprintable method I created in C++ (method setTexture), however I cannot yet understand how to do the same in pure C++ (trying through the method setTextureC)…
Can anyone explain to me how to do it?
*I am a noob…TT__TT
Thanks for the attention,
*CODE:
-FILE “DTHUD.h”:
#pragma once
#include "GameFramework/HUD.h"
#include "DTPlayerState.h"
#include "DTHUD.generated.h"
UCLASS()
class ACTIONSYSTEM_API ADTHUD : public AHUD
{
GENERATED_BODY()
public:
UTexture* texture;
UFUNCTION(BlueprintCallable, Category = "DT HUD")
ADTPlayerState* GetPlayerState();
UFUNCTION(BlueprintCallable, Category = "DT HUD")
void SetPlayerState(ADTPlayerState* newPlayerState);
UFUNCTION(BlueprintCallable, Category = "DT HUD")
UTexture* GetTexture();
UFUNCTION(BlueprintCallable, Category = "DT HUD")
void SetTexture(UTexture* newTexture);
UFUNCTION(BlueprintCallable, Category = "DT HUD")
void SetTextureC();
void DrawHUD();
protected:
ADTPlayerState* dTPlayerState;
};
-FILE “DTHUD.cpp”:
#include "ActionSystem.h"
#include "DTHUD.h"
void ADTHUD::DrawHUD(){
if (dTPlayerState){
DrawTextureSimple(texture, 0, 0, 1, false);
}
}
void ADTHUD::SetPlayerState(ADTPlayerState* newPlayerState){
dTPlayerState = newPlayerState;
}
ADTPlayerState* ADTHUD::GetPlayerState(){
return dTPlayerState;
}
void ADTHUD::SetTexture(UTexture* newTexture){
texture = newTexture;
}
UTexture* ADTHUD::GetTexture(){
return texture;
}
void ADTHUD::SetTextureC(){
static ConstructorHelpers::FObjectFinder<UTexture2D> MyObj(TEXT("/Game/ThirdPerson/test"));
texture = MyObj.Object;
}