Testing if FName is unique?

I’m having a minor nuisance. I got my FName property type customization working… mostly.

Essentially, what I wanted to do was just to check if the Name already exists elsewhere when entering my own. This is useful for what we’re doing because we have a table of Names, and want to make sure we’ve correctly typed the name when referencing it elsewhere.

Now I am able to test if the Name I’m typing exists already, but the problem is that when I save the value the value is added to the table of names. Thus, I’m no longer testing if the name exists elsewhere

To recap:

  • I want to define a Name variable someplace in blueprints.
  • We want to check whether or not this Name already exists when typing.
  • Upon completing my entry, the Name is added to the table, and our test above always returns a match - itself.

Here’s how I’m testing for an already existing entry:

if (FName(*NewText.ToString(), FNAME_Find) == NAME_None)
{
	bUniqueName = true;
}
else
{
	bUniqueName = false;
}

And this is simply reflected here…

if(bUniqueName)
{
	return FText::FromString(TEXT("!="));
}
else
{
	return FText::FromString(TEXT("=="));
}

I.e if I write “MachineIsPowered” - a name I know matches - I get a match. So that’s good! If I write “MachineIsPowerede” I no longer get a match… until I hit enter, upon which “MachineIsPowerede” is now an entry that I can match on…

I pseudo-solved this by checking if it exists before the data is committed. Unfortunately, any unique name is simply stored as an entry in a very big array, and referenced by its index. If you write an FName that matches something already in it, you’re simply given the existing index.

This means there is no count of how many uses exist, only if it exists.

If I’m wrong, please do tell. I’m still interested in fixing this, but this seems to be the case from what I’ve discovered.

Maybe you have to use TMap property (introduced in 4.15). If you dont want to migrate to 4.15 you can create something like that by using an UStruct with hidden TMap and right property customization. TMap can be easily checked for containing a key by using ‘Contains’ method

Thanks for the suggestion, but unfortunately that wasn’t an option for this context.

In this context, I was modifying the detail customization of FName. Just in general what I was doing required finding any other uses of the FName I’m trying to create.

Additionally, I wanted to find if there were more than zero instances. From what I can gather, there is not. You can determine if something exists, but not if there is more than one use of it.