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"

Two For loops cause "not all control paths return a value"

Ok i have a pretty simple code that counts X and Y up,

 FVector addCoords()
         FVector TempCoord;
         TempCoord = FVector(0, 0, 0);
         for (int8 x = -2; x <= 2; x++)
             for (int8 y = -2; y <= 2; y++)
                 TempCoord = FVector(x, y, 0);
              return TempCoord;

Pretty Straightforward i assumed. Count them up, give the X and Y cords out as a FVector for further usage. Done that hundreds of times back when i learned Java in school. However now i get the mentioned message that not all control paths return a value. But the point with "for" loops is, that i have just one way through, no breaks, no conditions. Just go from -2/-2 25 times up to +2/+2, return it as a Vector and done. So what seems to be the issue here?

Product Version: UE 4.12
more ▼

asked Jul 19 '16 at 04:47 PM in C++ Programming

avatar image

6 1 2

avatar image Xenome Jul 19 '16 at 05:15 PM

It's unclear what the intention is here. As it stands, that method would only be able to return precisely one vector with the values (-2, -2, 0).

Could be a confusion of terminology perhaps? An FVector in UE is just a group of three floats representing a position or a direction. I might be way off base here, but from your description it sounds like you're looking to make a list, which in UE would be done using a TArray.

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

1 answer: sort voted first

Without seeing the entire function, can't tell you positively about the error code. But, the loop that you did show is a mistake. It is not doing what your description for it is. It will return the first value, no incrementing will happen.

It is legal to return directly from in a for loop, but it is not good practice. There are break and continue keywords for a reason. If you want to end a loop early, set your variable, then break. A goto is perfectly acceptable to break from inside a nested for loop, it is actually maybe the only reason it's still in the language. But, you aren't testing for a condition inside the loop, so it makes no sense why you are returning out of it prematurely.

A local variable should be set, or appended to in the loop, then outside the loop at the bottom of the function return the variable if it is one. If your appending to a referenced list you don't need to return anything.

more ▼

answered Jul 19 '16 at 05:23 PM

avatar image

2.5k 102 67 261

avatar image Matzenator Jul 19 '16 at 05:34 PM

Ahh Yeah i recreated it inside of Blueprint and i had a mistake in my thought process. If i use 2 Loop inside each other i connected for example the spawn of an Actor to create a whole lot of blocks or whatever. BUT there, i connected the Loop Body to the next Position, so basically putting it into my for loop.

Yeah thanks. You helped me a lot :) My thinking was quite off.

(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