Announcement

Collapse
No announcement yet.

Error with possessing player character in some levels

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

    Error with possessing player character in some levels

    Hi,

    I made these blueprints to spawn the correct character class blueprint and then possess it. It worked in all the levels I had but now when I create a new level it doesn't work. When I call on the player character to do something after this code I get the error "Attempted to access Sorcerer_BP_C1 via property x but Sorcerer_BP_C1 is pending kill from function". This only happens in new levels that i create and in my existing levels it works. I don't get how this error can be level-based.

    I tested the nodes through print strings and all seems to be happening correctly. The print string that can be seen in the screenshot, that prints the player character after the possess returns the correct name, so the class selection is happening correctly.

    I thought it would be a problem with the DestroyActor node that destroys the playercharacter, so the player controller gets destroyed and the possess node cannot call it anymore, but that doesn't seem to be the case, the controller doesn't get destroyed with the DestroyActor node, and it's working in my existing levels so it must be working correctly.

    Any ideas why I get the error "Sorcerer_BP is pending kill" ?

    Thanks in advance!

    Click image for larger version

Name:	Possess.png
Views:	1
Size:	281.9 KB
ID:	1213707
    Creative Director at Rebel Camp Games

    http://www.rebelcampgames.com
    http://www.forestsofaugusta.com
    http://www.emberheartgame.com

    #2
    - Which class is your default pawn class in your GameMode? (Maybe the error is not exactly related to the new spawned actor, but the default class that is already in the game)

    - Is there any Character/Pawn already spawned in the level with Aut Receive Input set?

    - This same message occurs when you wish to spawn a Warrior?


    I know this doesn't make much sense if this was effectively working in your previous level, but that was my first thoughts after reading from your code.
    Maybe you should dig into the difference between each maps.

    Comment


      #3
      - The default class is Sorcerer_BP

      - There are no characters/pawn in the level. The level is just empty. Well technically, it spawns the default class that's set in the gamemode, and the whole purpose of my code is to destroy the default character that spawns and replace it with the correct class's character blueprint. But the default character that got spawned is set to auto receive input "disabled"

      - Yes the same message occurs when trying to load a warrior. Then the error becomes "Attempted to access Warrior_BP_C0 via property x but Warrior_BP_C0 is pending kill from function".

      - I looked at the differences between the levels but I can't find much. Only that the new level has PlayerStart and the old levels have NetworkPlayerStart. Don't know if that makes a difference?
      Creative Director at Rebel Camp Games

      http://www.rebelcampgames.com
      http://www.forestsofaugusta.com
      http://www.emberheartgame.com

      Comment


        #4
        i think u should do it this way.
        Make a gameInstance-> make a variable type integer, then if u chose Sorc->, set the integer to 1, warrior to 2.
        Make an array of default Pawn class or pawn class, then expand its, add all your Character Class in it. Then u can come to GameMode and set in the Event begin play, cast to GameInstance, if Inter=1-> SetDefaultPawnClass = the class in the array that u chose, in this example, it is Sorc. Bump, it was done. Dont Try to destroy the default pawn class and spawn your class.
        Sorry, u should put the SetDefaultPawnClass in Constructor, not in begin play event, edit
        https://www.youtube.com/watch?v=3Dt9...ature=youtu.be here i made a quick clip to show u how its done.
        Last edited by HienNguyen27; 03-25-2017, 01:09 PM.

        Comment


          #5
          cool thanks for the movie! I will take a look at it further. It is indeed a bit nasty to destroy the default pawn and respawn the correct class. But anyway I'm going out now, it will have to wait till tomorrow
          Creative Director at Rebel Camp Games

          http://www.rebelcampgames.com
          http://www.forestsofaugusta.com
          http://www.emberheartgame.com

          Comment


            #6
            Ok it works now! I ended up taking the class name from my savegame and do a switch string on those and then just set default pawn class. all in the construction script of the game mode

            Thanks again! really appreciate you making a movie clip!

            Click image for larger version

Name:	PosessError.png
Views:	1
Size:	177.7 KB
ID:	1125194
            Creative Director at Rebel Camp Games

            http://www.rebelcampgames.com
            http://www.forestsofaugusta.com
            http://www.emberheartgame.com

            Comment


              #7
              I created a video as well on this but I'm using an enum and the Gamemode override for default class this is useful as the construction method is called once when a level is loaded and if you wanted to change your class mid level and reset the player as that, you'd likely need extra code and restarting the level completely.

              The override is called everytime you reset the player

              https://youtu.be/O7FFRqb8T6o
              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


                #8
                Originally posted by Inph1del View Post
                I created a video as well on this but I'm using an enum and the Gamemode override for default class this is useful as the construction method is called once when a level is loaded and if you wanted to change your class mid level and reset the player as that, you'd likely need extra code and restarting the level completely.

                The override is called everytime you reset the player

                https://youtu.be/O7FFRqb8T6o
                Cool, thanks! That seems to be a good way to handle things, I will take a look at it, because my current solution still has some problems going on.

                Edit: Got it working flawlessly by using your method. Thanks alot! And thanks for the movie, I love this UE community so much
                Last edited by Rebel Camp Games; 03-28-2017, 05:21 AM.
                Creative Director at Rebel Camp Games

                http://www.rebelcampgames.com
                http://www.forestsofaugusta.com
                http://www.emberheartgame.com

                Comment

                Working...
                X