Having Issues using a later version of Unreal

Hi Ben / Sam,

I am stuck on this episode with some errors in Visual studio. I am using Unreal 4.16.3 and i think there is some differences with the methods used to accomplish certain things. either that or its the IWYU system of includes that is stuffing me around.

I really want to finish this tutorial but i cant get past this issue

(PROBLEM 1)
Mesh1P is throwing errors about incomplete class types (E0393) for every line AFTER the assignment line (top line)

// Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this 
pawn)
Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P"));
Mesh1P->SetOnlyOwnerSee(true);
Mesh1P->SetupAttachment(FirstPersonCameraComponent);
Mesh1P->bCastDynamicShadow = false;
Mesh1P->CastShadow = false;
Mesh1P->RelativeRotation = FRotator(1.9f, -19.19f, 5.2f);
Mesh1P->RelativeLocation = FVector(-0.5f, -4.4f, -155.7f);

(PROBLEM 2)
when I try to attach the gun to the mesh using:

Gun = GetWorld()->SpawnActor<AGun>(GunBlueprint);
//Attach gun mesh component to Skeleton, doing it here because the skeleton is not yet created in the constructor
Gun->AttachToComponent(Mesh1P, FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true), TEXT("GripPoint"));

i get error E0167 - argument of type USkeletalMeshComponent* is incompatible with parameter of type USceneComponent*.

While i understand that the types are different for the second problem I was wondering if you could shed some light on whether there is a different command to use for attaching the gun in later versions of unreal.

The first problem with Mesh1P i am completely lost about.

I have repeated this tutorial lesson from scratch plus the one previous to it a number of times and replicated your instructions within them 100%.

Could someone please help me understand how to fix this and what exactly is going on here?

EDIT:

I solved my first Problem by including the correct header:

#include "Components/SkeletalMeshComponent.h"

I still haven’t been able to attach the gun correctly without getting an immediate crash of the editor when i click play.

Going to continue to try to find an answer but would love it if someone could point me in the right direction :slight_smile:

I’m so glad to hear you solved this. In future if you can’t get the response you need, do try mentioning our student instructor @DanM here as he’s very helpful.

Your second problem should still compile.

I’m exactly like you man! Did you found the root of the problem?

There’s many difference from our template compared to the one used in the video. First, there’s new features regarding to VR, I’ve already pass that out to the gun class but still not working. Other difference I saw is that in our template we have this line of code:

FP_Gun->SetupAttachment(RootComponent);

The lecture’s code doesn’t have this and I don’t know if is important. By last, an student shared a tip in the Udemy comments of this lecture which I don’t know if is significative for the present issue.

Summoning everyone here! @ben @DanM @sampattuzzi
Please help, this is the most exciting section and I want to keep the work going!

Not sure what you’re actual question is. Generated code by the engine is probably going to differ from version to version, it shouldn’t matter in most cases.

Hi Edgar,

I did find a solution to this and it required a couple of tweaks.

With some googling i found that the version of Unreal that the series is using makes use of the “Monolithic” headers, which I believe means when you use simple includes like “Engine.h” you are essentially asking the compiler to parse EVERYTHING in the engine headers.

The newer version I am using (4.16.3) is using the IWYU Headers now (i believe it means “Include What You Use”) which increases compile time speed as the compiler has markedly less files to parse through to compile the code.

From the research on it I did I found that using:
#include "Components/SkeletalMeshComponent.h"

fixes the incomplete type error as the compiler now sees the parent class it needs for a skeletal mesh component.

as for the attachment issue I found by trial and error that I could get it to work though I cannot remember the exact steps.

below is the first 68 lines of my FirstPersonCharacter.cpp that you could use to compare to yours to see if your includes are the same and if your code is similar although i would recommend not copy pasting into your project as it may cause more undesired errors:

#include "FirstPersonCharacter.h"
#include "GameFramework/Actor.h"
#include "GameFramework/Character.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/InputComponent.h"
#include "Components/SkeletalMeshComponent.h"
#include "GameFramework/InputSettings.h"
#include "Weapon/Gun.h"
#include "Kismet/HeadMountedDisplayFunctionLibrary.h"
#include "Kismet/GameplayStatics.h"
#include "MotionControllerComponent.h"

DEFINE_LOG_CATEGORY_STATIC(LogFPChar, Warning, All);

//////////////////////////////////////////////////////////////////////////
// AFirstPersonCharacter

AFirstPersonCharacter::AFirstPersonCharacter()
{
	// Set size for collision capsule
	GetCapsuleComponent()->InitCapsuleSize(55.f, 96.0f);

	// set our turn rates for input
	BaseTurnRate = 45.f;
	BaseLookUpRate = 45.f;

	// Create a CameraComponent	
	FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
	FirstPersonCameraComponent->SetupAttachment(GetCapsuleComponent());
	FirstPersonCameraComponent->RelativeLocation = FVector(-39.56f, 1.75f, 64.f); // Position the camera
	FirstPersonCameraComponent->bUsePawnControlRotation = true;

	// Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn)
	Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P"));
	Mesh1P->SetOnlyOwnerSee(true);
	Mesh1P->SetupAttachment(FirstPersonCameraComponent);
	Mesh1P->bCastDynamicShadow = false;
	Mesh1P->CastShadow = false;
	Mesh1P->RelativeRotation = FRotator(1.9f, -19.19f, 5.2f);
	Mesh1P->RelativeLocation = FVector(-0.5f, -4.4f, -155.7f);

	// Default offset from the character location for projectiles to spawn
	GunOffset = FVector(100.0f, 0.0f, 10.0f);
	
	// Note: The ProjectileClass and the skeletal mesh/anim blueprints for Mesh1P, FP_Gun, and VR_Gun 
	// are set in the derived blueprint asset named MyCharacter to avoid direct content references in C++.
}

void AFirstPersonCharacter::BeginPlay()
{
	// Call the base class  
	Super::BeginPlay();
	
	if (GunBlueprint == NULL) {
		UE_LOG(LogTemp, Warning, TEXT("GunBlueprint is NULL"))
		return;
	}
	Gun = GetWorld()->SpawnActor<AGun>(GunBlueprint);
	Gun->AttachToComponent(Mesh1P, FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true), TEXT("GripPoint"));
	Gun->AnimInstance = Mesh1P->GetAnimInstance();
	//InputComponent->BindTouch(EInputEvent::IE_Pressed, this, &AFirstPersonCharacter::TouchStarted);
	
	InputComponent->BindAction("Fire", IE_Pressed, Gun, &AGun::OnFire);

}

let me know if this helps you solve the issue.

again this code most likely has a lot of bad practices in it and is messy but its what i ahve at the moment and it is working for me. Im almost positive that a couple of the includes are redundant but again, it works :slight_smile:

1 Like

Thank you bro! Mark this post as solved with your last answer.

Thank you ‘JonhhyShootos’ for the following tip:

#include “Components/SkeletalMeshComponent.h”

Nice one =]

Privacy & Terms