How do I change a mesh in a Construction Script based on a class variable?

I have a Spawner object which has a class variable of type “SpawnableObject” called “ThingToSpawn”.

Each child of SpawnableObject has a different mesh.

When I place a Spawner object in a level, I want it to grab the mesh from the SpawnableObject class which is the current value of the ThingToSpawn variable.

How do I get the SpawnableObject’s static mesh without spawning and instance of that class?

Nope thats not possible. Can I ask what exactly you want to achieve. Sounds like you overcomplicate things. If you just want to async load use a Soft object refference and resolve it during construction.

Use a Struct to pack your data that you need together like the class to Spawn and the Soft Obj ref.

1 Like

As I understood he wants it the otherway around getting the variable before Spawning via class refference. But you would be correct with this =)

Here’s an example: I’m creating a Spawner which level designers can place in the world. There is a variable which they can set to a class, for instance “Speed Powerup”. Speed Powerups (and all other powerups) inherit from SpawnableObject.

When you place a Spawner in a level and set it’s variable to a powerup type, I want the mesh for that powerup to show in the editor, so level designers can visualize their placement. The mesh varies based on which powerup they choose. We’ll continue creating new powerups as the project goes on, so I don’t want to have to keep updating an array of meshes that correspond to each class, I just want to use the static mesh component of SpawnableObject.

Hmm the closest I can come up with is this one without writing a Editor only script in C++

just disable the preview in the details Panel if you are done with positioning and you will have no overhead during Play. Just as safty I removed the child Component if it exist (in case a Artist forgets it)

Forgive me if I am misinterpreting your question.

In the details panel of any variable there is an option for making it “Instance Editable” and Expose on Spawn". If you select both of them whenever you call a spawn event for that class you set that variable before the object is spawned.

I’ve made it a bit further by adding a “Spawner Preview Mesh” variable to the class defaults. By setting the type to Asset ID I can choose a mesh in the SpawnableObject and it can be applied in the Construction Script of the Spawner. At least then I’m setting the mesh in the same object.

Yep, I’m trying to avoid spawning the spawnable object in the editor, only at runtime.