# Issues Loading Objects

**URL:** <https://forums.unrealengine.com/t/issues-loading-objects/1245590>\
**Category:** C++\
**Tags:** unreal-engine, question\
**Created:** [July 31, 2023, 7:23am UTC](https://forums.unrealengine.com/t/issues-loading-objects/1245590 "2023-07-31T07:23:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MonsOlympus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/monsolympus/32/619062_2.png) [@MonsOlympus](https://forums.unrealengine.com/u/MonsOlympus)\
**Post date:** [July 31, 2023, 7:23am UTC](https://forums.unrealengine.com/t/issues-loading-objects/1245590/1 "2023-07-31T07:23:30Z")

</div>

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 🕶

```auto
UObject* GameAbilityObj = LoadObject<UObject>(GetOwner(), *AbilityPath);

```

```auto
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.

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

```

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

```auto
"/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.

```auto
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.

```auto
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

---

<div class="post-metadata">

**Author:** ![MonsOlympus](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/monsolympus/32/619062_2.png) [@MonsOlympus](https://forums.unrealengine.com/u/MonsOlympus)\
**Post date:** [July 31, 2023, 11:42am UTC](https://forums.unrealengine.com/t/issues-loading-objects/1245590/2 "2023-07-31T11:42:44Z")

</div>

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).

```auto
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!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [August 30, 2023, 11:43am UTC](https://forums.unrealengine.com/t/issues-loading-objects/1245590/3 "2023-08-30T11:43:07Z")

</div>

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