Page 1 of 1

Detect if Actor is a class but NOT a child of that class

Posted: Sat Jan 22, 2022 4:22 am
by 1337GameDev
I am curious if there's a way to detect if a class is EXACTLY a specific class, but not a subclass.

An example could be if I subclass a particular Botpack weapon, but want to detect the original.

I thought about doing these:

Code: Select all

function bool isSpecificEnforcer(Inventory inv) {
    local Enforcer enf;
    enf = Enforcer(inv);

    if(enf != None) {
        //inv is an enforcer, but could be a subclass?
        return true;
    }

    if(inv.IsA('Enforcer') ){
        //inv is an enforcer, but could be a subclass?
        return true;
    }

    if(inv.Class == class'Enforcer') {
        //inv class is EXACTLY an enforcer? 
        return true;
    }
    
    return false;
}
What is the best approach?

Re: Detect if Actor is a class but NOT a child of that class

Posted: Sat Jan 22, 2022 5:38 am
by sektor2111
:???:
I don't get why you don't use "ClassIsChildOf" for figuring if said enforcer is not another enforcer resident elsewhere than Botpack ?
Also Actor set as variable will be listed as "Package.Class" where you can parse string for figuring if "BotPack" or another stock word it's part of the whole variable definition.

Re: Detect if Actor is a class but NOT a child of that class

Posted: Sat Jan 22, 2022 7:47 am
by Buggie
> if Actor is a class but NOT a child of that class
Actor != None && Actor.Class == DesiredClass

> if Actor is a class but ONLY a child of that class
DesiredClass(Actor) != None && Actor.Class != DesiredClass

Re: Detect if Actor is a class but NOT a child of that class

Posted: Sat Jan 22, 2022 10:04 am
by Barbie
A remark to type conversion vs. "IsA()":

Code: Select all

enf = Exampleclass(inv);
if(enf != None)
vs.

Code: Select all

if (inv.IsA('Exampleclass'))
Both give always the same result: inv is an Exampleclass or a sub class. I use the former when Exampleclass is known to the compiler. The latter, when Exampleclass is not known. But that one has the risk of undetected spelling errors.

Re: Detect if Actor is a class but NOT a child of that class

Posted: Sat Jan 22, 2022 10:35 am
by Buggie
Not exactly.

First check inv against well-know class Exampleclass. It is mean used exactly this class, and we travel on parent until find it, or until reach root.

Second check do almost same, except we check against name, not class. So if exists few classes with same name Exampleclass - then will be match against any.

UnrealShare.TriggerLight and Engine.TriggerLight is stock example about that.

Actor.isA('TriggerLight') - match both and require Actor != None

TriggerLight(Actor) != None - match only specific TriggerLight (Which compiler see first, and fine work when Actor == None.

Re: Detect if Actor is a class but NOT a child of that class

Posted: Tue Jan 25, 2022 7:13 am
by 1337GameDev
All great examples and confirms my suspicions :) Thanks for the collaborative help on this. Much appreciated :)