[Mono-ue] How to set the Default Player Character in Game Mode
Michael Hutchinson
m.j.hutchinson at gmail.com
Wed Dec 31 11:48:47 UTC 2014
I think you want something like:
var finder = new ClassFinder<Pawn>();
finder.Initialize("/Game/Blueprints/PlayerCharacter.PlayerCharacter");
DefaultPawnClass = finder.Class;
You can find examples of this kind of stuff in our C# port of the
ShooterGame sample, see e.g.
Source/ShooterGameMono/Online/MonoShooterGameMode.cs
- m
On 31 December 2014 at 11:18, Ryan Burnham <nitro52 at iinet.net.au> wrote:
> Hi All,
>
> So I thought I would try to go through the Gettings Started: Introduction to
> UE4 Programming tutorial
> (http://www.youtube.com/playlist?list=PLZlv_N0_O1gb5xvsc7VM7pfoRAKLuIcFi)
> and convert it to C# using Mono of UE.
>
> This required me to convert the PlayerCharacter to c#. I’ve gone through and
> done this but I’m trying to figure out now how to set it up as the default
> player character. Basing it on this tutorial
> https://wiki.unrealengine.com/First_Person_Shooter_C%2B%2B_Tutorial I can
> see you need to setup a new game mode in code and then initialise the
> DefaultPlayerPawn to the blueprint inherited from the custom
> PlayerCharacter. In C++ it looks like this
>
>
>
>
>
> AFPSGameMode::AFPSGameMode(const class FPostConstructInitializeProperties&
> PCIP)
>
> : Super(PCIP)
>
> {
>
> // set default pawn class to our Blueprinted character
>
> static ConstructorHelpers::FObjectFinder<UBlueprint>
> PlayerPawnObject(TEXT("Blueprint'/Game/Blueprints/BP_FPSCharacter.BP_FPSCharacter'"));
>
> if (PlayerPawnObject.Object != NULL)
>
> {
>
> DefaultPawnClass =
> (UClass*)PlayerPawnObject.Object->GeneratedClass;
>
> }
>
> }
>
>
>
> I’m no C++ expert so I’m not sure if I am missing something but I can’t
> figure out how to convert this in the C# Mono for UE equivalent. So far I
> have this
>
>
>
> public class CSharpGameMode : GameMode
> {
> // Constructor called when creating or loading an object
> protected CSharpGameMode(PostConstructInitializeProperties pcip) :
> base(pcip)
> {
> var playerPawnObject = new ObjectFinder<Blueprint>();
>
> playerPawnObject.Initialize("Blueprint'/Game/Blueprints/PlayerCharacter.PlayerCharacter'");
>
> if (playerPawnObject.Object != null)
> {
> DefaultPawnClass = //<------- How do i get SubclassOf
> <Pawn> from the ObjectFinder;
> }
> }
>
> // Constructor for hot-reloading. UProperties will already be
> initialized, but any purely managed fields or data
> // will need to be set up
> protected CSharpGameMode(IntPtr nativeObject) : base(nativeObject)
> {
>
> }
> }
>
>
>
>
> _______________________________________________
> Mono-ue mailing list
> Mono-ue at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-ue
>
--
Michael Hutchinson ~ https://mhut.ch
More information about the Mono-ue
mailing list