Sorry if my question sounds dumb. I’m trying to create a new object from a structure, and I want to use a FString value as the name.
Example:
struct Object
{
//stuff here
void functionName(FString iString)
{
//Creating a new object with the name from my string
Object (FString(TEXT(iString)));
}
};
Unfortunately this doesn’t work. Does anyone know of a way to make this work?
};
struct Structure2
{
Structure a; //me creating an object of structure
void CreateStructure(FString, iString)
{
Structure iString; //me attempting to use the value of iString as the name of a new Structure object.
}
};
This is what I’m trying to do. I want to use the value of a FString to use as the name while creating a new object.
I am not sure of what you are trying to achieve, but from your explanation i conclude that you want to refer (or ‘map’) a certain structure with an arbitrary name which is a string. And assuming you’re doing that because you will have more than one of them in the game then you may want to use a TMap , something like this:
/// This is the data structure
USTRUCT(BlueprintType)
struct FMyStruct
{
...
};
/// This is somewhere inside an object that manages the structure
TMap<FString, FMyStruct> MyStructs;
void GetOrCreateStruct( const FString& Name, FMyStruct& OutMyStruct )
{
FMyStruct* Entry = MyStructs.Find( Name );
if ( !Entry )
{
// There's no such entry, add a new one
OutMyStruct = MyStructs.Add( Name, FMyStruct() );
}
else
{
// Yes there is, use it as the output
OutMyStruct = *Entry;
}
}