Possess Pawn Doesn't Work - What Am I Doing Wrong?
Hi there, wanted to make a system where you can switch between different play styles. I used the TopDownCharacter Template and wanted to make it so that you can press tab and then you would possess this character because by default I want to use the DefaultPawn. Later there would be several pawns to chose from, however I can't get this possessing issue running..
Despite having it like the picture above shows, when I enter the game and hit tab which is represented by "InputAction ChangeMode" nothing happens and I don't understand why..?
Can anyone help, why can't I possess the desired pawn like that, what am I missing?
Thanks a lot for your help!
asked Apr 15 '16 at 07:36 AM in Blueprint Scripting
Finally! Well as I was suspecting I was missing a crucial node..
Apparently it is mandatory to get your "In Pawn" with a "Get All Actors Of Class" Array Node. Doesn't make sense to me but well, it is what you have to do and then it works :)
answered Apr 16 '16 at 10:03 PM
Well, I don't really want to let this standing without adding information.
It is not. Your Code didn't work, because your "TopDownPawnReference" was empty (at least I think it was). A blue Reference variable is not the same as an Integer or Boolean Variable. It's empty if you don't fill it. In C++, this is called a Pointer and you need to understand how this works. Otherwise you will run into these problems every time.
Also, "GetAllActorsOfClass" is an expensive and lazy node. You need to setup a way where you spawn your Pawns and save the Reference to them which you can later access. Since you use the PlayerController as a central point for switching Pawns, you should use it to Spawn and Save references.
What is a Reference and why are the Blue nodes Empty (Accessed None)
References or Pointers are Variables that are pointing to ONE instance of an Actor in your Game. Simple example:
You have 10 Pawns spawns in your Game, you can save a Reference to ONE of them in these Variables. If you don't save one into the Variable, it will be empty. From where should the variable know what Pawn you meant?
So you need to learn how to efficiently reference your Actors/Objects. For this, I can recommend you to watch this Stream Recap:
Watch it and rework your logic. "GetAllActorsOfClass" is not the way to go! If you have multiple Pawns in your Levels, this node will return all of them and you can't even make out which one is which, since they are not really ordered in that Array you get their.
Also if you don't have a Pawn in your Level, this Node will return an Empty Array.
Try to connect "Get player controller" to the target input.
answered Apr 15 '16 at 11:38 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here