Announcement

Collapse
No announcement yet.

Respawning Actor on Player Death

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

    Respawning Actor on Player Death

    A problem I'm having right now, is trying to respawn an actor after jumping on top of it, and destroying it 'mario style'. After the player dies, I can't seem to figure out how to respawn the actor back into the game.

    For example after collecting a checkpoint, I destroy an actor soon after. After destroying the actor I die, thus spawning back at the previous checkpoint. For some reason after respawning, the actor that was destroyed, stays dead.

    This is probably a dumb question, but any help would be appreciated thank you!


    Actor
    Click image for larger version

Name:	actor.png
Views:	1
Size:	179.7 KB
ID:	1209161

    Player
    Click image for larger version

Name:	player.png
Views:	1
Size:	167.8 KB
ID:	1209162

    #2
    When you destroy an actor that instance of code is gone.

    You'd need to spawn another one with spawn actor from class.

    If you want the world actors to respawn you may want to reload the map or go through a system of checks to respawn the actors.
    Inphidel / Brian - Developer of Ultraball
    http://www.ultraballgame.com

    Don't shy away from bugs in your game. Don't play it as intended. Break your game so you can fix it!

    Comment


      #3
      How would that look in the blueprints? Would it just be beginoverlap -> cast to sidescrollercharacter -> spawn actor along with a player controller?

      Thanks for the reply.

      Comment


        #4
        Are you having trouble respawning the player or the actors which the player is killing?

        If you want to respawn the player, then you would need to 'destroy' it, create a new instance using the 'spawn actor from class' node, and then 'possess', so it can be controlled.

        If you want to respawn the actors which the player is killing, then you have two easier methods which you can take (that I see anyways)
        1) When an actor is 'killed' by the player, just hide it and turn off collisions until its ready to 'respawn'. At that point, make it visible again and reenable collisions.
        2) Maintain an array or map of where the actors are supposed to spawn and also which type of actor is supposed to spawn. Then you can use this data to respawn the right type of actor using 'spawn actor from class' and settings its 'transform' using the data from the array/map

        Hopefully this helps, but I'm not sure I fully understand what you are trying to do.
        The guy that makes the wheels turn..

        Comment


          #5
          I want to respawn the actor that the player is killing. Option 1 seems to be the easiest, but I'm not sure how to go about it. Thanks for the reply.

          Comment


            #6
            I believe the nodes you are looking for are 'Set Visibility' and 'Set Actor Enable Collision'. I'm not currently near a computer with Unreal Engine on it, so I can't confirm that for you.

            You could probably hook these up to your begin overlap event and your respawn event.
            The guy that makes the wheels turn..

            Comment


              #7
              Your suggestion was spot on for the actor disappearing. Thank you for the help and patience. It's just getting it to reappear after the player dies that I am unsure of. Sorry for my lack of knowledge. Here are my connections.

              Actor Blueprints
              Click image for larger version

Name:	actor.png
Views:	1
Size:	223.2 KB
ID:	1122769

              Player Blueprints
              Click image for larger version

Name:	player.png
Views:	1
Size:	188.9 KB
ID:	1122768

              Comment


                #8
                The way I would approach this would be to create an array of actors in your game mode blueprint. In the construction script of your actors (or event onBeginPlay), I would suggest adding a reference to that actor into the array in your game mode. Then, when your player dies and respawns, you can trigger an event or function in your game mode called something like 'resetMap', and in here you can loop through each item in the array. As you loop through each item, call 'Set Visibility' and 'Set Actor Enable Collision' for each one.

                Does this make sense? I'm not sure if I explained it very well.
                The guy that makes the wheels turn..

                Comment


                  #9
                  Kind of, but I could definitely use a visual if you get the chance.

                  Comment


                    #10
                    I'm not near a PC equipped with Unreal right now, but I can try and visualize it a bit with text:

                    On your gamemode, create an array variable of type 'Actor'. For this example, I'll call this array variable 'arrActors'

                    Additionally, in your gamemode blueprint, create a custom event which I'll call 'ResetMap'. Add the follow sequence of nodes:
                    'Get arrActors' -> 'For Each Loop' and on the 'Array Element' pin of the 'For Each Loop' connect a 'Set Visibility' node and a 'Set Actor Enable Collision' node.

                    In your 'Actor' blueprints, off of event onBeginPlay, add the following sequence of nodes:
                    'Get Gamemode' -> 'Get arrActors' -> 'Add' node. As well, the add node should have a second pin representing what you want to add into the array. I can't remember if this defaults to 'self' but if it does, you're golden. If not, you will need to use a 'self' node and plug that in.

                    When your character respawns, add the additional sequence of nodes:
                    'Get Gamemode' -> 'ResetMap'
                    The guy that makes the wheels turn..

                    Comment


                      #11
                      I ran into a couple issues when trying to connect the get game mode and when trying to connect the array element unfortunately.

                      GameMode Blueprints
                      Click image for larger version

Name:	actor connect.png
Views:	1
Size:	232.1 KB
ID:	1122771

                      Actor Blueprints
                      Click image for larger version

Name:	game mode connect.png
Views:	1
Size:	172.0 KB
ID:	1122772

                      Comment


                        #12
                        Ah! That's my fault for forgetting to mention: You have to cast your game mode to your custom game mode blueprint. The node will be something like 'Cast to <insert_your_gamemode_blueprint_name_here>' then you should have better luck! Also, in your first screenshot, your 'Set Actor Collision' node should work fine because it's expecting an input type of 'Actor'. You can see what it's expecting as an input in the italicized text under the node name. The reason 'Set Visibility' isn't working is because that specific node is expecting a scene component. To make this work, you need to 'Get Static Mesh' from your actor and use that to plug it into 'Set Visiblity'.

                        This screenshot of yours actually did it right in a different event, so you can check it for more details on what I mean: https://forums.unrealengine.com/atta...7&d=1486587923

                        Hopefully this helps you finish it up!
                        The guy that makes the wheels turn..

                        Comment


                          #13
                          These are my connections. I tried to get a reference to my actor by using 'Get Static Mesh' for the gamemode blueprints, but no luck. Instead I tried a 'Cast to', but no change.

                          GameMode Blueprints

                          Click image for larger version

Name:	GameMode.png
Views:	1
Size:	271.9 KB
ID:	1122807

                          Actor Blueprints

                          Click image for larger version

Name:	Actor.png
Views:	1
Size:	331.9 KB
ID:	1122808

                          Comment


                            #14
                            I think most of your problem lies here:
                            Click image for larger version

Name:	6aa21244fc201728d543d4c294cbaa51.png
Views:	1
Size:	46.1 KB
ID:	1122809


                            You only want to call 'Reset Map' when your player dies. Or, in other words, after the 'DestroyActor' node in your PlayerDies commented area.

                            The other problem is that you aren't actually adding anything into your array of actors. The bottom input on the add node needs to have a 'self' node attached to it.

                            This is a screenshot from an unrelated thread which shows what I mean: Click image for larger version

Name:	21710-bp_2.png
Views:	1
Size:	129.0 KB
ID:	1122810
                            The guy that makes the wheels turn..

                            Comment


                              #15
                              I'm getting the same target error from before when I disconnect the 'Cast to'.

                              Click image for larger version

Name:	Actor.png
Views:	1
Size:	386.9 KB
ID:	1122826

                              Comment

                              Working...
                              X