How to convert int32 to FString to FName

I’m attempting to set up a for loop where a number of actors are spawned and then attached to a socket on the owner’s skeletal mesh. In doing this I’m trying to figure out how I can take int i and some how get it to be appended onto the FName that gets passed into AttachToComponent. If that’s unclear here is the code from my first attempt:

int32 i = 1;
		FString TempString =FString::FromInt(i);

WeakPoint = GetWorld()->SpawnActor<AWeakPoint>(WeakPointClass);
		WeakPoint->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform, TEXT("WeakPoint0" + TempString));

“WeakPoint” is an actor pointer of the type I am trying to spawn.

This is the error I am getting:

error C2664: ‘void AActor::AttachToComponent(USceneComponent *,const FAttachmentTransformRules &,FName)’: cannot convert argument 3 from ‘FString’ to ‘FName’

Build the string first and then use FName().

FString myString = // build your string however

WeakPoint->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform, FName(*myString)));
1 Like

A cleaner format your string is probably:

FString socketName = FString::Printf(TEXT("Weakpoint%i"), i);

// do attach using socket name

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