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"

For each loops run infinite, cant understand why


I am doing a game where in our world, when the main character overlaps on a tile or platform, the flipbook changes and the tile/platform is 'transformed'

I am trying to make a completion bar for the world, so the player can try and track how much of the world they have transformed. In my HUD, I am trying to do the function that would update the percent bar.

Basically the problem is in the for each loop. I just want to see if the variable of the platform for transformed = true, and if so, increment my NumberTransformed counter. For some reason, it just increments it infinitely forever. I'm not sure if I have to incrememt the array index, or if ue4 does it automatically, that's why on the bottom part of the blueprint (it looks like the same class as the other one but its actually another one, the names look the same) I have it increment the index. It didn't help solve my problem.

Can anyone offer any guidance?

alt text

Product Version: UE 4.10
foreachsnapshot.png (137.3 kB)
more ▼

asked Apr 27 '16 at 06:56 PM in Blueprint Scripting

avatar image

1 2 2

avatar image jayice Apr 27 '16 at 07:13 PM

It's hard for me to see the nodes in the PNG snapshot because the resolution is low. But as you are using a "For Each Loop", altering the "index" the way you have it, won't make a difference.

The For Each loop is going to loop once for each element in the array, if you are altering the number of elements in the array in the code after the for each loop (i.e. adding to the end of the array), that could cause some headaches but you are not doing that. Because the array coming into the loop is coming out of the GetActors node.


IceWare Inc.


avatar image Lgotwals Apr 27 '16 at 07:20 PM

Sorry about the quality. Is this better?

I understand about the index, that I don't need to increment it myself. As far as my loop body though, do you see anything in it that would make NumberTransformed increment infinitetly? alt text

capture.png (270.7 kB)
avatar image jayice Apr 27 '16 at 07:30 PM

chuckles, if you could double the size one more time, would be good! My eyes are old, sorry about that, I just can't see what classes you are getting the actors for.

But I would put in print string, after each GetActor node, to dump out the length of each array being returned, There is actually nothing in the flow of execution to cause a infinite loop. As the code for the top loop is essentially identical to the code for the bottom loop, and you have the return node in order to return to the caller.

You may wish to look at the calling function, to see, if it is calling more this inner routine more than you expect.


IceWare Inc.


avatar image Lgotwals Apr 27 '16 at 07:36 PM

I put in a print string to see what NumberTransformed is, and I just realized my problem. If i transform 1 platform, it just keeps incrementing it by 1, because it just recounts the same platform as being transformed. I need a way to make it take all of the transformed platforms out of the array, so it only considers platforms that are not transformed and have not been counted for...

avatar image jayice Apr 27 '16 at 08:01 PM

Depending on which array you are referring too, you have two GetActor nodes. You really don't have a way to take an element out of an array that is meaningful.

The top loop gets it's own array, then so does the bottom loop. Hence you have what is called "information loss". In that the bottom loop cannot know what the top loop is doing, all the bottom loop knows is that that that the top loop finished executing (because of the completed pin), plus the "total transformable" and the "number transformed", but there is no information conveyed as to what is transformed.

As a hack, you might consider, making a new local array, that holds all the elements that were transformed. Then using it to filter out, on the lower loop, if they are getting the same set of Actors, or it they are connected in some fashion.


IceWare Inc.


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

1 answer: sort voted first

Don't know for sure if this is the thing that you are doing wrong, but in your second foreach loop you add to the index, you don't need to that since it is a foreach loop

more ▼

answered Apr 27 '16 at 07:00 PM

avatar image

413 17 15 31

avatar image Lgotwals Apr 27 '16 at 07:05 PM

ahh, ok thats what i thought initially but it wanst sure so I added it. I'll take it out

avatar image Lgotwals Apr 27 '16 at 07:10 PM

what it looks like nowalt text

untitled.png (134.5 kB)
(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