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"

Help crash

I'm currently at the end of my patience with unreal:

I'm currently following a Udemy course in which they don't show the required includes so we are left to our own devices. I could go with it except every time i add an include i get the error "this declaration has no storage class or type specifier" and if I manage to get around it, (this is my current status) every time i use GetWorld()->GetPlayerController()->GetPawn() to get the player actor i get the error "pointer to incomplete class type is not allowed". The code i entered seems to be correct, but Unreal Engine still seems to crash.

For clarification purposes: GetWorld()->GetPlayerController() works; I could only get the GetPawn() after i installed Visual Assist; I'm fairly new to C++ and a complete begginer to unreal although i have dabbled in unity.

Code for the GetPawn thing:

 void UOpenDoor::BeginPlay()
 {
     Super::BeginPlay();
 
     // ...
     ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
 }

Includes:

include "CoreMinimal.h"

include "Components/ActorComponent.h"

include "Engine/TriggerVolume.h"

include "Engine/World.h"

include "GameFramework/DefaultPawn.h"

include "OpenDoor.generated.h"

Product Version: UE 4.16
Tags:
more ▼

asked Jul 10 '17 at 11:35 AM in C++ Programming

avatar image

ZeD4805
3 1 4

avatar image Ninjin Jul 10 '17 at 01:02 PM

Would it be possible to show your complete code, .cpp and .h, it's really difficult to tell otherwise <3

avatar image ZeD4805 Jul 10 '17 at 01:34 PM
 .h
 #pragma once
 
 #include "CoreMinimal.h"
 #include "Components/ActorComponent.h"
 #include "Engine/TriggerVolume.h"
 #include "Engine/World.h"
 #include "OpenDoor.generated.h"
 
 UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
 class MYPROJECT4_API UOpenDoor : public UActorComponent
 {
     GENERATED_BODY()
 
 public:    
     // Sets default values for this component's properties
     UOpenDoor();
 
 protected:
     virtual void BeginPlay() override;
 
     void OpenDoor();
 
 public:    
     virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
 
 private:
     UPROPERTY(VisibleAnywhere)
         float OpenAngle = 90.f;
         
     UPROPERTY(EditAnywhere)
         ATriggerVolume* PressurePlate;
 
     UPROPERTY(EditAnywhere)
         AActor* ActorThatOpens; //Pawn inherits Actor
 };
 

Note: I deleted some of the commets because of word count.

avatar image ZeD4805 Jul 10 '17 at 01:35 PM
 .cpp
 #include "OpenDoor.h"
 #include "GameFramework/PlayerController.h"
 
 // Sets default values for this component's properties
 UOpenDoor::UOpenDoor()
 {
     // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
     // off to improve performance if you don't need them.
     PrimaryComponentTick.bCanEverTick = true;
 
     // ...
 }
 

 void UOpenDoor::BeginPlay()
 {
     Super::BeginPlay();
 
     // ...
     if (GetWorld()->GetFirstPlayerController()->GetPawn())
         ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
 }
 
 void UOpenDoor::OpenDoor()
 {
     AActor* Owner = GetOwner();
 
     FRotator NewRotation = FRotator(0.0f, -60.0f, 0.0f);
 
     Owner->SetActorRotation(NewRotation);
 }
 
 
 // Called every frame
 void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
 {
     Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
 
     if (PressurePlate->IsOverlappingActor(ActorThatOpens) == true) {
         OpenDoor();
     }
     // ...
 }
 
 
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

First what type of object is UOpenDoor from the looks of it it's an UObject but it probably should be an actor ie. AOpenDoor. If it's an uobject GetWorld() probably returns a nullptr which cases a crash. Always make sure to check that a pointer is valid before accessing it in c++.

more ▼

answered Jul 10 '17 at 11:50 AM

avatar image

MatzeOGH
591 21 11 32

avatar image ZeD4805 Jul 10 '17 at 12:21 PM

That mistake is obviously a newbie mistake XD, i neglected the nullptr EDIT: changed some stuff including that but it still crashes

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hey, luckily I had the same problem. You just need to include GameFramwork/PlayerController.h The last answer from Kalash61 from this thread shows everything you need to include. Would be great to hear if that work out for you! <3

more ▼

answered Jul 10 '17 at 12:11 PM

avatar image

Ninjin
4.2k 88 38 152

avatar image ZeD4805 Jul 10 '17 at 12:23 PM

I'm currently trying it out. But how do you fix the include line thingy? By which i mean "this declaration has no storage class or type specifier" which seems to be related to the UClass placement EDIT: Still doesn't work, still crashes

avatar image Ninjin Jul 10 '17 at 03:01 PM

Do you mean it compiles, but it crashes when you hit the Play Button? If yes, did you make sure to give your pawn class a reference to trigger object in the world? Also, you don't need to ask for IsOverlappingActor(ActorThatOpens) == true; you can safely remove the "== is true".

avatar image ZeD4805 Jul 10 '17 at 10:35 PM

it compiles but crashes on play, I'm a little rusty on C/C++ (I need to practice more :p), what do you mean by giving the pawn class a reference to the trigger object? what I'm doing is checking the trigger volume for the presence of the player pawn, so I don't think I have to mess with the player pawn...

avatar image Ninjin Jul 11 '17 at 02:38 AM

I'm sorry, I mean your Opendoor class. You have a representation of it in the World, right? Did you make sure when clicking on it to give it a reference to your Collision Box (which is also somewhere in the World)? <3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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