Set actor component variable to static mesh component in actor

I have an actor component with a static mesh component variable that is exposed. I can set it to the containing actor’s static mesh component using get component by tag, but is it possible to assign it in the actor’s blueprint editor Details panel?
I can set bools, ints etc, but when I add a cube to the actor and try to add it to the component in the Details panel, it doesn’t show up.

There is a difference between a static mesh and a static mesh component.

Static mesh (variable) is a reference to the asset. Static mesh component is what shows an instance of the static mesh.

By definition, the above is not possible. You may have an actor component with a static mesh, but not with a static mesh component.


  • here’s an actor component with an exposed static mesh variable:

  • I can add it to an actor but it does not mean the static mesh will show up as we do not have anything to show it with:

  • below, I’ve just added a static mesh component to my actor, it can display the static mesh that the actor component was assigned:


Above:

  • actor has a static mesh component that can handle any static mesh
  • and actor component with a static mesh is added
  • the actor fetches the static mesh from the actor component and assigns it to its own static mesh component

Sounds like you’re building something modular.

1 Like

Something worth keeping in mind:

You can have an actor component (above) reach out to its parent, and set its smc to the static mesh the actor component was assigned. Setting up interfaces smooths out that kind of workflow dramatically.

1 Like

I was hoping to be able to drop an actor component on an actor, and drag a reference to a mesh (a mesh on same actor) to the actor component’s static mesh reference variable, but I can use the methods you describe.
Most of the time I’ll probably only need to manipulate the actors position and rotation, or call functions via an interface.

Thank you for your answer. :slight_smile: Most of what I do is modular, but I’m used to Unity’s way of doing things, and even though I’ve had fun with UE4 before, blueprints are still new to me.

1 Like

Consider the alternative:

  • override a static mesh component:

  • inside that new component:

  • when added to an actor, the static mesh will show up:

Much neater.


You could use a native static mesh component but if you override, you get a full graph:

This way you can script extra functionality right into the component that displays the mesh.

Interesting. That’s a bit like dependency injection, but with the component injecting itself into another.
I would have to experiment a bit with that, but it would not be considered “best practice” by any means would it?

I’d prefer to use a strategy pattern/component approach to every gameplay feature that I implement, where actor components handle very specific functions, and can be combined to form mechanics and features. It seems to me that UE is built with that architecture in mind, but it’s all very new to me.

It works well.

You were going to add an actor component to an actor. If the main goal was to have it handle static mesh display on that actor, it’d be better to use a specialised version of that actor component - the static mesh component.

If you follow the hierarchy:

You’ll notice that the static mesh component inherits from the actor component, and then adds extra functionality of its own - the ability to handle static meshes in this case.

Were you to build a modular robot the player attaches various meshes to, each with a life of its own, it would not be a bad idea to use this method.

Also, this new custom component can be support further inheritance.

image

So, in case of a robot, you could have a base component - a BodyPart, and a child for each of the unique Limb, Torso, Head the robo may need. Each of those can have common and/or unique functionality and variables.

It’s a powerful thing.