Download

Unreal Engine 4 C++: Weapon Essentials issues

I was following the tutorial in this thread https://forums.unrealengine.com/showthread.php?44553-Tutorial-Weapon-Essentials-C-Series and got through part 1 and started part 2 only to find that I did not get nearly the same result as he did and literally none of what I did seems to be of any use (was a regular blueprint, not as depicted in the second part of the tutorial despite following all the steps to the letter and not getting any errors). I then followed this thread’s guide to updating code to more recent engine versions (https://forums.unrealengine.com/showthread.php?53389-4-6-Transition-Guide) but that has given me more problems than anything and no matter what I do it fails with errors. The code snippets it even uses in its error reporting is also incorrect from what I have. It says ‘const FObjectInitializer &’ but I put ‘const class FObjectInitializer&’.

The tutorial in that original thread seemed to be a great start to unreal engine c++ but doesn’t even work apparently. Can anyone help me out here?

error C2664: ‘AActor::AActor(const FObjectInitializer &)’ : cannot convert argument 1 from ‘const FObjectInitalizer’ to ‘const AActor &’
1> Reason: cannot convert from ‘const FObjectInitalizer’ to ‘const AActor’
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(15): error C2027: use of undefined type ‘FObjectInitalizer’
1> c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(53) : see declaration of ‘FObjectInitalizer’
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(18): error C2027: use of undefined type ‘FObjectInitalizer’
1> c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(53) : see declaration of ‘FObjectInitalizer’
1> -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Binaries\Win64\UE4Editor-CPPTest-8663-Win64-DebugGame.dll
1> Total build time: 28.07 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command ““C:\Program Files\Epic Games\4.8\Engine\Build\BatchFiles\Build.bat” CPPTestEditor Win64 DebugGame “C:\Users\Kyle\Documents\Unreal Projects\CPPTest\CPPTest.uproject” -rocket” exited with code -1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Weapons.h


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameFramework/Actor.h"
#include "Weapon.generated.h"


#define TRACE_WEAPON ECC_GameTraceChannel1	// defines our custom game trace channel

UENUM(BlueprintType)
namespace EWeaponProjectile
{
	enum ProjectileType	//projectile types
	{
		EBullet		UMETA(DisplayName = "Bullet"),
		ESpread		UMETA(DisplayName = "Spread"),
		EProjectile	UMETA(DisplayName = "Projectile"),
	};
}

USTRUCT()
struct FweaponData
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditDefaultsOnly, Category = Ammo)
	int32 MaxAmmo;

	UPROPERTY(EditDefaultsOnly, Category = Config)
	float TimeBetweenShots;

	UPROPERTY(EditDefaultsOnly, Category = Ammo)
	float ShotCost;

	UPROPERTY(EditDefaultsOnly, Category = Config)
	float WeaponRange;

	UPROPERTY(EditDefaultsOnly, Category = Config)
	float WeaponSpread;
};

UCLASS()
class CPPTEST_API AWeapon : public AActor
{
	//GENERATED_BODY()
	GENERATED_UCLASS_BODY()
	
public:	
	// Sets default values for this actor's properties
	AWeapon(const class FObjectInitalizer& ObjectInitializer);

	// Called when the game starts or when spawned
	//virtual void BeginPlay() override;
	
	// Called every frame
	//virtual void Tick( float DeltaSeconds ) override;

	UFUNCTION()
	void Fire();

	UFUNCTION()
	void Instant_Fire();

	UPROPERTY(EditDefaultsOnly, Category = Config)
	FweaponData WeaponConfig;

	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Config)
	TEnumAsByte<EWeaponProjectile::ProjectileType> ProjectileType;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
	UBoxComponent* CollisionComp;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
	USkeletalMeshComponent* WeaponMesh;

protected:
	FHitResult WeaponTrace(const FVector &TraceFrom, const FVector &TraceTo) const;
	
	void ProcessInstantHit(const FHitResult &Impact, const FVector &Origin, const FVector &ShootDir, int32 RandomSeed, float ReticleSpread);
};


Weapon.cpp


// Fill out your copyright notice in the Description page of Project Settings.

#include "CPPTest.h"
#include "Weapon.h"
#include "Engine.h"


// Sets default values
AWeapon::AWeapon(const class FObjectInitalizer& ObjectInitializer)
	: Super(ObjectInitializer)
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	CollisionComp = ObjectInitializer.CreateDefaultSubobject<UBoxComponent>(this, TEXT("CollisionComp"));
	RootComponent = CollisionComp;

	WeaponMesh = ObjectInitializer.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("WeaponMesh"));
	WeaponMesh->AttachTo(RootComponent);

}

