Announcement

Collapse
No announcement yet.

In Level Blueprint, how to create references to Actors spawned at runtime?

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

    In Level Blueprint, how to create references to Actors spawned at runtime?

    I have a GameMode that spawns different (1-4) controllable characters at runtime. I would like to use the Level Blueprint to switch pawn possession using hotkeys (1-4 for example) like in this tutorial.

    How can I instruct it to search for characters, add them to a list/array of references, and then enable the hotkey swap like in the tutorial?

    Thanks in advance.
    PORTFOLIO

    #2
    There is the GetAllActors of class node, but if you are spawning them just put them in your list right after they spawn. The reference to the new actor is a pin on the output of the spawn actor node, then add that to your list.

    Comment


      #3
      If you spawn the Characters, you don't need the LevelBlueprint.
      Like [MENTION=75]mikepurvis[/MENTION] said, save the actors into a list (Array) directly after spawning.
      Then you can setup a simple switch Pawn system in your "PlayerController" that just
      gets the Array from the GameMode.

      Normally, you don't need the LevelBlueprint/GetAllActorsOfClassNode in your game.
      If you use it, you should think about a proper way to (which is what you do with this thread, so thumbs up!)
      Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

      My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
      (Including 100+ Pages Multiplayer Network Compendium to get you started.)

      Comment


        #4
        Hi guys,
        thank you both for answering, and sorry for this late reply.
        I've been trying not to use the Level Blueprint, as you suggested, but I'm not being able to figure out how to make this list/array, could you guys show me an example?
        Thanks in advance.
        PORTFOLIO

        Comment


          #5
          You said you spawn your Characters in your GameMode.
          Each "SpawnActor" node should have a Return Value.

          Create an Array of type "Pawn (Reference)" and add the return value of the "SpawnActor" node
          to it. Then it will (in theory), have 4 entries in the exact same order as you added them.

          Then you can always use "GetGameMode->PAWNARRAY (What ever name you gave it)" and
          use "Get" on it with a number from 0-3 (programming starts counting at 0, not 1! And you said you have 4 Characters).

          This will then give you one of the 4 spawned pawns that you can call "Possess" on. So no need
          for the LevelBlueprint.
          Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

          My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
          (Including 100+ Pages Multiplayer Network Compendium to get you started.)

          Comment


            #6
            Originally posted by eXi View Post
            You said you spawn your Characters in your GameMode.
            Each "SpawnActor" node should have a Return Value.

            Create an Array of type "Pawn (Reference)" and add the return value of the "SpawnActor" node
            to it. Then it will (in theory), have 4 entries in the exact same order as you added them.

            Then you can always use "GetGameMode->PAWNARRAY (What ever name you gave it)" and
            use "Get" on it with a number from 0-3 (programming starts counting at 0, not 1! And you said you have 4 Characters).

            This will then give you one of the 4 spawned pawns that you can call "Possess" on. So no need
            for the LevelBlueprint.
            Hi eXi, I was able to make it work in the end. Thank you very much for the assistance!
            PORTFOLIO

            Comment


              #7
              Originally posted by Klawd3 View Post
              Hi eXi, I was able to make it work in the end. Thank you very much for the assistance!
              Awesome! (:
              Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

              My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
              (Including 100+ Pages Multiplayer Network Compendium to get you started.)

              Comment

              Working...
              X