Performance Discussion (Spawning Mesh vs Spawning Actor)

Hi,

I was wondering if there are any performance differences between directly spawning a Static Mesh and spawning an Actor that represents that Static Mesh?

I aim to generate meshes procedurally and randomly, and creating an actor would offer more functional benefits. However, I don’t want to compromise performance. If it’s necessary, I prefer sacrificing these functional benefits for significant performance gains. Otherwise, I would prefer to spawn an Actor.

Does anyone have any insights or clarification on this matter?

Thank you!

Static meshes are derived from actors

class AStaticMeshActor : public AActor { ... }

They internally have a UStaticMeshComponent. The static mesh component can’t live in the world by itself, it needs an actor to attach to.

If you turn off tick in your custom actor then you should get comparable performance.

3 Likes

Hey @3dRaven thanks for your answer. But what about creating a static mesh onto an actor directly?

For example, I am making an inventory system where I don’t want to spawn actors and attach to my character all the time. So, if I wish to wear a helmet or armour, equip a shield or wear boots, I was thinking if I could add a static mesh component to my actor dynamically. And then set the static mesh with that relevant asset - spartan_helmet, golden_armour, elven_boots etc.

Of course, in a multiplayer setting, this should be a NetMulticast RPC if I’m not wrong.

So, what is your advice?

Do you think I should spawn an actor that replicates, and on RepNotify - change the static mesh of that item for all clients to that static mesh asset?
Or spawn static mesh components attached to my character’s skeletal socket - with NetMulticast?

I do wish to bind overlap events for certain static meshes, like a sword / axe / spear - there’s that requirement too!

Please help! Thanks in advance.

For equipment on the character you should have skeletal mesh component that match your character skeleton and use the leader pose to drive the mixed meshes as 1 character combination.

You should set the skeletal mesh component’s mesh via on rep notify so that it updates even for people that later join your game.

Only part where static meshes would be useful is if the clothes / armour doesn’t deform at all. Though it’s extra overhead in that you need extra functions to handle the attachment to a specific bone.

This is a tough task when it comes to body armour as you may get the underlying clothing to clip through the armour at angles.(it’s more a rigging problem though than an unreal one)

To further the optimizations you could combine the skeletal meshes into a new one at runtime, but that would probably require more work.

1 Like

Alright, will look into Skeletal Mesh merge, that could help me.

Yeah, RepNotify on mesh components could be a great place to render the right static mesh.

How are functions to attach to a specific bone an overhead? Isn’t it always done that way - Spawn Actor and Attach to socket?
(Or for some items in my game, create static mesh at SkeletalMesh-socket, and then update mesh in ReNotify)?

Please let me know, Thanks @3dRaven!

You can either

  • have the up front cost of having skeletal / static mesh component on the character and save processing time for adding / removing components

  • dynamically add / remove them paying the cost of spawning and deleting components at runtime but saving some memory.

Thanks for the quick response!

So, I wish to dynamically add static mesh components to actors at their skeletal mesh sockets. It would look something like this:

Eg: A glove on right arm -

  1. (RPC server) granting a static mesh component,
  2. (server ) set to replicate
  3. (server) attach to socket - weapon_r (on hand_r bone)
  4. (server) change static mesh asset to “SM_red_glove”

Is this less taxing on memory and faster than spawning an actor called “red_glove_actor”?
Even in a multiplayer setting?

In such cases, it would be better to preserve or keep the same static mesh to, maybe, spawn a shield static mesh at the same socket right?

I would personally do this in the on rep notify function passing in the needed mesh and socket name.
The function could then

  • spawn the static mesh and attach (if dynamic)
  • set the preset static mesh component to needed mesh (if static)
1 Like

Yeah, this could work!

Thanks @3dRaven for your help and advice!