void AWeapon::Fire()
{
	if (ProjectileType == EWeaponProjectile::EBullet)
	{
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Bullet"));
		Instant_Fire();
	}
	if (ProjectileType == EWeaponProjectile::ESpread)
	{
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Spread"));
		for (int32 i = 0; i <= WeaponConfig.WeaponSpread; i++) {
			Instant_Fire();
		}
	}
	if (ProjectileType == EWeaponProjectile::EProjectile)
	{
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Projectile"));

	}
}

void AWeapon::Instant_Fire()
{
	const int32 RandomSeed = FMath::Rand();	//generate random seed
	FRandomStream WeaponRandomStream(RandomSeed);
	const float CurrentSpread = WeaponConfig.WeaponSpread;	//current weapon spread
	const float SpreadCone = FMath::DegreesToRadians(WeaponConfig.WeaponSpread * 0.5);
	const FVector AimDir = WeaponMesh->GetSocketRotation("mf").Vector();	//figure out our aim direction
	const FVector StartTrace = WeaponMesh->GetSocketLocation("mf");	//starts trace
	const FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, SpreadCone, SpreadCone);	//figure out our shoot direction
	const FVector EndTrace = StartTrace + ShootDir * WeaponConfig.WeaponRange;	// calculate difference between start direction and weapon range
	const FHitResult Impact = WeaponTrace(StartTrace, EndTrace);
	//Now these are all set up now we can actually process instant hit
	ProcessInstantHit(Impact, StartTrace, ShootDir, RandomSeed, CurrentSpread);
}
/*
// Called when the game starts or when spawned
void AWeapon::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AWeapon::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

}*/

FHitResult AWeapon::WeaponTrace(const FVector &TraceFrom, const FVector &TraceTo) const
{
	static FName WeaponFireTag = FName(TEXT("WeaponTrace"));
	FCollisionQueryParams TraceParams(WeaponFireTag, true, Instigator);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = true;
	TraceParams.AddIgnoredActor(this);

	FHitResult Hit(ForceInit);

	GetWorld()->LineTraceSingleByChannel(Hit, TraceFrom, TraceTo, TRACE_WEAPON, TraceParams);

	return Hit;
}

void AWeapon::ProcessInstantHit(const FHitResult &Impact, const FVector &Origin, const FVector &ShootDir, int32 RandomSeed, float ReticleSpread)
{
	const FVector EndTrace = Origin + ShootDir * WeaponConfig.WeaponRange;
	const FVector EndPoint = Impact.GetActor() ? Impact.ImpactPoint : EndTrace;
	DrawDebugLine(this->GetWorld(), Origin, Impact.TraceEnd, FColor::Black, true, 10000, 10.0f);
}

Those are my modified versions in trying to follow the 4.6 transition guide linked above. If you want the original tutorial version I could revert back and post that for you.

It’s because you’re using the old GENERATED_UCLASS_BODY() which already defines the constructor. In addition to that, you’re also putting ‘class’ in front of FObjectInitializer which is causing it to be redefined. You shouldn’t ever need to do that.



(const FObjectInitializer& ObjectInitializer)


So yeah, either remove your constructor declaration in the header file or switch to GENERATED_BODY()

My error log now is as follows:



1>------ Build started: Project: CPPTest, Configuration: DebugGame_Editor x64 ------
1>  Compiling game modules for hot reload
1>  Parsing headers for CPPTestEditor
1>  Reflection code generated for CPPTestEditor
1>  Performing 3 actions (4 in parallel)
1>  Weapon.cpp
1>  CPPTest.generated.cpp
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(46): error C2338: You have to define AWeapon::AWeapon() or AWeapon::AWeapon(const FObjectInitializer&). This is required by UObject system to work correctly.
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(51): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(51): error C2143: syntax error : missing ',' before '&'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(46): error C2338: You have to define AWeapon::AWeapon() or AWeapon::AWeapon(const FObjectInitializer&). This is required by UObject system to work correctly.
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(51): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(51): error C2143: syntax error : missing ',' before '&'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(9): error C2143: syntax error : missing ',' before '&'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(10): error C2065: 'ObjectInitializer' : undeclared identifier
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(15): error C2065: 'ObjectInitializer' : undeclared identifier
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(18): error C2065: 'ObjectInitializer' : undeclared identifier
1>  -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Binaries\Win64\UE4Editor-CPPTest-2805-Win64-DebugGame.dll
1>  Total build time: 82.87 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command ""C:\Program Files\Epic Games\4.8\Engine\Build\BatchFiles\Build.bat" CPPTestEditor Win64 DebugGame "C:\Users\Kyle\Documents\Unreal Projects\CPPTest\CPPTest.uproject" -rocket" exited with code -1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

