What is wrong with my code that makes the editor at 71% while starting up?

Hello,

i am new to UE4 and i am stuck at a rather silly problem at the moment. My Editor keeps crashing at 71% when i add some really simple code. If I delete the code the Editor starts as normal.
Because of the simplicity of my code i cant really understand why this is happening and i hope that someone can provide some answers.

Inside a for-loop i am calling my function ‘PrintFloatToScreen’ like this:

PrintFloatToScreen("Some Array Filled With Floats");

This function is defined like this:

void AImportBuildings::PrintFloatToScreen(float Output) {
      GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Output-float: %f"), Output));
}

And in my headerfile i wrote this:

UFUNCTION(Category = "Custom Functions", BlueprintCallable)
    	void PrintFloatToScreen(float Output); 

Basically i just want to print the values of the array on my screen. Furthermore i want to use this function inside a blueprint.

I hope someone can help me figure out this problem.

Note:
I have the same problem implementing an if-else structure. Again: The code is really simple though it is crashing my editor. I get the feeling that there might be a far bigger problem with my coding that i dont understand yet. I am not completly new to c++ programming and i am surely able to implement some code outside UE4. Somehow i am barely able to implement anything in UE4.

Any help will be appreciated.

Have a nice day

Hey,
I would start UE from visual studio so you can have a debug on that
( set your project as startup project and click the green arrow )

Where do you put that for loop ? it’s call in engine initialisation ?
maybe “GEngine” is still null in that moment ?

could you put the code you use to call this method ?

Hey,
Thanks for your reply. I think it is the easiest if i show you my code and you can look at it yourself.
It is quite possible that GEngine is still null at this moment, because the engine is just starting up.
This would also explain why my code works once the engine is started.
If this is the root of my problem:
How do i prevent the engine from executing this code during startup or how do i make this code not crash?
Why does the engine execute this code during startup in the first place?

ImportBuildings.h:

#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Landscape.h"
#include <Engine.h>
#include <fstream>
#include <iostream>
#include <cmath>
#include "ProceduralMeshComponent.h" //Do need this later on to generate meshes during runtime
#include "ImportBuildings.generated.h"

UCLASS()
class MYPROJECT_API AImportBuildings : public AActor
{
	GENERATED_BODY()

public:
	AImportBuildings();
	virtual void Tick(float DeltaTime) override;
	virtual void BeginPlay() override;

	UPROPERTY(BlueprintReadWrite)
		TArray<float> BuildingConturPoints;

private:
	//Functions:
	UFUNCTION(Category = "Custom Functions", BlueprintCallable)
	TArray<float> GetPointCoordinates(); 

	UFUNCTION(Category = "Custom Functions", BlueprintCallable)
	void PrintFloatToScreen(float Output); 

	//Variables:
	TArray<double> AllPoints;										
};

ImportBuildings.cpp:

#include "ImportBuildings.h"

AImportBuildings::AImportBuildings()
{
	PrimaryActorTick.bCanEverTick = true;
	GetPointCoordinates();
}

void AImportBuildings::BeginPlay()
{
	Super::BeginPlay();
}

void AImportBuildings::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

TArray<float> AImportBuildings::GetPointCoordinates() {

	//Get the vertices coordinates as a big string and split it
	FString InputString("291951.496 5630174.519 200.57 291951.516 5630175.0 200.57 291951.539 5630175.539 200.575 291951.559 5630176.0 200.574 291951.584 5630176.584 200.568 291951.601 5630177.0 200.564 291951.628 5630177.628 200.564 291951.644 5630178.0 200.574 291951.672 5630178.672 200.58 291951.686 5630179.0 200.576 291951.717 5630179.717 200.576");

	TArray<FString> OutputString;
	InputString.ParseIntoArray(OutputString, TEXT(" "), true);
	AllPoints.SetNum(OutputString.Num());

	BuildingConturPoints.SetNum(OutputString.Num());

	for (int i = 0; i < OutputString.Num();i++) {
		BuildingConturPoints[i] = FCString::Atod(*OutputString[i]); 

		PrintFloatToScreen(BuildingConturPoints[i]);
	}

	return BuildingConturPoints;
}

void AImportBuildings::PrintFloatToScreen(float Output) {
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Output-float: %f"), Output));
}

Note:
To shorten my answer I deleted alot of other stuff in that code that would happen after the long string is split and converted into numbers. Therefore this code is simplyfied by alot, which further represents why i think that my problem is really basic and that my c++ coding is not the root cause, but my lacking understanding of UE4.

Thanks in advance for your help.

I would need all the places where you call that “PrintFloatToScreen” method !
but that’s strange that the engine try to call it, once again, put a break point on it and check by yourself, i can’t do that for you :confused:

Also i see you have those includes, i would recommand you to only use UE ones ( probably not the problem here though )

 #include <Engine.h>
 #include <fstream>
 #include <iostream>
 #include <cmath>

Ok, just checked on my game,

at 71%, idoes call contructor of your classes/blueprints to generate the “default objects” for them

so that’s normal if it’s called durring engine loading

simply change

void AImportBuildings::PrintFloatToScreen(float Output) {
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT(“Output-float: %f”), Output));
}

to

     void AImportBuildings::PrintFloatToScreen(float Output) {
if(GEngine)         
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Output-float: %f"), Output));
     }

this will silence the log when loading the engine and keep it when engine is loaded

Thank you very much for your help.

I really appreciate your efforts.