ForEachLoop does not get all actors from class

Hi,

I have a blueprint system where upon the player overlapping a trigger volume the blueprint spawns AI from Class on the location of actors from another class (hidden in-game) that basically functions as location points. By connecting “Get all Actors of Class” with a ForEachLoop and connecting a GetActorLocation with the Array Element I spawn AI actors on those locations. But the problem is that it doesn’t spawn actors on all of those locations. I have placed 7 location markers but on only 4 or 5 of those AI actors get spawned. If this doesn’t make sense then here’s a screenshot:

Is there anything I’m doing wrong here? I do get some errors in the Message Log but I’m not sure I understand them:

Error Accessed None ‘CallFunc_SpawnAIFromClass_ReturnValue2’ from node Spawn Default Controller in graph ‘EventGraph’ in blueprint Stream_Level_Test3

Error Accessed None ‘CallFunc_SpawnAIFromClass_ReturnValue2’ from node Spawn Default Controller in graph ‘EventGraph’ in blueprint Stream_Level_Test3

Error Accessed None ‘CallFunc_SpawnAIFromClass_ReturnValue2’ from node Spawn Default Controller in graph ‘EventGraph’ in blueprint Stream_Level_Test3

Is there something I should be doing different?

Probably related to this bug: https://answers.unrealengine.com/questions/294580/get-all-actors-of-class-with-level-streaming-broke.html

Try adding a small delay before GetAllActorsOfClass.

You may also want to take a look at the array being used, to see if there is a null value in it. before you start to access the data. The error you show, will may cause the loop to terminate prematurly, and not fully process the array. To check for a null, get the != node, wire up the the output of the array into the node,and then wire the != into a If node (branch). This will check for a null, and allow you to bypass it.

Hope this helps,

Hi ,

Using a branch and checking for a null does indeed get rid of those errors, thank you. Unfortunately it does not solve the problem of not spawning actors on all of the locations.

With that said, I do appreciate not getting those errors anymore so thank you for this advice. I’ll make sure to remember this for the future.

Hi Arida,

Thank you, I did not see that post. Unfortunately adding a delay does not solve the problem for me but I’ll be sure to keep an eye on any future bug fix notes. For now I’ll just use a transform or vector array. Thank you!

Edit: It does actually seem to get all locations. When I use a print text for each array element it does return 7 vector values. It just doesn’t spawn AI on all those values. I may have to look into that.

Edit 2: connecting a get object name to the return value of “Spawn AIFrom Class” and using a print text confirms that it does not get all actors as it gives me 3 null messages. I’ll just wait for any bug fixes.

Hi !

Ok with the errors out of the way. There is another thing, that makes talking about this sort of stuff easier, or at least to me.

That is instead of the screen shots, when you have the function displayed in the UE4 editor, do a CTRL+A to select all the nodes in the blueprint function your looking at. Then do a CTRL+C, in order to copy it to the clipboard. Grab your favorite text editor, and do CTRL+V, in order to paste from the clipboard (or the equivalent for the OS of choice,and I’m not trying to be patronizing, just attempting to stop forum post tag!)

When you take a look at what was pasted in, you will see the entire “function” there in text format, GUID’s for vars, init states, etc. This has helped me track down so many issues, some Epic’s, mostly mine. Because it makes a lot of the error/warning messages meaningful. Now you know which node they are talking about! lol

Also, if you paste that back into the UE4 Editor, the Blueprint editor, understands it, and will create all the nodes, it doesn’t really create the variables for you, so that’s a gotcha, but you can see what the type of the variable is, etc. So it’s still pretty fantastic. And yes, I have a product i’m building based solely off this. It can be used to do a very quick backup of blueprints, if your getting concerned about something. Although not the best way to do it, but it’s fast. Best way in my opinion for a back is, to isolate all the development your doing, and then simply copy that directory to another directory, and you’ve got it all, and can be used to restore.

So why all this verbage, it’s faster to see what is going on in your blueprint doing it in this fashion, for the function in question, than the screen shots. When I see the screen shots, i’m always like, what the hell is happening off to the right and left! lol

Alright, I think I found my answer and I feel kind of silly now. The problem wasn’t that it didn’t get all actors. It was simply that they were too big and caused collision fails. Checking “No Collision Fail” confirmed this. It simply didn’t spawn actors on locations where the collisions would fail.

With that said, thank you for your help!

one quick question, that “no collision checkbox”? could that be preventing the spawn at certain locations? Such that if there is collision, the spawn doesn’t occur? The logic for the node option maybe inverted, but I couldn’t find any information quickly for that node,and was just wondering. As I don’t know the location, etc I mean if the level is flat, this is no issue of course, but if there are hills, or other objects at the spawn point?

Another thought, are you now checking after the spawn node, to see if the actor was truely spawned? So that some error checking code can be injected? to give some more information concerning the issue?

Hey ,

Lol, I just posted that question back to ya! Glad it’s working, and have a great day!