Issues Loading Objects

Okay so Im going to admit I feel like an idiot with this issue, I have a inkling I might be missing something really simple but I’ll run through it and hopefully someone can help :sunglasses:

UObject* GameAbilityObj = LoadObject<UObject>(GetOwner(), *AbilityPath);
LogTemp: Warning: LoadObject: LaunchDrone_DA 

When I load a class using UObject like this it loads fine but I need to cast this object to get access to call a function.

UIroncladGameplayAbility* IronGameAbilityObj = Cast<UIroncladGameplayAbility>(StaticLoadObject(UIroncladGameplayAbility::StaticClass(), nullptr, *AbilityPath));

AbilityPath in this instance is copied from the UAsset in the Content Browser:

"/Game/Commander/Abilities/Drone/LaunchDrone_DA.LaunchDrone_DA"

Ive tried loading the UClass manually and it loads fine as with the UObject loading fine unless its cast during load or after. UIroncladGameplayAbility is a subclass of UObject its nothing fancy, Im using it as a container to link GAS with EnhancedInput.

UIroncladGameplayAbility* CastedAbility = Cast<UIroncladGameplayAbility>(GameAbilityObj);

This also returns null which about feels where my brain is! I thought it might be an Angelscript issue but confirmed the same thing happens on stock 5.2 and 5.3 preview. Its definitely not the expected behaviour, like I said I feel like Ive missed a step but I continually get LoadObject warnings.

LogUObjectGlobals: Warning: Failed to find object 'IroncladGameplayAbility /Game/Commander/Abilities/Drone/LaunchDrone_DA.LaunchDrone_DA'

I can provide a sample project for 5.2 if anyone wants to take a look at more of the specifics but Ive tried to eliminate all possible problems outside of LoadObject. Any help would be greatly appreciated.

Thanks

Okay so my suspicion was correct, it was something I had overlooked. I was casting to a class which the Blueprint wasnt inherited from. The class being UBlueprint and having to access the GeneratedClass and then GetDefaultObject (CDO).

void UActionabilityComponent::AddAbility(FString AbilityPath)
{
	UE_LOG(LogTemp, Warning, TEXT("Path: %s "), *AbilityPath);
	
	UBlueprint* BPAbilityObj = LoadObject<UBlueprint>(GetOwner(), *AbilityPath);
	UE_LOG(LogTemp, Warning, TEXT("Load: %s "), *BPAbilityObj->GetName());

	if (BPAbilityObj)
	{
		UClass* GeneratedClass = BPAbilityObj->GeneratedClass;
		if (GeneratedClass)
		{
			UE_LOG(LogTemp, Warning, TEXT("GeneratedClass: %s "), *BPAbilityObj->GeneratedClass->GetName());

			UIroncladGameplayAbility* BlueprintInstance = Cast<UIroncladGameplayAbility>(GeneratedClass->GetDefaultObject());
			if (BlueprintInstance)
			{
				FInputActionValue InputActionValue;
				BlueprintInstance->TriggerInput(InputActionValue, 0.0f, 0.0f, BlueprintInstance->InputAction);
			}
		}
	}

This is the code that ended up allowing me to load a UObject from an Asset Path and execute a function. Funnily enough I have to give credit to ChatGPT which I used as a last resort!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.