Announcement

Collapse
No announcement yet.

GetAllActorsOfClass function not working on Construction Script Third person Game Mode

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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.
    Click image for larger version

Name:	totalNumofpickableFunction.png
Views:	1
Size:	283.1 KB
ID:	1209335
    In the construction Script I get totals or all types of Pickables
    Click image for larger version

Name:	COnstructionScript.png
Views:	1
Size:	346.4 KB
ID:	1209336

    In Event Graph of ThirPersonGameMode I added the test:
    Click image for larger version

Name:	test.png
Views:	1
Size:	301.2 KB
ID:	1209337

    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!

    #2
    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.
    @CarstenZarbock - Follow me on Twitter, thank you

    Comment


      #3
      Originally posted by pyrobit View Post
      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.
      [ATTACH=CONFIG]129045[/ATTACH
      In the construction Script I get totals or all types of Pickables
      [ATTACH=CONFIG]129046[/ATTACH
      In Event Graph of ThirPersonGameMode I added the test:
      [ATTACH=CONFIG]129047[/ATTACH

      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!
      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...

      Comment


        #4
        Originally posted by Name368 View Post
        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.
        @CarstenZarbock - Follow me on Twitter, thank you

        Comment


          #5
          Originally posted by KrautPotato View Post
          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:

          So what this does is when a Construction Script fires off, it'll get every single instance of an actor that is that blue pickup, put it in an array. We hit the length of the array which is basically how many objects are in that array, and we set that to the total number of blue pickups. Now, when you do the same thing again for the pink, but there's a really nifty thing you can do to keep you blueprints organized. I can drag off of this Construction Script which is already connected and type in seq to search for a sequence and then it automatically inserts a sequence node in here. Now, what a sequence node does is really straightforward. Any time you have an input come into it, it will then in sequence go and execute every single output. So the first thing it'll do is do everything for the blue, we're going to take this node, right-click on it, and actually click Duplicate. We haven't used that before but basically the same as copy-pasting. Drag this down, we're going to change this to actually in search for pink, p-i-n-k, and make this the BP_pickup_child_pink, so it'll search for all the pink child actors for the pickups, drag this out, get the length. And then, we need to set our total pink pickups, and there we have it. We got all of our pink and all our blue. Now, to show you kind of how this works, click Compile and Save. We're going to do a little bit of it a event, basically, a debug thing that we're going to just use for this lesson and then discard, just to show you how this Construction Script is working. So we go into our EventGraph, and just kind of come above where we've done our collected pickups event. If we right-click and search for begin, we should be able to find a Event Begin Play right here at the bottom. So zoom into that. So what we're actually going to do is really quick do a Print String and what we're going to do is, and we'll only need to do this for the one variable.
          And in the video it looks like it is working fine.

          Comment


            #6
            I tested moving the script from 'construction script' to Event BeginPlay in 'Event Graph' and it is now working. Thanks a lot!
            Last edited by pyrobit; 02-11-2017, 02:33 PM.

            Comment


              #7
              Originally posted by Name368 View Post
              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...

              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!

              Comment

              Working...
              X