Check if an actor in an array's class is equal

Hi all, so I have an array of actors which represent the player’s inventory.

In this case, I have a key actor in the inventory.

When I get close to a lock blueprint, I want it to check the player’s inventory (which I can successfully access using casting) if there are any actors that are part of the key class.

How do I do this last part?

Try iterating through each element in the inventory array (ForEach node) and try casting each element into a Key blueprint. If the Cast node returns IsValid, then the actor is a Key.

If the inventory was large, I’d probably save a reference or an index to the key(s) in a separate array outside the inventory. Much easier to query.

This worked!

Fortunately my inventory is small, but can you elaborate on the reference array thing? I’m having a bit of trouble understanding it.

When you add a new item to your inventory, you could try casting it to see if it’s a key; if it is, you could have another array of keys that you could reference much quicker.

But if size isn’t a problem, then at least save an integer telling you how many keys you currently have. Increment it every time a key is added, and decrement it when one is removed; that way you could save time searching through the whole inventory for a key that you know isn’t there.