Possessing a placed pawn


Whitaker Antalek

03/24/23

When it came to setting up players and AI i knew how to accomplish this with single player. Basic AI would be manually set into the world and UE knew to control those with an AI controller over a player controller. Using the Game mode I could easily set up a default pawn to spawn into the world as the main player. This pawn would use a spawn point as its starting point. Easy enough. However, I wanted all the pawns to be placed in the world and i would possess one at the start of the game. This proved to not be as cut and dry as I believed.


The Solution:

Originally, I believed that using the level blueprint was my best option. I would get a reference to the pawn I wanted to possess and setup the possession on it. Turns out I was able to possess the pawn but none of my inputs would work! After some debugging, I figured out that the pawns were spawned in before the level blueprint was called. So, when my pawns begin play tried to set up the enhanced input local player system, it would always fail because it did not have a controller attached to it!

I was able to fix this issue by giving the main pawn two variables. A bool to check if it is AI or not and a integer to check which player it is (one - four). With these two variables I would check within the playerpawns begin play. If the pawn is not AI, possess that pawn with the proper player controller based on that pawns index. Then set up the input system. This allowed me to control whichever pawn I set to not be AI with that bool.

Files

Install Party Panic.exe 224 MB
Mar 23, 2023

Get Party Panic!

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.