Referencing blueprint in C++

Okay so I have a snippet of code that looks like this:

	if (ActiveWeaponEnum == ActiveWeapon::AW_Katana  && Actor != this)
		{
			ValidDamageTypeClass = KatanaDamType;  //trying this out here;
			FDamageEvent DamageEvent(ValidDamageTypeClass);
			const float DamageAmount = Katana->getWeap_Damage();

			Actor->TakeDamage(DamageAmount, DamageEvent, ()->GetFirstPlayerController(), this);
			return;
		}
		if (ActiveWeaponEnum == ActiveWeapon::AW_Hammer && Actor != this)
		{
		    ValidDamageTypeClass = TSubclassOf<UDamageType>(HammerDamType); //trying this style here

			FDamageEvent DamageEvent(ValidDamageTypeClass);

		//	UE_LOG(LogTemp, Warning, TEXT("Damage Type is is: %s "), *HammerDamType->GetOwnerClass()->GetName());

			const float DamageAmount = Hammer->getWeap_Damage();
			Actor->TakeDamage(DamageAmount, DamageEvent, ()->GetFirstPlayerController(), this);
			return;
		}

hammer damage type katana damage type come from

	ConstructorHelpers::FObjectFinder<UBlueprint> HammerDamage(TEXT("Blueprint'/Game/TopDown/Character/Wasabi_Tumich/Weapon_Roster/HammerType.HammerType'"));
	ConstructorHelpers::FObjectFinder<UBlueprint> KatanaDamage(TEXT("Blueprint'/Game/TopDown/Character/Wasabi_Tumich/Weapon_Roster/KatanaType.KatanaType'"));

	if (HammerDamage.Succeeded()) {
		HammerDamType = (UClass*) HammerDamage.Object;
	}
	if (KatanaDamage.Succeeded()) {
		KatanaDamType = (UClass*) KatanaDamage.Object;
	}

and

HammerDamType and KatanaDamType are both UClass*

I’m trying to use them as damage type from the first snippet. I can’t seem to get them to work. any advice on what I’m doing wrong?

Haha!.. I knew I forgot something

so the error I get is:

Exception thrown at 0x00007FFFC67701CA (UE4Editor-CoreUObject.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

If there is a handler for this exception, the program may be safely continued.

that’s when I run through visual studios, throws an exception and forces me to break.

through just the ue4 client it’s…

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

UE4Editor_CoreUObject!UClass::GetDefaultObject() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\coreuobject\public\uobject\class.h:2196]
UE4Editor_Engine!AActor::TakeDamage() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\actor.cpp:1984]
UE4Editor_Engine!APawn::TakeDamage() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\pawn.cpp:416]
UE4Editor_Wasabi_Horizon!AWasabi_HorizonCharacter::CheckCollisionOnAttack() [c:\users\wolfw\onedrive\documents\unreal projects\wasabi_horizon\source\wasabi_horizoncharacter.cpp:763]
UE4Editor_Engine!FTimerUnifiedDelegate::Execute() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\public\timermanager.h:41]
UE4Editor_Engine!FTimerManager::Tick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\timermanager.cpp:477]
UE4Editor_Engine!UWorld::Tick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:1246]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\editor\unrealed\private\editorengine.cpp:1349]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:368]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2775]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\launch\private\launch.cpp:148]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32
ntdll

So… what error you getting?

What said, also you don’t need to do the casting, could simply do this: ConstructorHelpers::FObjectFinder HammerDamage(TEXT("Class'/Game/TopDown/Character/Wasabi_Tumich/Weapon_Roster/HammerType.HammerType_C'"));

For some reason answerhub is deleting my > / < and everything between it, the template type is a UClass following the FObjectFinder

updated with error

updated with error, I’m going to try out the helper you wrote right now! :smiley:

Hey Vaei, switching it to this actually made it work :smiley: I knew there was a better way to reference the blueprint, thank you! :smiley: