How to find a specific element in an array that is the same as others

you will probably have to run a loop on all the actors in the array. basically get john smith as the actor then compare all others to him. so for each, get john smith sir name, get X sir name, does X == smith, branch, if true make family relation based on conditions, if false do nothing / move on to next.

I have a random npc generator in my project and I’m trying to random gen family members.

So basically through any number of ingame events the npcs are generated randomly. Names, ages, height weight, stats etc… All random. If npcs happen to share last names then the game would make them related somehow. Father, son. Husband, wife etc. etc…

Random npc generated > info added to profile struct > last name stored into array > and here is where I am stuck. It’s adding all npc names to the array but how do I check for say Smith if there’s already a Smith there and they’re both the same?

Say npc 1 is generated first, name: John Smith, another npc is generated: Nancy Smith how do I make an array compare those? They’re functionally the same so the contains node is always gonna return true even if nance isn’t in the array.

Any help appreciated.

Okay I understand the basic concept, but how do I get an actor that doesn’t exist yet? Cause everything is spawned and generated when they are put into the world.

I’m sorry since this basic ■■■■ but I’m just super new to ue and trying to learn.

Here’s a picture of my current code setup on this function.

If the last name is stored in the profile struct and you can retrieve an array of profile structs for all NPCs, you can basically setup a function that has a Map where the Key=Lastname and Value=Array of Indexes. Or you can even do this while generating NPCs.

So basically, as you go through each profile, you add its index in the Profiles array to the map using its last name. At the end, you will have each LastName pointing to an array of profiles with that last name, then process it as needed.
So for example:
ProfilesArray: [0] John Smith, [1] Nancy Smith, [2] Max Connor

The map result would be:
[Smith]:[0, 1]
[Connor]:[2]

Then you process the map as you want your families to be processed.

How do I add an array to a map any attempt I do says it’s uncompatible with my npc array. And how do I stop it from pulling itself out? So It adds smith and checks for smith wouldn’t it just pull itself every time? That’s my problem with the way I’m trying to do it. And if they have unique numbers assigned that’s all well and good but I have no way to know which number will get assigned where since it’s random gen.

So I have to tell it to look for the name it gens at random which would make it pull itself.

You create a struct that has an array of indexes (Ints) inside of it.
The index in the profiles array is what you use to link the map to each individual profile. Like the example I mentioned.