GetAllActorsOfClass function not working on Construction Script Third person Game Mode

Hi,
This is from a pluralsight tutorial I am trying to figure out:
I have been struggling with this for some weeks, would like to check if is there something I am missing.
I want to get total of all pickable objects for each pickable type in a game level.

I have a base blueprint class for pickable objects and three types of pickable instances Blue, Pink and Key.
Defined a gunction to Get total Number of Pickables with variables TotalBluePickups, TotalKeyPickups, TotalPinkPickups.


In the construction Script I get totals or all types of Pickables

In Event Graph of ThirPersonGameMode I added the test:

I already checked all intances of the pickable blueprints in the level, are indeed blueprints child of pickup base class. But somehow the construction script is not properly updating the variable after running GetAllActorsOfClass function.
Any ideas of what might be happening?

Thanks!

The GameMode Constructor is most likely called before the map is loaded and / or the actors are setup.

This won’t work.

You could print the values in the contructor - they will be 0.

AFAIK:
construction script is for editor, not for gameplay needs (but im unsure)
i read somewhere that construction script is launched everytime you move with actor in editor or something like that… so i recommend you to move all logic to event graph…

The construction script / constructor is called when the game object (e.g. the actor, the game mode, etc) is getting created.
The game mode object will most likely be created before all other actors (not sure about that) - so the KeyPickup Actors are not there yet.

You shouldn’t access other objects in the constructor. The constructor should be used carefully with only class interna needed stuff.

You probably want to use BeginPlay in the Level Blueprint or Begin Play in the Game Mode Blueprint.

Hi Thanks for the response.
The tutorial used Unreal engine 4.3 version and I am using the 4.14 I am not sure if this was changed, but in the text version of the tutorial you can read the following:

And in the video it looks like it is working fine.

I tested moving the script from ‘construction script’ to Event BeginPlay in ‘Event Graph’ and it is now working. Thanks a lot! :slight_smile:

Indeed this is also bugging me, Because in the editor I have all Blueprints pickups placed, so it should work in the construction script. The tutorial I was following was made with UE4.3 and I am using 4.14, maybe the changed something regarding the construction script features, will check if I find something.
Thanks for the reply!