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"

How to get the index from an array element?

I'm making the targeting system for a turn based RPG and would like to get an element index in integer form, so I could check who's selected and stuff like that. Is it at all possible, or do I need to create an integer and manage it all the way through?

Product Version: UE 4.20
Tags:
more ▼

asked Sep 09 '18 at 09:15 PM in Blueprint Scripting

avatar image

BillyOAntiBully
1 1 1 1

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

2 answers: sort voted first

No, because TArray same as raw C++ array is using memory offset as index, making it unreliable id, if you remove element from array it will move all farther items in memory in direction of removed item. You might consider using TMap which use key to value pairing (TPair) to store items and you can use any type as index, at first it might not make sense to use integer as key type as it will work like TArray, but thing in TMap set index will be persistent or else you will change index of the item yourself

more ▼

answered Sep 09 '18 at 09:46 PM

avatar image

Shadowriver
35.8k 926 169 1104

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

I'm not sure I follow exactly what your thinking is here, but I have found that using an array of actor object references I am able to set and index to "None" by using "Set Array Element" an connecting the array and index pins and leaving the "item" pin unconnected. You can use the "Find" node to find and Element in an Array and return it's index. You can use "Get (a copy)" on the array and use an index integer to retrieve the Element at that index. You can then use "Is Valid" to check if it is valid (Not Pending Kill and Not "None") or you can use the "Find" Node to find the first element that is "None" by not connecting the "Item" pin. It will return the index number of the first index it finds -- to "None" ad return that index, or if all indexes are set, it will return a -1 for the integer.

Does this Help? You could make an Array of Actor Objects and assign the characters/enemies. You could create multiple Arrays (Selected/Targeted/Wounded etc.) and each index in each array would represent each character/enemy. Your other arrays could be booleans, floats or what ever. As long as you do the same operation (Removing, inserting etc.) the same to each array your indexes should match. Or you could create a custom structure variable to put in an array which contains all the data you need and make an array of that structure corresponding to your array of characters/enemies. Hope this makes sense??

more ▼

answered Apr 16 '19 at 04:07 PM

avatar image

blindminds
43 1 3

(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