I have used the following code to construct an Object Class into the memory:
void UAbilitySystemComponent::add_ability(TSubclassOf<UABILITY> ability_class)
{
UABILITY* ability = NewObject<UABILITY>(GetTransientPackage(), ability_class);
if (ability)
{
UE_LOG(LogTemp, Warning, TEXT("Ability added - %s"), *ability->GetName());
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Failed to create ability - %s"), *(ability_class->GetName()));
}
}
The above code uses GetTransientPackage()
for Outer parameter and ability_class name
. The Object is also being constructed.
I am using the following code to get the Object in memory:
UABILITY* UAbilitySystemComponent::get_ability(TSubclassOf<UABILITY> ability_class)
{
UABILITY* ability = Cast<UABILITY>(FindObject<UObject>(GetTransientPackage(), *(ability_class->GetName())));
if (ability)
{
UE_LOG(LogTemp, Warning, TEXT("Found ability - %s"), *ability->GetName());
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Could not find ability - %s"), *(ability_class->GetName()));
}
return ability;
}
Although here, I am unable to find the ability. I get the Log Message -
"Could not find ability - <ability-name>"
I have also tried using GetWorld()
for Outer parameter for adding NewObject and finding object. Yet it doesn’t work!
Please help me with this. Where am I going wrong?
Something wrong with the class-name or Outer parameter?
Thanks in advance.