After reading that log I then changed my declaration in the header file to AWeapon::AWeapon(const FObjectInitializer& ObjectInitializer) and tried again to get this error log:


1>------ Build started: Project: CPPTest, Configuration: DebugGame_Editor x64 ------
1>  Compiling game modules for hot reload
1>  Parsing headers for CPPTestEditor
1>  Reflection code generated for CPPTestEditor
1>  Performing 3 actions (4 in parallel)
1>  Weapon.cpp
1>  CPPTest.generated.cpp
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(51): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(51): error C2143: syntax error : missing ',' before '&'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(51): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(51): error C2143: syntax error : missing ',' before '&'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(9): error C2143: syntax error : missing ',' before '&'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(10): error C2065: 'ObjectInitializer' : undeclared identifier
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(15): error C2065: 'ObjectInitializer' : undeclared identifier
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(18): error C2065: 'ObjectInitializer' : undeclared identifier
1>  -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Binaries\Win64\UE4Editor-CPPTest-7185-Win64-DebugGame.dll
1>  Total build time: 26.93 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command ""C:\Program Files\Epic Games\4.8\Engine\Build\BatchFiles\Build.bat" CPPTestEditor Win64 DebugGame "C:\Users\Kyle\Documents\Unreal Projects\CPPTest\CPPTest.uproject" -rocket" exited with code -1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Okay so, are you using GENERATED_BODY() now or GENERATED_UCLASS_BODY()?

It doesn’t seem to know what ‘AWeapon’ actually is, so I’m starting to wonder if the problem is further up the header file - probably with the declaration of a namespace. Try defining your enum like this first of all (this is the way it’s meant to be):



UENUM(BlueprintType)
enum class EWeaponProjectile : uint8
{
	EBullet	UMETA(DisplayName = "Bullet"),
	ESpread	UMETA(DisplayName = "Spread"),
	EProjectile	UMETA(DisplayName = "Projectile"),
};


EDIT: Oh and, you’re missing the default constructor in your USTRUCT:



USTRUCT()
struct FWeaponData
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditDefaultsOnly, Category = Ammo)
	int32 MaxAmmo;

	UPROPERTY(EditDefaultsOnly, Category = Config)
	float TimeBetweenShots;

	UPROPERTY(EditDefaultsOnly, Category = Ammo)
	float ShotCost;

	UPROPERTY(EditDefaultsOnly, Category = Config)
	float WeaponRange;

	UPROPERTY(EditDefaultsOnly, Category = Config)
	float WeaponSpread;

	FWeaponData()
		: MaxAmmo(0)
		, TimeBetweenShots(0.f)
		, ShotCost(0.f)
		, WeaponRange(0.f)
		, WeaponSpread(0.f)
	{}
};


That is correct, I am using GENERATED_BODY() now.

Here is the new error log after implementing what you posted.


