Check if an Actor is abstract

Discussions about Coding and Scripting
User avatar
Barbie
Godlike
Posts: 2069
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Check if an Actor is abstract

Post by Barbie » Thu Mar 25, 2021 10:05 pm

Is there a possibility to check if a given Actor string like "Class'UnrealShare.Skaarj'" describes an abstract class without spawing it? I want to realize something like

Code: Select all

var() class<actor> prototype;
...
if (IsAbstract(prototype))
	warn("cannot spawn an abstract Actor");
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett

Buggie
Adept
Posts: 421
Joined: Sat Mar 21, 2020 5:32 am

Re: Check if an Actor is abstract

Post by Buggie » Thu Mar 25, 2021 10:50 pm

Look like no any direct way determine this.

You can try instantiate object directly with key word new, but it is very Buggie bugged way.

Like that:
https://github.com/Slipyx/UT99/blob/f2e ... dow.uc#L60

Code: Select all

LooksAndFeels[i] = new LFClass;
If result None (or game/server crash :lol2: ) then you try do it on abstract class.

Also even if this work initially, then on garbage collection can be another crash...
Or in new UT version even if now all fine. :loool:

--- EDIT --

Partially solution - make list of all standard abstract classes and compare full Class with it.
Also need pray and cross fingers for any author will be not smart enough for use abstract classes or pass to your code. :lol2:

--- EDIT ---
Buuuuu!
Show

Code: Select all

Botpack/Classes/Arena.uc:       abstract;
Botpack/Classes/Bot.uc: abstract;
Botpack/Classes/ChallengeVoicePack.uc:  abstract;
Botpack/Classes/FemaleBotPlus.uc:       abstract;
Botpack/Classes/HumanBotPlus.uc:        abstract;
Botpack/Classes/Ladder.uc:      abstract
Botpack/Classes/MaleBotPlus.uc: abstract;
Botpack/Classes/StationaryPawn.uc:      abstract;
Botpack/Classes/TFemaleBody.uc: abstract;
Botpack/Classes/TMaleBody.uc:   abstract;
Botpack/Classes/TournamentAmmo.uc:      abstract;
Botpack/Classes/TournamentConsole.uc:   abstract;
Botpack/Classes/TournamentFemale.uc:    abstract;
Botpack/Classes/TournamentHealth.uc:    abstract;
Botpack/Classes/TournamentMale.uc:      abstract;
Botpack/Classes/TournamentPlayer.uc:    abstract;
Botpack/Classes/TournamentWeapon.uc:    abstract;
Botpack/Classes/UTHumanCarcass.uc:      abstract;
Botpack/Classes/UT_Decoration.uc:       abstract;
Botpack/Classes/VoiceFemale.uc: abstract;
Botpack/Classes/VoiceMale.uc:   abstract;
Core/Classes/Commandlet.uc:     abstract
Editor/Classes/BrushBuilder.uc: abstract
Engine/Classes/Actor.uc:        abstract
Engine/Classes/Ammo.uc: abstract
Engine/Classes/DamageType.uc:   abstract;
Engine/Classes/Decoration.uc:   abstract
Engine/Classes/HUD.uc:  abstract
Engine/Classes/Info.uc: abstract
Engine/Classes/Inventory.uc:    abstract
Engine/Classes/Keypoint.uc:     abstract
Engine/Classes/MessagingSpectator.uc:   abstract;
Engine/Classes/Pawn.uc: abstract
Engine/Classes/Pickup.uc:       abstract
Engine/Classes/Projectile.uc:   abstract
Engine/Classes/ReplicationInfo.uc:      abstract
Engine/Classes/VoicePack.uc:    abstract;
Engine/Classes/Weapon.uc:       abstract
Fire/Classes/FractalTexture.uc: abstract;
Fire/Classes/WaterTexture.uc:   abstract;
MultiMesh/Classes/CustomBot.uc: abstract;
MultiMesh/Classes/customplayer.uc:      abstract;
Relics/Classes/Relic.uc:        abstract;
UBrowser/Classes/UBrowserServerListFactory.uc:  abstract;
UnrealI/Classes/Burned.uc:      abstract;
UnrealI/Classes/Corroded.uc:    abstract;
UnrealI/Classes/Decapitated.uc: abstract;
UnrealI/Classes/Drowned.uc:     abstract;
UnrealI/Classes/Fell.uc:        abstract;
UnrealI/Classes/UnrealDamageType.uc:    abstract;
UnrealShare/Classes/Bots.uc:    abstract;
UnrealShare/Classes/DeadMales.uc:       abstract;
UnrealShare/Classes/Female.uc:  abstract;
UnrealShare/Classes/FemaleBot.uc:       abstract;
UnrealShare/Classes/Human.uc:   abstract;
UnrealShare/Classes/HumanBot.uc:        abstract;
UnrealShare/Classes/HumanCarcass.uc:    abstract;
UnrealShare/Classes/Male.uc:    abstract;
UnrealShare/Classes/MaleBot.uc: abstract;
UnrealShare/Classes/ScriptedPawn.uc:    abstract;
UnrealShare/Classes/ShareSounds.uc:     abstract;
UnrealShare/Classes/Skaarj.uc:  abstract;
UnrealShare/Classes/UnrealIPlayer.uc:   abstract;
UTMenu/Classes/MeshBrowser.uc:  abstract;
UTMenu/Classes/UTLadder.uc:     abstract;
UTMenu/Classes/UTLadderStub.uc: abstract;

User avatar
sektor2111
Godlike
Posts: 5209
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Check if an Actor is abstract

Post by sektor2111 » Sun Mar 28, 2021 9:18 am

