# Accessing C++ 'Native class' and it's variables from a UBlueprint object

**URL:** <https://forums.unrealengine.com/t/accessing-c-native-class-and-its-variables-from-a-ublueprint-object/2230406>\
**Category:** C++\
**Tags:** casting, unreal-engine, Blueprint, CPP, question\
**Created:** [December 18, 2024, 2:14pm UTC](https://forums.unrealengine.com/t/accessing-c-native-class-and-its-variables-from-a-ublueprint-object/2230406 "2024-12-18T14:14:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bwbilyeu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bwbilyeu](https://forums.unrealengine.com/u/bwbilyeu)\
**Post date:** [December 18, 2024, 2:14pm UTC](https://forums.unrealengine.com/t/accessing-c-native-class-and-its-variables-from-a-ublueprint-object/2230406/1 "2024-12-18T14:14:20Z")

</div>

I am trying to check the values of the C++ ‘Native Class’ of a Blueprint object, in C++ code. I am working with a derived `EditorValidator_Base` class. I want to validate that my blueprinted `MyGameplayAbility` objects have certain fields set properly (ex: duration = 0 for duration policy of instant, positive magnitude values for healing abilities, etc).

`CanValidateAsset_Implementation` works as intended as I check for the passed asset’s class to be UBlueprint and that asset’s parent class is equal to `MyGameplayAbility`.

Within `ValidateLoadedAsset_Implementation` is where I want to access the values within the `MyGameplayAbility` class of the asset I am validating, but I cannot find any way to do this.

Is this something where I am missing the forest for the trees or is this actually a problem process?

---

<div class="post-metadata">

**Author:** ![MagForceSeven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/magforceseven/32/906563_2.png) [@MagForceSeven](https://forums.unrealengine.com/u/MagForceSeven)\
**Post date:** [December 18, 2024, 3:07pm UTC](https://forums.unrealengine.com/t/accessing-c-native-class-and-its-variables-from-a-ublueprint-object/2230406/2 "2024-12-18T15:07:07Z")

</div>

Sounds like you want to cast the `InAsset` parameter to your native type:

`UMyGameplayAbility* Ability = Cast<UMyGameplayAbility>(InAsset);`

Or am I misunderstanding?

---

<div class="post-metadata">

**Author:** ![bwbilyeu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bwbilyeu](https://forums.unrealengine.com/u/bwbilyeu)\
**Post date:** [December 18, 2024, 3:20pm UTC](https://forums.unrealengine.com/t/accessing-c-native-class-and-its-variables-from-a-ublueprint-object/2230406/3 "2024-12-18T15:20:16Z")

</div>

The object is a UBlueprint of the UMyGameplayAbility class. If I cast directly to UMyGameplayAbility, it fails. While it is possible to use a UGameplayAbility class (or derived class) directly as this asset type, this sacrifices the functionality of blueprints for special abilities and removes the need to manually code every exception.

---

<div class="post-metadata">

**Author:** ![Chatouille](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chatouille/32/1194622_2.png) [@Chatouille](https://forums.unrealengine.com/u/Chatouille)\
**Post date:** [December 18, 2024, 3:36pm UTC](https://forums.unrealengine.com/t/accessing-c-native-class-and-its-variables-from-a-ublueprint-object/2230406/4 "2024-12-18T15:36:34Z")

</div>

try accessing it via

```cpp
UBlueprint* Bp = Cast<UBlueprint>(InAsset);
UClass* Class = Bp->GeneratedClass;
UObject* CDO = Class->GetDefaultObject();
UMyGameplayAbility* Ability = Cast<UMyGameplayAbility>(CDO);

```

You might want to validate each step with a check

---

<div class="post-metadata">

**Author:** ![bwbilyeu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bwbilyeu](https://forums.unrealengine.com/u/bwbilyeu)\
**Post date:** [December 18, 2024, 3:38pm UTC](https://forums.unrealengine.com/t/accessing-c-native-class-and-its-variables-from-a-ublueprint-object/2230406/5 "2024-12-18T15:38:37Z")

</div>

That did it and thank you!

```c++
EDataValidationResult UEditorValidator_GameplayAbilities::ValidateLoadedAsset_Implementation(UObject* InAsset, TArray<FText>& ValidationErrors)
{
    UBlueprint* InBlueprint = Cast<UBlueprint>(InAsset);
    UMyGameplayAbility* Instance = Cast<UMyGameplayAbility>(InBlueprint->GeneratedClass->GetDefaultObject());

    // validation steps/logic here
}

```

---

<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:** [January 17, 2025, 3:39pm UTC](https://forums.unrealengine.com/t/accessing-c-native-class-and-its-variables-from-a-ublueprint-object/2230406/6 "2025-01-17T15:39:22Z")

</div>

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