1>------ Build started: Project: CPPTest, Configuration: DebugGame_Editor x64 ------
1>  Compiling game modules for hot reload
1>  Parsing headers for CPPTestEditor
1>  Reflection code generated for CPPTestEditor
1>  Performing 3 actions (4 in parallel)
1>  CPPTest.generated.cpp
1>  Weapon.cpp
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(50): error C2590: 'FWeaponData' : only a constructor can have a base/member initializer list
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(66): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(66): error C2143: syntax error : missing ',' before '&'
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(84): error C2838: 'ProjectileType' : illegal qualified name in member declaration
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(84): error C2065: 'ProjectileType' : undeclared identifier
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(84): error C2923: 'TEnumAsByte' : 'ProjectileType' is not a valid template type argument for parameter 'TEnum'
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(61): error C2512: 'TEnumAsByte' : no appropriate default constructor available
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(50): error C2590: 'FWeaponData' : only a constructor can have a base/member initializer list
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(66): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(66): error C2143: syntax error : missing ',' before '&'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(84): error C2838: 'ProjectileType' : illegal qualified name in member declaration
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(84): error C2065: 'ProjectileType' : undeclared identifier
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(84): error C2923: 'TEnumAsByte' : 'ProjectileType' is not a valid template type argument for parameter 'TEnum'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(61): error C2512: 'TEnumAsByte' : no appropriate default constructor available
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Intermediate\Build\Win64\UE4Editor\Inc\CPPTest\CPPTest.generated.cpp(453): error C2512: 'TEnumAsByte' : no appropriate default constructor available
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(9): error C2143: syntax error : missing ',' before '&'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(10): error C2065: 'ObjectInitializer' : undeclared identifier
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(11): error C2512: 'TEnumAsByte' : no appropriate default constructor available
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(15): error C2065: 'ObjectInitializer' : undeclared identifier
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(18): error C2065: 'ObjectInitializer' : undeclared identifier
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(25): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'TEnumAsByte' (or there is no acceptable conversion)
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h(98): could be 'bool TEnumAsByte<TEnum>::operator ==(TEnumAsByte<TEnum>) const'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h(87): or       'bool TEnumAsByte<TEnum>::operator ==(TEnum) const'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Sound/DialogueWave.h(36): or       'bool operator ==(const FDialogueContextMapping &,const FDialogueContextMapping &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Sound/DialogueTypes.h(56): or       'bool operator ==(const FDialogueContext &,const FDialogueContext &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/StaticMesh.h(209): or       'bool operator ==(const FMeshSectionInfo &,const FMeshSectionInfo &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(514): or       'bool operator ==(const UMaterialInterface &,const FSkeletalMaterial &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(513): or       'bool operator ==(const FSkeletalMaterial &,const UMaterialInterface &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(512): or       'bool operator ==(const FSkeletalMaterial &,const FSkeletalMaterial &)'
1>          c:\program files\epic games\4.8\engine\source\runtime\rhi\public\RHIResources.h(179): or       'bool operator ==(const FRHIUniformBufferLayout &,const FRHIUniformBufferLayout &)'
1>          C:\Program Files (x86)\Windows Kits\8.1\include\shared\guiddef.h(192): or       'bool operator ==(const GUID &,const GUID &)'
1>          while trying to match the argument list '(TEnumAsByte, EWeaponProjectile)'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(30): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'TEnumAsByte' (or there is no acceptable conversion)
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h(98): could be 'bool TEnumAsByte<TEnum>::operator ==(TEnumAsByte<TEnum>) const'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h(87): or       'bool TEnumAsByte<TEnum>::operator ==(TEnum) const'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Sound/DialogueWave.h(36): or       'bool operator ==(const FDialogueContextMapping &,const FDialogueContextMapping &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Sound/DialogueTypes.h(56): or       'bool operator ==(const FDialogueContext &,const FDialogueContext &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/StaticMesh.h(209): or       'bool operator ==(const FMeshSectionInfo &,const FMeshSectionInfo &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(514): or       'bool operator ==(const UMaterialInterface &,const FSkeletalMaterial &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(513): or       'bool operator ==(const FSkeletalMaterial &,const UMaterialInterface &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(512): or       'bool operator ==(const FSkeletalMaterial &,const FSkeletalMaterial &)'
1>          c:\program files\epic games\4.8\engine\source\runtime\rhi\public\RHIResources.h(179): or       'bool operator ==(const FRHIUniformBufferLayout &,const FRHIUniformBufferLayout &)'
1>          C:\Program Files (x86)\Windows Kits\8.1\include\shared\guiddef.h(192): or       'bool operator ==(const GUID &,const GUID &)'
1>          while trying to match the argument list '(TEnumAsByte, EWeaponProjectile)'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(37): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'TEnumAsByte' (or there is no acceptable conversion)
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h(98): could be 'bool TEnumAsByte<TEnum>::operator ==(TEnumAsByte<TEnum>) const'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h(87): or       'bool TEnumAsByte<TEnum>::operator ==(TEnum) const'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Sound/DialogueWave.h(36): or       'bool operator ==(const FDialogueContextMapping &,const FDialogueContextMapping &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Sound/DialogueTypes.h(56): or       'bool operator ==(const FDialogueContext &,const FDialogueContext &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/StaticMesh.h(209): or       'bool operator ==(const FMeshSectionInfo &,const FMeshSectionInfo &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(514): or       'bool operator ==(const UMaterialInterface &,const FSkeletalMaterial &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(513): or       'bool operator ==(const FSkeletalMaterial &,const UMaterialInterface &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(512): or       'bool operator ==(const FSkeletalMaterial &,const FSkeletalMaterial &)'
1>          c:\program files\epic games\4.8\engine\source\runtime\rhi\public\RHIResources.h(179): or       'bool operator ==(const FRHIUniformBufferLayout &,const FRHIUniformBufferLayout &)'
1>          C:\Program Files (x86)\Windows Kits\8.1\include\shared\guiddef.h(192): or       'bool operator ==(const GUID &,const GUID &)'
1>          while trying to match the argument list '(TEnumAsByte, EWeaponProjectile)'
1>  -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Binaries\Win64\UE4Editor-CPPTest-9830-Win64-DebugGame.dll
1>  Total build time: 26.01 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command ""C:\Program Files\Epic Games\4.8\Engine\Build\BatchFiles\Build.bat" CPPTestEditor Win64 DebugGame "C:\Users\Kyle\Documents\Unreal Projects\CPPTest\CPPTest.uproject" -rocket" exited with code -1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Incase you want to look at the code as it sits after these changes as the moment here is the Weapon.h:


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameFramework/Actor.h"
#include "Weapon.generated.h"


#define TRACE_WEAPON ECC_GameTraceChannel1	// defines our custom game trace channel

/*UENUM(BlueprintType)
namespace EWeaponProjectile
{
	enum ProjectileType	//projectile types
	{
		EBullet		UMETA(DisplayName = "Bullet"),
		ESpread		UMETA(DisplayName = "Spread"),
		EProjectile	UMETA(DisplayName = "Projectile"),
	};
}*/
UENUM(BlueprintType)
enum class EWeaponProjectile : uint8
{
	EBullet	UMETA(DisplayName = "Bullet"),
	ESpread	UMETA(DisplayName = "Spread"),
	EProjectile	UMETA(DisplayName = "Projectile"),
};

USTRUCT()
struct FweaponData
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditDefaultsOnly, Category = Ammo)
	int32 MaxAmmo;

	UPROPERTY(EditDefaultsOnly, Category = Config)
	float TimeBetweenShots;

	UPROPERTY(EditDefaultsOnly, Category = Ammo)
	float ShotCost;

	UPROPERTY(EditDefaultsOnly, Category = Config)
	float WeaponRange;

	UPROPERTY(EditDefaultsOnly, Category = Config)
	float WeaponSpread;

	FWeaponData()
		: MaxAmmo(0)
		, TimeBetweenShots(0.f)
		, ShotCost(0.f)
		, WeaponRange(0.f)
		, WeaponSpread(0.f)
	{}
};

UCLASS()
class CPPTEST_API AWeapon : public AActor
{
	GENERATED_BODY()
	//GENERATED_UCLASS_BODY()
	
public:	
	// Sets default values for this actor's properties
	AWeapon::AWeapon(const FObjectInitalizer& ObjectInitializer);

	// Called when the game starts or when spawned
	//virtual void BeginPlay() override;
	
	// Called every frame
	//virtual void Tick( float DeltaSeconds ) override;

	UFUNCTION()
	void Fire();

	UFUNCTION()
	void Instant_Fire();

	UPROPERTY(EditDefaultsOnly, Category = Config)
	FweaponData WeaponConfig;

	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Config)
	TEnumAsByte<EWeaponProjectile::ProjectileType> ProjectileType;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
	UBoxComponent* CollisionComp;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
	USkeletalMeshComponent* WeaponMesh;

protected:
	FHitResult WeaponTrace(const FVector &TraceFrom, const FVector &TraceTo) const;
	
	void ProcessInstantHit(const FHitResult &Impact, const FVector &Origin, const FVector &ShootDir, int32 RandomSeed, float ReticleSpread);
};


and here is the Weapon.cpp:


// Fill out your copyright notice in the Description page of Project Settings.

#include "CPPTest.h"
#include "Weapon.h"
#include "Engine.h"


// Sets default values
AWeapon::AWeapon(const FObjectInitalizer& ObjectInitializer)
	: Super(ObjectInitializer)
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	CollisionComp = ObjectInitializer.CreateDefaultSubobject<UBoxComponent>(this, TEXT("CollisionComp"));
	RootComponent = CollisionComp;

	WeaponMesh = ObjectInitializer.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("WeaponMesh"));
	WeaponMesh->AttachTo(RootComponent);

}

void AWeapon::Fire()
{
	if (ProjectileType == EWeaponProjectile::EBullet)
	{
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Bullet"));
		Instant_Fire();
	}
	if (ProjectileType == EWeaponProjectile::ESpread)
	{
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Spread"));
		for (int32 i = 0; i <= WeaponConfig.WeaponSpread; i++) {
			Instant_Fire();
		}
	}
	if (ProjectileType == EWeaponProjectile::EProjectile)
	{
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, TEXT("Projectile"));

	}
}

