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"

Blueprint class derived from C++ class keeps getting invalidated at startup

I think this may be an engine bug but it could be my code.

I have created a APlayerCamera in C++ and try to derive a blueprint class from it. This works fine, however, everytime I restart the editor the blueprint class is 'invalid' and when I try to open it the editor sometimes crashes.

Editor message on opening blueprint:

Blueprint could not be loaded because it derives from an invalid class. Check to make sure the parent class for this blueprint hasn't been removed! Do you want to continue (it can crash the editor)?

Download Logs

playercamera.h

 #pragma once
 
 #include "CoreMinimal.h"
 #include "GameFramework/Pawn.h"
 #include "PlayerCamera.generated.h"
 
 class UCameraComponent;
 class USpringArmComponent;
 
 UCLASS()
 class APlayerCamera : public APawn
 {
     GENERATED_BODY()
 
 public:
     // Sets default values for this pawn's properties
     APlayerCamera();
 
 protected:
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
 
 private:
     UPROPERTY(EditDefaultsOnly, Category="Movement")
     float CameraMoveSpeed = 1.0f;
 
     UPROPERTY(EditDefaultsOnly, Category = "Movement")
     float CameraZoomSpeed = 10.0f;
 
     UPROPERTY(EditDefaultsOnly, Category = "Camera")
     USceneComponent *Root = nullptr;
 
     UPROPERTY(EditDefaultsOnly, Category = "Camera")
     USpringArmComponent *SpringArmComponent = nullptr;
 
     UPROPERTY(EditDefaultsOnly, Category = "Camera")
     UCameraComponent *CameraComponent = nullptr;
 
     float ReferenceMouseX = 0.0f;
     float ReferenceMouseY = 0.0f;
 
 public:
     // Called every frame
     virtual void Tick(float DeltaTime) override;
 
     // Called to bind functionality to input
     virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
 
     UFUNCTION(BlueprintCallable, Category = "Movement")
     void MoveAround(float mouseX, float mouseY);
 
     UFUNCTION(BlueprintCallable, Category = "Movement")
     void MoveForward(float speed);
 
     UFUNCTION(BlueprintCallable, Category = "Movement")
     void MoveSideways(float speed);
 
     UFUNCTION(BlueprintCallable, Category = "Movement")
     void SetReferenceMouseXY(float mouseX, float mouseY);
 
     UFUNCTION(BlueprintCallable, Category = "Movement")
     void Zoom(float speed);
     
 };

playercamera.cpp

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "PlayerCamera.h"
 
 #include "Camera/CameraComponent.h"
 #include "GameFramework/SpringArmComponent.h"
 
 // Sets default values
 APlayerCamera::APlayerCamera()
 {
      // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
 
     Root = CreateDefaultSubobject<USceneComponent>(FName("Root"));
 
     SpringArmComponent = CreateDefaultSubobject<USpringArmComponent>(FName("SpringArm"));
     SpringArmComponent->AttachToComponent(Root, FAttachmentTransformRules::KeepRelativeTransform);
     SpringArmComponent->SetRelativeRotation(FRotator(-45.0f, 0.0f, 0.0f));
 
     CameraComponent = CreateDefaultSubobject<UCameraComponent>(FName("Camera"));
     CameraComponent->AttachToComponent(SpringArmComponent, FAttachmentTransformRules::KeepRelativeTransform);
 }
 
 // Called when the game starts or when spawned
 void APlayerCamera::BeginPlay()
 {
     Super::BeginPlay();
 }
 
 // Called every frame
 void APlayerCamera::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
 
 }
 
 // Called to bind functionality to input
 void APlayerCamera::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
 {
     Super::SetupPlayerInputComponent(PlayerInputComponent);
 }
 
 void APlayerCamera::MoveAround(float mouseX, float mouseY)
 {
     // Yaw needs to be applied to this object
     FRotator Rotator = this->GetActorRotation();
     Rotator.Pitch = 0.0f;
     Rotator.Roll = 0.0f;
     Rotator.Yaw += ReferenceMouseX - mouseX;
     this->SetActorRotation(Rotator);
 
     // Pitch needs to be applied to the SpringArmComponent
     FRotator SpringArmRotator = this->SpringArmComponent->GetComponentRotation();
     SpringArmRotator.Pitch = FMath::Clamp(SpringArmRotator.Pitch + ReferenceMouseY - mouseY, -70.0f, -10.0f);
     SpringArmRotator.Roll = 0.0f;
     SpringArmRotator.Yaw = 0.0f;
     this->SpringArmComponent->SetRelativeRotation(SpringArmRotator);
 }
 
 void APlayerCamera::MoveForward(float speed)
 {
     FVector Location = this->GetActorLocation();
     Location += this->GetActorForwardVector() * speed * CameraMoveSpeed;
     this->SetActorLocation(Location);
 }
 
 void APlayerCamera::MoveSideways(float speed)
 {
     FVector Location = this->GetActorLocation();
     Location += this->GetActorRightVector() * speed * CameraMoveSpeed;
     this->SetActorLocation(Location);
 }
 
 void APlayerCamera::SetReferenceMouseXY(float mouseX, float mouseY)
 {
     this->ReferenceMouseX = mouseX;
     this->ReferenceMouseY = mouseY;
 }
 
 void APlayerCamera::Zoom(float speed)
 {
     // Invert scrolling
     speed = speed * -1.0f;
     SpringArmComponent->TargetArmLength += speed * CameraZoomSpeed;
 }


