How to get default pawn class from level blueprint?

Hi all,

I have to reference my DefaultPawnClass, set in the game mode, in my level blueprint.

I tried “GetGameMode → GetDefaultPawnClass” but it seems to return an instance of the class and not an object of that class.

Any ideas please?

Am i missing something?

Thanks in advance

Are you trying to get the players Pawn? The DefaultPawnClass is just that, the class used to spawn new Pawns by default.

Hey, well there’s two ways I know of;

GetPlayerPawn (which should be in your favorites section)

5696-getplayerpawn.jpg

Or casting to the character:

5697-casttocharacter.jpg

Hope this helps!

The best way is to create a child class from ALevelScriptActor and add this into it:

	/** The default character class used by players on this team. */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Classes)
		TSubclassOf<class ACharacter>  DefaultCharacterClass;

Then open the level blueprint and reparent that blueprint with your new child class. Then you need to override the GetDefaultPawnClassForController function in your custom AGameMode class. Then in that function access the instance of your level using the Singleton pattern or however you choose to accomplish it and then return the DefaultCharacterClass attribute from that.

If you need more help, shoot me a message, but this is what we do in Black Sand Studio’s World at War.