void AWeapon::Instant_Fire()
{
	const int32 RandomSeed = FMath::Rand();	//generate random seed
	FRandomStream WeaponRandomStream(RandomSeed);
	const float CurrentSpread = WeaponConfig.WeaponSpread;	//current weapon spread
	const float SpreadCone = FMath::DegreesToRadians(WeaponConfig.WeaponSpread * 0.5);
	const FVector AimDir = WeaponMesh->GetSocketRotation("mf").Vector();	//figure out our aim direction
	const FVector StartTrace = WeaponMesh->GetSocketLocation("mf");	//starts trace
	const FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, SpreadCone, SpreadCone);	//figure out our shoot direction
	const FVector EndTrace = StartTrace + ShootDir * WeaponConfig.WeaponRange;	// calculate difference between start direction and weapon range
	const FHitResult Impact = WeaponTrace(StartTrace, EndTrace);
	//Now these are all set up now we can actually process instant hit
	ProcessInstantHit(Impact, StartTrace, ShootDir, RandomSeed, CurrentSpread);
}
/*
// Called when the game starts or when spawned
void AWeapon::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AWeapon::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

}*/

FHitResult AWeapon::WeaponTrace(const FVector &TraceFrom, const FVector &TraceTo) const
{
	static FName WeaponFireTag = FName(TEXT("WeaponTrace"));
	FCollisionQueryParams TraceParams(WeaponFireTag, true, Instigator);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = true;
	TraceParams.AddIgnoredActor(this);

	FHitResult Hit(ForceInit);

	GetWorld()->LineTraceSingleByChannel(Hit, TraceFrom, TraceTo, TRACE_WEAPON, TraceParams);

	return Hit;
}

