Equivalent of IsValidClass Node in C++?

I am looking for a function equivalent to node (IsValidClass) in C++.

1

I tried something like this but the function doesn’t exist, or I don’t have the necessary include.

IsValidClass();

I can’t find the solution on Google either.

Do you know how to do it?
Thank you so much!!

ok… i found this in the Lyra code

TSubclassOf PartClass = ULyraDevelopmentStatics::FindClassByShortName(AssetName);

if (PartClass != nullptr)

I hope it works

Perhaps this is what you’re looking for?

UKismetSystemLibrary::IsValidClass(const UClass *Class);

The above method forwards to:

::IsValid(const UObject*);

Also you can do it like that :

if (IsValid(YourClass))
{
}

or

if (YourClass)
{
}

Thank you very much for your reply

1

However it appears to be a private member of the class

Just use IsValid().

Thanks for your reply
I’m going to try it.

Not sure if it will work though… seems to only work with classes derived from UObject.

1

This class is not derived class derived from UObject
2

But this is a derived class derived from UObject

3

3

4

5

So maybe I should use it this way

6

I’m going to try it and then come back here to say what happened.

Thank you very much for your help!!

UClass does derive from UObject. TSubclassOf is just a wrapper that holds a pointer to a UClass.

So IsValid() is correct.

And you shouldn’t need to call .Get() on a TSubclassOf. It should just work. I have tried it and it compiles.

edit: The reason it works with TSubclassOf despite not deriving from UObject is because it has an operator that will return the contained pointer and since that pointer does derive from a UObject, it should just work. These are implicit conversions that the compiler will do.

Ok, I will do as you say, thank you very much for your explanation!

Thank you so much :heart: