"Get All Actors of Class" return null sometimes

Hi guys, I found the node “Get All Actors of Class” may return null sometimes, even if the matched actor is always stay in level, and i promise i didn’t have blueprint to change my target actor.

I think the possible reason is “Traget Actor isn’t exist”
In my case, the target actor is placed in level and i doesn’t be destroyed at some time.
Also, in the debug log,
at first “Get All Actors of Class” works,
at some time “Get All Actors of Class” doesn’t work,
after that, “Get All Actors of Class” works again.
So it manifests that my Target Actor exists along the way.

It confused me because it seems like a ghost, sometimes appear but sometimes dont. I wonder why it happened and how can i aviod it? Thanks a lot!

In my deemo, I use “Get All Actors of Class” in BP_Slime and i want to get a actor which class is BP_Judger.
And here is my testing print and debug log.

Image1 BP_Slime

Image2 Debug Log

351052-33.png

Image3 World Outliner

LogBlueprintUserMessages: [BP_Slime_Parent13] 1
LogBlueprintUserMessages: [BP_Slime_Parent12] 1
LogBlueprintUserMessages: [BP_Slime_Parent11] 1
LogBlueprintUserMessages: [BP_Slime_Parent10_25] 1
LogBlueprintUserMessages: [BP_Slime_Parent_C_19] 0
LogScript: Warning: Script Msg: Attempted to access index 0 from array ‘CallFunc_GetAllActorsOfClass_OutActors’ of length 0 in ‘/Game/LianJiaCheng/Blueprint/Slime/BP_Slime_Parent.BP_Slime_Parent_C:UserConstructionScript’!
LogBlueprintUserMessages: [BP_Slime_Parent_C_0] 0
LogScript: Warning: Script Msg: Attempted to access index 0 from array ‘CallFunc_GetAllActorsOfClass_OutActors’ of length 0 in ‘/Game/LianJiaCheng/Blueprint/Slime/BP_Slime_Parent.BP_Slime_Parent_C:UserConstructionScript’!
LogBlueprintUserMessages: [BP_Slime_Parent_C_0] 0
LogScript: Warning: Script Msg: Attempted to access index 0 from array ‘CallFunc_GetAllActorsOfClass_OutActors’ of length 0 in ‘/Game/LianJiaCheng/Blueprint/Slime/BP_Slime_Parent.BP_Slime_Parent_C:UserConstructionScript’!
LogBlueprintUserMessages: [BP_Slime_Parent4] 1
LogBlueprintUserMessages: [BP_Slime_Parent3_8] 1
LogBlueprintUserMessages: [BP_Slime_Parent2_5] 1
LogBlueprintUserMessages: [BP_Slime_Parent20] 1
LogBlueprintUserMessages: [BP_Slime_Parent_2] 1

Debug Log

Is there any reason you need to do a Get All Actors of Class so often? It looks in the log like it is happening very frequently. I suggest caching the Actor (especially if it is just sitting in the level) and then referencing it later where needed. Also might I suggest the Get Actor of Class function which just returns the first actor of a particular target class.

Could you not use ‘isvalid’ node after Get(copy) so it only executes if a valid entry is returned?

Are you calling this from tick?
I think this happens when you try to GetAlActorsFromClass before the last GetAllActorsFromClass has completed.

1 Like