void AWeapon::ProcessInstantHit(const FHitResult &Impact, const FVector &Origin, const FVector &ShootDir, int32 RandomSeed, float ReticleSpread)
{
	const FVector EndTrace = Origin + ShootDir * WeaponConfig.WeaponRange;
	const FVector EndPoint = Impact.GetActor() ? Impact.ImpactPoint : EndTrace;
	DrawDebugLine(this->GetWorld(), Origin, Impact.TraceEnd, FColor::Black, true, 10000, 10.0f);
}

try this



UCLASS()
class CPPTEST_API AWeapon : public AActor
{
	GENERATED_BODY()
	//GENERATED_UCLASS_BODY()
	
public:	
	// Sets default values for this actor's properties
	AWeapon();





    AWeapon::AWeapon() : Super()
    {
     	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    	PrimaryActorTick.bCanEverTick = true;

    	CollisionComp = CreateDefaultSubobject<UBoxComponent>(TEXT("CollisionComp"));
    	RootComponent = CollisionComp;

    	WeaponMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("WeaponMesh"));
    	WeaponMesh->AttachTo(RootComponent);

    }


I tried that but got this error log:


1>------ Build started: Project: CPPTest, Configuration: DebugGame_Editor x64 ------
1>  Compiling game modules for hot reload
1>  Parsing headers for CPPTestEditor
1>  Reflection code generated for CPPTestEditor
1>  Performing 3 actions (4 in parallel)
1>  Weapon.cpp
1>  CPPTest.generated.cpp
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(50): error C2590: 'FWeaponData' : only a constructor can have a base/member initializer list
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(85): error C2838: 'ProjectileType' : illegal qualified name in member declaration
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(85): error C2065: 'ProjectileType' : undeclared identifier
1>c:\users\kyle\documents\unreal projects\cpptest\source\cpptest\Weapon.h(85): error C2923: 'TEnumAsByte' : 'ProjectileType' is not a valid template type argument for parameter 'TEnum'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(50): error C2590: 'FWeaponData' : only a constructor can have a base/member initializer list
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(85): error C2838: 'ProjectileType' : illegal qualified name in member declaration
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(85): error C2065: 'ProjectileType' : undeclared identifier
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.h(85): error C2923: 'TEnumAsByte' : 'ProjectileType' is not a valid template type argument for parameter 'TEnum'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Intermediate\Build\Win64\UE4Editor\Inc\CPPTest\CPPTest.generated.cpp(453): error C2512: 'TEnumAsByte' : no appropriate default constructor available
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(12): error C2512: 'TEnumAsByte' : no appropriate default constructor available
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(31): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'TEnumAsByte' (or there is no acceptable conversion)
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h(98): could be 'bool TEnumAsByte<TEnum>::operator ==(TEnumAsByte<TEnum>) const'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h(87): or       'bool TEnumAsByte<TEnum>::operator ==(TEnum) const'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Sound/DialogueWave.h(36): or       'bool operator ==(const FDialogueContextMapping &,const FDialogueContextMapping &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Sound/DialogueTypes.h(56): or       'bool operator ==(const FDialogueContext &,const FDialogueContext &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/StaticMesh.h(209): or       'bool operator ==(const FMeshSectionInfo &,const FMeshSectionInfo &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(514): or       'bool operator ==(const UMaterialInterface &,const FSkeletalMaterial &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(513): or       'bool operator ==(const FSkeletalMaterial &,const UMaterialInterface &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(512): or       'bool operator ==(const FSkeletalMaterial &,const FSkeletalMaterial &)'
1>          c:\program files\epic games\4.8\engine\source\runtime\rhi\public\RHIResources.h(179): or       'bool operator ==(const FRHIUniformBufferLayout &,const FRHIUniformBufferLayout &)'
1>          C:\Program Files (x86)\Windows Kits\8.1\include\shared\guiddef.h(192): or       'bool operator ==(const GUID &,const GUID &)'
1>          while trying to match the argument list '(TEnumAsByte, EWeaponProjectile)'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(36): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'TEnumAsByte' (or there is no acceptable conversion)
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h(98): could be 'bool TEnumAsByte<TEnum>::operator ==(TEnumAsByte<TEnum>) const'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h(87): or       'bool TEnumAsByte<TEnum>::operator ==(TEnum) const'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Sound/DialogueWave.h(36): or       'bool operator ==(const FDialogueContextMapping &,const FDialogueContextMapping &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Sound/DialogueTypes.h(56): or       'bool operator ==(const FDialogueContext &,const FDialogueContext &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/StaticMesh.h(209): or       'bool operator ==(const FMeshSectionInfo &,const FMeshSectionInfo &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(514): or       'bool operator ==(const UMaterialInterface &,const FSkeletalMaterial &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(513): or       'bool operator ==(const FSkeletalMaterial &,const UMaterialInterface &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(512): or       'bool operator ==(const FSkeletalMaterial &,const FSkeletalMaterial &)'
1>          c:\program files\epic games\4.8\engine\source\runtime\rhi\public\RHIResources.h(179): or       'bool operator ==(const FRHIUniformBufferLayout &,const FRHIUniformBufferLayout &)'
1>          C:\Program Files (x86)\Windows Kits\8.1\include\shared\guiddef.h(192): or       'bool operator ==(const GUID &,const GUID &)'
1>          while trying to match the argument list '(TEnumAsByte, EWeaponProjectile)'
1>C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Source\CPPTest\Weapon.cpp(43): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'TEnumAsByte' (or there is no acceptable conversion)
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h(98): could be 'bool TEnumAsByte<TEnum>::operator ==(TEnumAsByte<TEnum>) const'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h(87): or       'bool TEnumAsByte<TEnum>::operator ==(TEnum) const'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Sound/DialogueWave.h(36): or       'bool operator ==(const FDialogueContextMapping &,const FDialogueContextMapping &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Sound/DialogueTypes.h(56): or       'bool operator ==(const FDialogueContext &,const FDialogueContext &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/StaticMesh.h(209): or       'bool operator ==(const FMeshSectionInfo &,const FMeshSectionInfo &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(514): or       'bool operator ==(const UMaterialInterface &,const FSkeletalMaterial &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(513): or       'bool operator ==(const FSkeletalMaterial &,const UMaterialInterface &)'
1>          C:\Program Files\Epic Games\4.8\Engine\Source\Runtime\Engine\Classes\Engine/SkeletalMesh.h(512): or       'bool operator ==(const FSkeletalMaterial &,const FSkeletalMaterial &)'
1>          c:\program files\epic games\4.8\engine\source\runtime\rhi\public\RHIResources.h(179): or       'bool operator ==(const FRHIUniformBufferLayout &,const FRHIUniformBufferLayout &)'
1>          C:\Program Files (x86)\Windows Kits\8.1\include\shared\guiddef.h(192): or       'bool operator ==(const GUID &,const GUID &)'
1>          while trying to match the argument list '(TEnumAsByte, EWeaponProjectile)'
1>  -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: C:\Users\Kyle\Documents\Unreal Projects\CPPTest\Binaries\Win64\UE4Editor-CPPTest-1545-Win64-DebugGame.dll
1>  Total build time: 26.59 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command ""C:\Program Files\Epic Games\4.8\Engine\Build\BatchFiles\Build.bat" CPPTestEditor Win64 DebugGame "C:\Users\Kyle\Documents\Unreal Projects\CPPTest\CPPTest.uproject" -rocket" exited with code -1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


EDIT: After some good ol’ debugging I got it to successfully generate but I am STILL no better off than before and I am now back to the original issue. I am unable to create a sub blueprint class from the Weapon C++ class in the sense that it is not custom made and is the generic old blueprint when creating them default. This one (as depicted early in the second part of the tutorial series) should be entirely different with components already in place.

I’m stumped to be honest, unless the file just isn’t being properly included in the project for whatever reason… bizarre.

If you are able to upload a test project anywhere I can give it a go on my end for you.

I am compressing it now so I can upload it to my file server. it will be 882MB just so you know.

EDIT: As of right now it will take over an hour to upload. I will edit this post again with a download link once it is done.

EDIT2: Here is the download link to the project: dl.markyrosongaming.ar.nf/UE4/CPPTest.zip

Just grabbed it, working on something atm but I’ll check it out soon as I can :slight_smile:

Okay, please keep me posted. How long do you think it will be until you can check it out?

Well, I compiled it and it worked perfectly first time. No code changes whatsoever.

I recommend refreshing the project. Delete the Intermediate, Saved, Binaries and Build folder. Also delete all the files in the main folder apart from the Unreal Project File. Then switch to engine version 4.8 and regenerate project files, should be fine! Sometimes a good refresh is all it needs.

That did resolve my issues, thank you! :slight_smile:

Now I continued following along (had to switch to a third person project though due to it all being weird in first person project and that fixed weirdness) but now I keep getting the error ‘Unhandled exception at 0x000007FED8CE3CDE (UE4Editor-WeaponEssentials-5317.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000370.’ And the engine crashes. I am not sure what is going on.

The part I continued with: https://youtu.be/qwYEu2nvXhA

I have included my code from the source folder. Please ignore the Achievements class as it is not called anywhere nor relevant and was just something I made while I was bored for the fun of it (and error occurred before it was added).

Source folder download: dl.markyrosongaming.ar.nf/UE4/Source.zip

That usually refers to a variable that has been garbage collected, or doesn’t exist. It’s basically saying it’s tried to access memory that it can’t get to or doesn’t exist. Again, I can have a quick look later.

okay, thank you. Looking forward toy our response and sorry to bother you with probably rather stupid questions.

Did you manage to test it out?

I noticed that your struct is called FweaponData but the constructor is FWeaponData. Pretty certain that constructors are case sensitive. You might want to rectify that.

In addition, try placing the weapon.h include under the engine.h include.

In the updated scripts (which you can download for yourself here: http://dl.markyrosongaming.ar.nf/UE4/Source.zip) the first issue you mentioned is resolved. I tried moving the includes around but it created a fatal error when I tried to build the source.

Also, in the linked source, please ignore the Achievements class as it does not do anything and was something I just made while I was bored for the fun of it. To clarify, the error etc I referred to here (https://forums.unrealengine.com/showthread.php?79303-Unreal-Engine-4-C-Weapon-Essentials-issues&p=357900&viewfull=1#post357900) existed well before I ever added that class.

EDIT: I have since tried to comment out the OnCollision function in WeaponEssentialsCharacter and when I attempted to hit “Play” I got this error log:


MachineId:A910A2B74D3C7B4F546D37A1A834B09A
EpicAccountId:150fc3235a22410298ffc5e0f522d346

Access violation - code c0000005 (first/second chance not available)

""

UE4Editor_WeaponEssentials!AWeapon::Fire() [c:\users\kyle\documents\unreal projects\weaponessentials\source\weaponessentials\weapon.cpp:31]
UE4Editor_Engine!UPlayerInput::ProcessInputStack() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\userinterface\playerinput.cpp:1084]
UE4Editor_Engine!APlayerController::ProcessPlayerInput() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\playercontroller.cpp:2366]
UE4Editor_Engine!APlayerController::TickPlayerInput() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\playercontroller.cpp:3785]
UE4Editor_Engine!APlayerController::PlayerTick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\playercontroller.cpp:2040]
UE4Editor_Engine!APlayerController::TickActor() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\playercontroller.cpp:3858]
UE4Editor_Engine!FActorTickFunction::ExecuteTick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\actor.cpp:105]
UE4Editor_Engine!FTickTaskSequencer::FTickFunctionTask::DoTask() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private	icktaskmanager.cpp:113]
UE4Editor_Engine!TGraphTask<FTickTaskSequencer::FTickFunctionTask>::ExecuteTask() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\public\async	askgraphinterfaces.h:753]
UE4Editor_Core!FTaskThread::ProcessTasks() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\async	askgraph.cpp:430]
UE4Editor_Core!FTaskThread::ProcessTasksUntilQuit() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\async	askgraph.cpp:273]
UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\private\async	askgraph.cpp:991]
UE4Editor_Engine!FTaskGraphInterface::WaitUntilTaskCompletes() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\core\public\async	askgraphinterfaces.h:192]
UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private	icktaskmanager.cpp:232]
UE4Editor_Engine!FTickTaskManager::RunTickGroup() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private	icktaskmanager.cpp:643]
UE4Editor_Engine!UWorld::RunTickGroup() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\leveltick.cpp:697]
UE4Editor_Engine!UWorld::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\engine\private\leveltick.cpp:1181]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\editor\unrealed\private\editorengine.cpp:1339]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\editor\unrealed\private\unrealedengine.cpp:366]
UE4Editor!FEngineLoop::Tick() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\launchengineloop.cpp:2359]
UE4Editor!GuardedMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\launch.cpp:142]
UE4Editor!GuardedMainWrapper() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.8\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]


the line 31 referenced in the first line of the log has nothing wrong with it (yes, the curly brace is on the line below) and is as follows


if (ProjectileType == ProjectileType::EBullet)