Spliting string

Currently I have:

	FString *ThrowAway;
	FString *HealthIndexString;
	GetActorLabel().Split(FString("BP_EnemyCharacter"), ThrowAway, HealthIndexString);
	int32 HealthIndex = FCString::Atof(HealthIndexString->GetCharArray().GetData());
	GEngine->AddOnScreenDebugMessage(-1, 1.f, FColor::Black, HealthIndexString->GetCharArray().GetData());

I get and error of “uninitialized local variable ‘HealthIndexString’ used” and “uninitialized local variable ‘ThrowAway’ used”. I have no idea what I’m doing wrong and would love some help with this.

Let me preface this answer with this statement. It has been a long time since I’ve done anything in C++, but I’ve programmed a few languages and know how they work.

Generally speaking, when you say “string myString;” that means you have reserved a space for it, which isn’t the same as initializing it. In order to initialize the string, you must set it to something, even if it is empty.

After reading up on the FString documentation, I have come to the conclusion that yes, you should try to initialize it like so:

FString *ThrowAway = FString(TEXT(""));
FString *HealthTindexString = FString(TEXT(""));

Be warned, everything I mentioned might be gibberish. I don’t use C++ in UE4 (yet), but I’ve learned a lot about programming through trial and error, so give it a shot. If it works, cool, if not, hopefully someone more versed in the matter can help.

When I set it like that I get an error of “No suitable conversion from FString to FString *” I’ve tried everything I can think to do and the functions used need the FString *

I fixed it initializing them with nullptr

Good to know I helped despite my lack of knowledge :slight_smile: