DELGOODIE
(DELGOODIE)
August 15, 2022, 9:50pm
1
So I have three blueprint classes derived from UObject and I store them in TArray<UObject*> but then I want to find an object in the array that is from a
UPROPERTY(EditDefaultsOnly) TSubclassOf<UObject> MyBPClass
How can I do this?
Basically I wish I could either:
if (Cast<MyBPClass>(Objects[0]))
if (MyBPClass == Objects[0]->Class)
using == checks for an exact match, not if a class is a subclass. Casting does check if a class is an exact match or one of its parent base classes.
if (!IsValid(MyBPClass)) {
return;
}
for (UObject* ObjectX : Objects) {
if (ObjectX->GetClass() == MyBPClass->GetClass()) {
// DoStuff
}
// or
if (ObjectX->IsA(MyBPClass->GetClass())) {
// DoStuff
}
}
This does not work:
MyBPClass* MyBPObject = Cast<MyBPClass>(ObjectX))
3 Likes
DELGOODIE
(DELGOODIE)
August 15, 2022, 10:49pm
3
Hmm Are you saying that MyBPClass is a TSubclassOf?
if so this is still not working for me!
Here is my exact code:
// InactiveAttackPool: TArray<UAttack*> (UAttack inherits from UObject)
// AttackClass: TSubclassOf<UAttack>
if (InactiveAttackPool[i]->GetClass() == AttackClass->GetClass())
{
// do stuff
== does an exact match check. Can you test the IsA method?
1 Like
eblade
(eblade)
August 15, 2022, 11:30pm
5
If youβre doing GetClass() already just do GetClass()->IsChildOf(OtherThing), else use IsA(OtherThing)
1 Like
DELGOODIE
(DELGOODIE)
August 16, 2022, 1:13am
6
So:
InactiveAttackPool[i]->IsA(AttackClass)
β true
but
InactiveAttackPool[i]->GetClass() == AttackClass->GetClass()
β false
So Iβm going to use IsA()
Thanks
Is comparable with:
5 β is a number? β true
5 == 3 β false
As in an apple is a fruit but they are not the exact same thing.