Announcement

Collapse
No announcement yet.

Can't set DefaultPawn in game mode

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

    Can't set DefaultPawn in game mode

    Hello. I've created a player class as AActor. I created a blueprint and set this player as parent class. In game mode class I wrote
    Code:
    static ConstructorHelpers::FObjectFinder<UBlueprint> WarriorActorBPClass(TEXT("Blueprint'/Game/Blueprints/BP_WarriorActor.BP_WarriorActor'"));
    if (WarriorActorBPClass.Object != NULL)
    {
    	DefaultPawnClass = (UClass*)WarriorActorBPClass.Object->GeneratedClass;
    }
    I set this mode in preferences in editor and I can see pawn description and controller - everything correct. I set a breakpoint in Game mode and when I start a game I see that if() statement is executed. But BeginPlay() function never called for my player, and actually I can't see player mesh when I fly around. If I place blueprint in the scene BeginPlay() fired for this instance.

    Upd.: I changed my default pawn from AActor to ADefaultPawn and now everything works. So what was the problem with Actor? Why can't I setup it as main player?
    Last edited by nikitablack; 05-13-2014, 06:01 AM.

    #2
    In this case, Object Oriented Programming requires that the DefaultPawnClass is set to a class extended from (and including) Pawn.
    Pawn is actually extended from Actor so logically it makes no sense to try and use Actor when the code is expecting a Pawn.

    Consider what would happen if you were allowed to do this. What would happen if you called a Pawn-specific function on the Pawn instance when in fact that Pawn is just an Actor?
    That Pawn-specific function would not exist. Hence, you can only use classes extended from Pawn, as they will always contain the expected functions and properties.

    Comment


      #3
      Yeah, that's right. Thank you.

      Comment

      Working...
      X