Product Version: UE 4.17
Tags:
log.txt (18.4 kB)
more ▼

asked Aug 23 '17 at 08:21 PM in C++ Programming

avatar image

UE4Course
6 1 2 4

avatar image UE4Course Aug 23 '17 at 08:50 PM

I noticed that 4.17 places everything in the private folder while 4.16 places only cpp files in the private folder and header files in the public folder. Could this have something to do with it?

avatar image NLEBEDENCO Dec 03 '17 at 04:39 AM

Stumbled upon this one myself today. It took me a few hours to understand what was going on. In the end I didn't bother debugging the engine and simply changed the class name to something else. This issue might be related to this bug

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

1 answer: sort voted first

Problem is your header file what you wrote before UCLASS() are not includes! Those are illegal.

  class UCameraComponent;
  class USpringArmComponent;

Your header file should look like this (with proper includes)

  #pragma once
  
  #include "CoreMinimal.h"
  #include "GameFramework/Pawn.h"
  #include "Runtime/Engine/Classes/GameFramework/SpringArmComponent.h"
  #include "Runtime/Engine/Classes/Camera/CameraComponent.h"
  #include "PlayerCamera.generated.h"
  
  UCLASS()
  class APlayerCamera : public APawn
  {
      GENERATED_BODY()
  
  public:
      // Sets default values for this pawn's properties
      APlayerCamera();
  
  protected:
      // Called when the game starts or when spawned
      virtual void BeginPlay() override;
  
  private:
      UPROPERTY(EditDefaultsOnly, Category="Movement")
      float CameraMoveSpeed = 1.0f;
  
      UPROPERTY(EditDefaultsOnly, Category = "Movement")
      float CameraZoomSpeed = 10.0f;
  
      UPROPERTY(EditDefaultsOnly, Category = "Camera")
      USceneComponent *Root = nullptr;
  
      UPROPERTY(EditDefaultsOnly, Category = "Camera")
      USpringArmComponent *SpringArmComponent = nullptr;
  
      UPROPERTY(EditDefaultsOnly, Category = "Camera")
      UCameraComponent *CameraComponent = nullptr;
  
      float ReferenceMouseX = 0.0f;
      float ReferenceMouseY = 0.0f;
  
  public:
      // Called every frame
      virtual void Tick(float DeltaTime) override;
  
      // Called to bind functionality to input
      virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
  
      UFUNCTION(BlueprintCallable, Category = "Movement")
      void MoveAround(float mouseX, float mouseY);
  
      UFUNCTION(BlueprintCallable, Category = "Movement")
      void MoveForward(float speed);
  
      UFUNCTION(BlueprintCallable, Category = "Movement")
      void MoveSideways(float speed);
  
      UFUNCTION(BlueprintCallable, Category = "Movement")
      void SetReferenceMouseXY(float mouseX, float mouseY);
  
      UFUNCTION(BlueprintCallable, Category = "Movement")
      void Zoom(float speed);
      
  };
more ▼

answered Aug 24 '17 at 10:38 AM

avatar image

phoenix[illusion]
118 8 11 15

avatar image UE4Course Aug 24 '17 at 12:27 PM

Those are forward declarations. They should be legal.

(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