ForLoop to find actor in the array

Hey
So I wanted to make an custom node to find the actor in any actor array, since contains item doesnt go through all the elements in the array
So If the object name matches the given name i want it fire print string and say “true” if it doesnt just “false”
Here is what I have so far:

And I could not get any furher.
Thanks in advance

Hi there,
you just need to use the LoopBody execution path instead of the Completed path. Then it should work as expected.

Perhaps you want to check out these tutorials (9-For Loops to 12 For Each Loop), to gain more understanding of usage.

You probably want to use For Each Loop or For Each Loop with Break, depending on what you want to achieve with.

Sorry, I actually started to create you a blueprint sample, but i thought you will be more happy about these tutorials to avoid further struggles with basics :slight_smile:

hth :slight_smile: Marooney

Thanks, and please a blueprint sample would be great please :smiley:

^^ ok this one spits out the result for every actor in the array as i understood with your question:

Try the sample from Atheist91 too if you want to print just True if any exists, or False if none exists.

When I test, it doesnt work it returns true if there is an actor in the array doesnt matter which one

Oh I found the problem, the issue is within the ‘Get Display Name’ it returns none why??

I don’t think so It used to work I dont know why it fails now
‘Add’ is the correct way to add an element to an array right?

Try this:

1 Like

Can you show me how you use it? I’ve tested it and it worked as I thought you wanted.

It should go through array of actors you pass, and if it finds the one using the name you provided it prints “true”, otherwise it says “false”.

Maybe your array contains empty elements?

I’ve updated my answer. Forgot to add null check. (marked with red rectangle)

Could you show me:

  • the place you fill your array
  • the place you execute the function
  • yours implementation of this function

This would help to narrow down the issue.

Yes, adding is proper way. Or rather one of proper ways. There are nodes like Add, AddUnique and Insert.

But again, It’ll be easier to find the problem if you’d just show me the things I asked above. Without it, it’s just guessing game with lots of possible answers. :confused:

Okay, it… doesn’t help that much. :confused:

You could try to double check name of newly added object to the array.
Also, before executing FindActorInTheArray function, you could try to print names of all objects and see if these are valid.

Also, I’m not sure if it’s intended (as you wanted to have a function that searches for ACTOR in array of ACTORS), but you’re adding static mesh to the array. That means, the array cannot be an array of actors. And when you get a name of a component, returnes name sticks to the pattern: . (e.g. CharacterPlayer.Mesh)

That could be possible cause why it wouldn’t find that object if you’d search for it.

I believe GetDisplayName would return none, only if it would be actual name of the object (which is pretty rare :p) or if the object whose name you want to get is null.

Maybe your objects got destroyed somewhere between you add them to the array and call the function?

Here it is(in order):

Yeah Array of Static Mesh Components would be a better name :slight_smile:
does toggling the visibility of the object destroy it but i dont think so.

Also if use get display name and choose it from the content browser it works fine but if i use it from the casting it displays nothing if i use it from the array it displays none

Nope, it shouldn’t destroy the object.

Is it possible you’d reproduce that problem in clean project and upload it here?

I really dont think this a specific-project issue and if i were to reproduce it .it’d require to rebuild the whole thing again
the problem is not with the array im sure its with the casting or.some sort.
can you import a ststic mesh and make a blurprint of that and cast it in the.firsperson bp and get the display game to seeif that works for you?