Detect loaded classes / u files for dependencies?

Discussions about Coding and Scripting
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Detect loaded classes / u files for dependencies?

Post by 1337GameDev »

I am curious on the best / most reasonable manner to detect if a particular class / file is loaded?

Code: Select all

function book HasLoadedDependencies(){
    local SpecialObject obj1;
    Local SpecialActor act1;

    obj1 = new class'SpecialObject'();
    act1 = Spawn(class'SpecialActor');
}

Or do I have to use dynamic load and load the class variable into the types:

Code: Select all

local class<object> obj1;
local class<actor> act1;
How would this be done, and what's the best way to go about this?

Edit:

I did find an example of dynamic load, but unsure if it's the best way to go about things:

Code: Select all

act1 = class<Actor>(DynamicLoadObject("MyPackage.SpecialActor", class'Class'));
Then could just check for (act1 == None).

Would this be reasonable?
User avatar
sektor2111
Godlike
Posts: 6442
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Detect loaded classes / u files for dependencies?

Post by sektor2111 »

Probably yes, it's reasonable as long as I'm using this way inside NavAdder. It doesn't fail - "DynamicLoad" has the other switch because XC_Engine is fixing it.
NavAdder.7z
Completely Server-Side but capable to map Packages when are needed. NavAdded.upkg files used in source-code will set Package flags properly.

Code: Select all

[Flags]
ServerSideOnly=True
AllowDownload=False
ClientOptional=False
You do not have the required permissions to view the files attached to this post.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Detect loaded classes / u files for dependencies?

Post by 1337GameDev »

Interesting. What is navadder? A way to patch navigation, dynamically for maps to help with new mods or etc, and don't want to distribute new versions of older/stock maps?

If this is true, i'm curious how you modify this, as i wnat to modify navigation as well at runtime
Buggie
Godlike
Posts: 3227
Joined: Sat Mar 21, 2020 5:32 am

Re: Detect loaded classes / u files for dependencies?

Post by Buggie »

1337GameDev wrote: Sun Jan 16, 2022 2:21 am I am curious on the best / most reasonable manner to detect if a particular class / file is loaded?
Exists trick with usage classes only when they loaded before, without create dependency. For example:

Code: Select all

var class<Actor> GateClass;

event PostBeginPlay() {
    Super.PostBeginPlay();
    SetPropertyText("GateClass", "class'gateways'");
}
now GateClass filled with class'gateways' only if it loaded on server. if no, there be None. No any dependency. With class you can do all stuff: use in iterators, compare by name, check for subclass of and so on.
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: Detect loaded classes / u files for dependencies?

Post by 1337GameDev »

Well, what if my code depends on another mod / package....

If I call SetPropertyText like that.... would it be "none" if it cannot find class<gateways>?

Wouldn't I instead want to use a dynamic load?

And does postbeginplay only execute on a server? Wouldn't I need to check for ActorRole to see if it's an authority?
User avatar
anth
Adept
Posts: 257
Joined: Thu May 13, 2010 2:23 am

Re: Detect loaded classes / u files for dependencies?

Post by anth »

Code: Select all

ClassesList = Level.ConsoleCommand("obj list class=class");
ClassTree   = Level.ConsoleCommand("obj classes")$" ";
Buggie
Godlike
Posts: 3227
Joined: Sat Mar 21, 2020 5:32 am

Re: Detect loaded classes / u files for dependencies?

Post by Buggie »

If your code strictly depends (not weak) to some class - just use it. In any form. You can define local variable of this type for example.
All of this lead to include this classes/packages to dependency by compiler, and loaded later by linker. no any special steps need.

Tricks need only if you want make code independent from presence some packages with optional features.

For example, viewtopic.php?f=7&t=14969 - mutator which work for any game type, but if run against Gauntlet do some additional functionality.

If it will be coded in usual way, it will be require gauntlet for work, which not acceptable.

> Well, what if my code depends on another mod / package....
If no any special requirements (as above), for make code independent and optionally do some functionality, then just use need classes.

> If I call SetPropertyText like that.... would it be "none" if it cannot find class<gateways>?
Yes.

> Wouldn't I instead want to use a dynamic load?
Who knows. Depends from what you want or need. It is different approaches for solve different kind of problems.

> And does postbeginplay only execute on a server? Wouldn't I need to check for ActorRole to see if it's an authority?
If function not labeled as simulated, then it (usually) not run on role less from authority. Usually (but not always) it is sounds as "on client".
But if you spawn actor on client, then actor authoritative here, and all non-simulate function run fine here.
User avatar
sektor2111
Godlike
Posts: 6442
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Detect loaded classes / u files for dependencies?

Post by sektor2111 »

1337GameDev wrote: Wed Jan 19, 2022 11:02 pm Interesting. What is navadder? A way to patch navigation, dynamically for maps to help with new mods or etc, and don't want to distribute new versions of older/stock maps?

If this is true, i'm curious how you modify this, as i wnat to modify navigation as well at runtime
Exactly, you are not sure if there will be or not a future patch plugin, so mutator is "testing" if plugin is there and it's loading that if it does exists. Plugin loaded is automated by Engine with normal calls to PreBeginPlay PostBeginPlay and all related "auto state" stuff so it will go active by itself when mutator spawns it. Plugin can be even removed later (when other map is being loaded), and no changes are needed anywhere.

What's a "master-piece" here ?
Client part (when is used) is mapped as package like is called by map itself, this is one of features added to XC_Engine which is helping a lot. You don't need to load 500 ServerPackages, you load what you need and only when you need, saving resources. Also XC_Engine is opening access to do "functions replacements" and accessing ReachSpecs which is another big plus in front of a plain server. There (in XC assets) you can see how to map a package in certain game conditions and only if package is there - this was main base biography for NavAdder - fix "dripgenerator" only if loaded map has the bugged thing or else nothing needs to be fixed and charging memory for no purpose.

In current context, your mutator might go inactive if required dependencies are missing from game-server, and even logging if it was a problem in loading certain class and not messing with Null objects in any way. Stock UT might have another sort of "How To" in function "ReplaceWith" located in class Engine.Mutator but that's a very basic one - for me that function is not ready and never was. That function replaces an actor only if replacement exists or else source actor it's just destroyed replaced with nothing.
Run-Time assets for navigation which I wrote so far were concerning certain map as main target, nothing common yet, scripted solutions here might fail in certain "special map" and then... to me this way is no way. In exchange if you know that you need something polished in a stock map, you don't need a new map-file and so a new package for player. All paths related task are Server-Side. Applying/Adjusting paths is doable in multiple ways: using a Tester Pawn with a short LifeSpan, either way if Pawn is messing up around you can use "hard-coded" paths previously captured from a temporary copy of evil map.

This package by example has patch plugins for map DM-Phobos and has two files: Server-Side and Client Package part. They are loaded if are there or else nothing happens - Client package is mapped automatically as ServerPackage only for map DM-Phobos. The part concerning client has fixes for "asteroids" which nobody could ever see them On-Line in a stock server. This is another sort of "How To" do net stuff without a lot of extra-channels and without replicating to much extra-data.