How to set Apex Asset via Unrealscript?

I’m having a lot of success extending ApexDestructibleActorSpawnable to spawn destruction effects for my various base building pieces.

I spawn these when the building item is destroyed.

However, there is no SetApexAsset() function on the ApexStaticDestructibleComponent class.

Meaning, currently I would have to have a .uc file for every single Apex mesh variant I want to spawn.

Deleting the const from Asset in ApexComponentBase, and then manually setting the ApexAsset doesn’t seem to work either. Then no mesh shows at all.

Is there no way to set the ApexAsset on ApexStaticDestructibleComponent via script at runtime?

if there’s no setter and removing the const doesn’t help you’re gonna have to do some tedious work sadly

making an archetype of that class allows you to change its vars in the editor in an equivalent way of changing defaultproperties in a class
you’ll still have to make an archetype for each apex asset variant, but I’d argue that creating archetypes in the editor is more clean than making a .uc class for each of them

Thanks Chosker. I hadn’t considered creating archetypes. That will be a lot less gross than what I was planning.


I’m a little confused by the nature of Archetypes. It appears the only way to use them in code is to reference them in a classes default properties. From the documentation:

var StaticMeshActor MeshActorTemplate;

// Actor archetype instancing example
function CreateActorArchetype()
    local StaticMeshActor MeshActorInstance;
    // now spawn the Actor, passing in the Archetype reference as the template
    MeshActorInstance = Spawn(class'StaticMeshActor', None, 'None', Location, Rotation, MeshActorTemplate);


My concern here is if the class may be creating an actor instance for the template, before it’s even being used. As it appears you can pass MeshActorTemplate as an Actor. There are many thousands of these actors, so i want to be careful about memory.

I know I can use DynamicLoadObject, but then I’m using strings, and not having actual references to the asset’s path in my code, which isn’t a good idea when it comes to cooking etc.

Any thoughts on this?

You’ve got two of the three ways I know how to use an archetype there. Everywhere in my own code where I use an archetype, I either set it in DefaultProperties, use DynamicLoadObject on a string, or I use the editor to set an archetype’s reference to another archetype.

So for example in my own game, I have randomly generated enemy armies. Wolf armies, undead armies, and bandit armies all have different pawns that they will spawn when the army gets created. I create an army archetype, and then in the army class, there’s an array that I use to hold the possible pawn archetypes that can spawn in that army. They all use the same code to spawn their soldiers; they just have different archetypes they’ll spawn soldiers from.

I don’t know exactly if this would work, but I think that for you, you could make a class that extends ApexStaticDestructibleComponent, and give it a var() ApexAsset (or var() array<ApexAsset>) of the apex asset (or array of possible apex assets) you want it to spawn. And then in the editor, you create an instance or archetype of whatever child class of ApexStaticDestructibleComponent you created, and then you set that instance/archetype’s apex asset.