x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: Not Selected
Tags:
more ▼

asked Feb 28 '15 at 06:27 PM in Blueprint Scripting

avatar image

ShrewGlue
419 97 83 106

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Feb 28 '15 at 07:52 PM

avatar image

riandrake
156 8 10 12

avatar image ShrewGlue Feb 28 '15 at 10:48 PM

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.

avatar image riandrake Mar 02 '15 at 08:35 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question