AddOnScreenMessage does not work

I have tried everything , even enabling and disabling all on screen messages. nothing works.

The UE_LOG runs and works but not the add on screen.

#include "PuzzlePlatformsGameInstance.h"

UPuzzlePlatformsGameInstance::UPuzzlePlatformsGameInstance(const FObjectInitializer& ObjectInitializer)
{
	UE_LOG(LogTemp, Display, TEXT("GameInstance: Constructor"));
}

void UPuzzlePlatformsGameInstance::Init()
{
	UE_LOG(LogTemp, Display, TEXT("GameInstance: Init()"));
	GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Your Message"));
}

void UPuzzlePlatformsGameInstance::Host()
{
	//UEngine* Engine = GetEngine();
	if (!ensure(GEngine != nullptr)) return;

	GEngine->AddOnScreenDebugMessage(1, 10.f, FColor::Green, TEXT("Hosting"), true, FVector2D(2,2));
	UE_LOG(LogTemp, Warning, TEXT("Host Run"));
	//FScreenMessageString* Message =  ScreenMessages.Find(-1);
	//if (Message != NULL)Message->TextScale.X = Message->TextScale.Y = 1.0f;
}

ok update:

I ended up just following the join stuff and realised that my live coding was not working. So i restarted ue5 project and now its working. I also opened the project with standalone a few times, both single and 2 players. before i gave up and went on to the joining code.

here is my full code at the end of the day:

// Fill out your copyright notice in the Description page of Project Settings.


#include "PuzzlePlatformsGameInstance.h"

UPuzzlePlatformsGameInstance::UPuzzlePlatformsGameInstance(const FObjectInitializer& ObjectInitializer)
{
	UE_LOG(LogTemp, Display, TEXT("GameInstance: Constructor"));
}

void UPuzzlePlatformsGameInstance::Init()
{
	UE_LOG(LogTemp, Display, TEXT("GameInstance: Init()"));
	GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Initialized"));
}

void UPuzzlePlatformsGameInstance::Host()
{
	//UEngine* Engine = GetEngine();
	if (!ensure(GEngine != nullptr)) return;

	GEngine->AddOnScreenDebugMessage(0, 10.f, FColor::Green, TEXT("Hosting"));
	UE_LOG(LogTemp, Warning, TEXT("Host Run"));
	//FScreenMessageString* Message =  ScreenMessages.Find(-1);
	//if (Message != NULL)Message->TextScale.X = Message->TextScale.Y = 1.0f;
}

void UPuzzlePlatformsGameInstance::Join(const FString& Address)
{
	if (!ensure(GEngine != nullptr)) return;

	GEngine->AddOnScreenDebugMessage(0, 10.f, FColor::Green, FString::Printf(TEXT("Joining %s"), *Address));
	UE_LOG(LogTemp, Warning, TEXT("Join Run"));
}

This is a change in UE5.1 and later I think. You need to add Super::Init() into your Init call. I think it causes some problems.

Give that a try to start with. Also, disable live coding - this just causes more problems than it solves.

EDIT:
As it happens, this should be there. UE4.x and 5.0 works just fine without this.

Yeah , i saw that my Init was missing my super, i added it not long after this was posted. Live coding has been working just fine, only happened to be not working because of the IDE not updating. Which lead me to the solution of closing and reopening the ide and project

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms