x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do i possess a pawn with playercontroller?

I am new to the engine and fairly new to C++ and I have been trying to find out how to do this but I cannot figure it out or find any tutorials on it so I thought I'd try asking here.

Product Version: Not Selected
Tags:
more ▼

asked May 05 '15 at 07:47 PM in C++ Programming

avatar image

Dead_Cat
6 2 5 3

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

Code:

 AController *MyPlayerController;
 // It can be your character too. Since the ACharacter class inherits from APawn
 APawn *MyPawn; 
 MyPlayerController->Possess(MyPawn);

Wiki page link:

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AController/Possess/index.html

I hope it helps! Cheers! :)

more ▼

answered May 05 '15 at 07:59 PM

avatar image

Azarus
1.9k 59 50 189

avatar image Dead_Cat May 05 '15 at 08:25 PM

Thanks for the reply.

Where would you call this? (In the gamemode?) And what if you eg. wanted to make a custom character or pawn class and a custom playercontroller class and then use them?

avatar image Azarus May 05 '15 at 08:38 PM

You can call this anywhere where you need it. Its useful when you want to make a simple respawn logic or so. I am not sure about your second question what you're asking exactly but you definitely should make your own Character / Pawn classes for your pawns. Inhertied from the ACharacter or from the APawn. The difference is that, if you use the ACharacter you get a MovementComponent for your Character.

avatar image Dead_Cat May 06 '15 at 02:10 PM

I mean if you add code to project and then click playercontroller or pawn/character would you just do it like this?

 AMyCustomController *MyPlayerController;
 AMyCustomPawn *MyPawn;
 
 MyPlayerController->Possess(MyPawn);

Also I tried:

H:

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #pragma once
 
 #include "GameFramework/GameMode.h"
 #include "ControllerTestGameMode.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class CONTROLLERTEST_API AControllerTestGameMode : public AGameMode
 {
     GENERATED_BODY()
 
         AControllerTestGameMode(const class FObjectInitializer & ObjectInitializer);
 
     virtual void BeginPlay() override;
 
 public:
     AController *MyPlayerController;
     APawn *MyPawn;
 };
 

CPP:

  // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "ControllerTest.h"
 #include "ControllerTestGameMode.h"
 
 AControllerTestGameMode::AControllerTestGameMode(const class FObjectInitializer & ObjectInitializer)
     :Super(ObjectInitializer)
 {
 
 }
 
 void AControllerTestGameMode::BeginPlay()
 {
     Super::BeginPlay();
 
     MyPlayerController->Possess(MyPawn);
 }
 

And it crashed when i started playing.

avatar image Azarus May 06 '15 at 04:13 PM

The problem is that you're not setting the

  AMyCustomController *MyPlayerController;
  AMyCustomPawn *MyPawn;

variables, i just put them into my code so you know their types.

If you're new to C++ i recommend to try this first: https://wiki.unrealengine.com/Entry_Level_Guide_to_UE4_C%2B%2B

Then step by step learn the language

avatar image Dead_Cat May 06 '15 at 04:36 PM

What would you set them to?

avatar image Azarus May 06 '15 at 07:26 PM

You need to get an instance of your Controller and Pawn

avatar image Dead_Cat May 06 '15 at 07:39 PM

How would you do that?

(comments are locked)
10|2000 characters needed characters left
more ▼

answered May 05 '15 at 07:49 PM

avatar image

Achilleon
767 38 33 69

avatar image Dead_Cat May 05 '15 at 07:51 PM

Thanks for the reply. I have looked at this, but I want to do it in C++.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question