Thanks for the list, Buggie. I think future checkers will go based on this list instead of attempting to spawn abstracts and checking them. The rest means private patching when a "mapping" surprise shows up from nowhere.

User avatar
Barbie
Godlike
Posts: 2069
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Check if an Actor is abstract

Post by Barbie » Sun Mar 28, 2021 12:44 pm

Thanks for all replies.
That information must be somewhere inside an Actor because function Spawn() tells you that an Actor cannot be spawned because it it abstract.
Buggie wrote:
Thu Mar 25, 2021 10:50 pm
Partially solution - make list of all standard abstract classes
BTW: I suspect that the star in front of a class name in UnrealEd v469b indicate an abstract class?
Stars.jpg
You do not have the required permissions to view the files attached to this post.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett

User avatar
OjitroC
Godlike
Posts: 2334
Joined: Sat Sep 12, 2015 8:46 pm

Re: Check if an Actor is abstract

Post by OjitroC » Sun Mar 28, 2021 1:09 pm

Barbie wrote:
Sun Mar 28, 2021 12:44 pm
BTW: I suspect that the star in front of a class name in UnrealEd v469b indicate an abstract class?
Yes, it does - it took me a while to work that out. First noticed that in the 227 Editor.

User avatar
Feralidragon
Godlike
Posts: 5300
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Check if an Actor is abstract

Post by Feralidragon » Sun Mar 28, 2021 9:53 pm

As others said, there's no such function or flag that you can check, as far as I know.
The engine obviously knows what's abstract and what isn't, but that isn't exposed to UScript, even because that would essentially amount to a "reflection" feature, which UScript has none of.

Why exactly do you want to do this?
Considering that the spawn fails already with abstract classes, and it gets logged and the game doesn't crash, what's the problem you're trying to address here?

User avatar
Barbie
Godlike
Posts: 2069
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Check if an Actor is abstract

Post by Barbie » Sun Mar 28, 2021 10:57 pm

Feralidragon wrote:
Sun Mar 28, 2021 9:53 pm
what's the problem you're trying to address here?
I have a Mutator that checks some things in a map and this topic is especially for Factories where the prototype is an abstract class.
No mapper does such? It happened even to myself when I thought "oh, let's spawn some Skaarj here"... :loool:
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett

User avatar
Feralidragon
Godlike
Posts: 5300
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Check if an Actor is abstract

Post by Feralidragon » Sun Mar 28, 2021 11:40 pm

Never mentioned that no mapper does it, especially having it done myself in my early days. :)
I was trying to understand what exactly you were trying to accomplish.

That makes sense, but unfortunately you can't do that directly.

In that case Buggie's suggestion of a list makes most sense, since that mistake is common for standard Actors, whereas for custom ones from custom packages not so much, so knowing if a custom actor is abstract may not be that important in relation to what you're trying to do.

User avatar
sektor2111
Godlike
Posts: 5209
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Check if an Actor is abstract

Post by sektor2111 » Mon Mar 29, 2021 5:30 am

"MH Mapper" perhaps uses mainly stock things as long as compiling classes in plain MH it's impossible and advanced users know what they do. I was thinking at an array with these abstract classes and testing if prototype is abstract comparing class with said embedded hard-coded stock array - or flexible array for future needs.

Buggie
Adept
Posts: 421
Joined: Sat Mar 21, 2020 5:32 am

Re: Check if an Actor is abstract

Post by Buggie » Mon Mar 29, 2021 11:21 am

Barbie, I just say more. Even if custom code use abstract class, you always can extends your exclude list, when face this issue.

User avatar
Shadow
Masterful
Posts: 725
Joined: Tue Jan 29, 2008 12:00 am
Personal rank: Mad Carpenter
Location: Halle/Leipzig, Germany

Re: Check if an Actor is abstract

Post by Shadow » Mon Mar 29, 2021 2:58 pm

You could write a simple native function that reads the ClassFlags property of the class you want to check:

Code: Select all

if (CheckedClass->ClassFlags & CLASS_Abstract)
{
  // this is an abstract class
}
Image

Buggie
Adept
Posts: 421
Joined: Sat Mar 21, 2020 5:32 am

Re: Check if an Actor is abstract

Post by Buggie » Mon Mar 29, 2021 4:03 pm

Native code mean next:
1. Build .dll and .so file.
2. Mess with compilers and linked stuff.
3. Prey it is work when you update server, because native code not compatible for any new patch.

User avatar
Shadow
Masterful
Posts: 725
Joined: Tue Jan 29, 2008 12:00 am
Personal rank: Mad Carpenter
Location: Halle/Leipzig, Germany

Re: Check if an Actor is abstract

Post by Shadow » Mon Mar 29, 2021 4:19 pm

Yes, kinda. Native code should work with 469a at least. 469b is unusable for c++/native coding tho.
Sry, but there's no other way to check, if a class is abstract beforehand, because UClass has no script (checking X UClass->ClassFlags)..
Image

Buggie
Adept
Posts: 421
Joined: Sat Mar 21, 2020 5:32 am

Re: Check if an Actor is abstract

Post by Buggie » Mon Mar 29, 2021 4:30 pm

Also if this code must run on client side you in big trouble, because client can be v436 and v469. How handle this - IDK.

User avatar
Shadow
Masterful
Posts: 725
Joined: Tue Jan 29, 2008 12:00 am
Personal rank: Mad Carpenter
Location: Halle/Leipzig, Germany

Re: Check if an Actor is abstract

Post by Shadow » Mon Mar 29, 2021 4:50 pm

That shouldnt be much of a problem, because the core mechanics of 436 and 469 shouldnt differ on this level, at least concerning UClass behavior, but I'm not 100 % sure, there're still NO public headers for 469 out there.
Image