Download

How do I assign a texture map to a mesh programmatically?

Under normal circumstances, when setting up a level, I understand that you can place an instance on a map, and then drag the texture map onto the instance, and it applies the texture automatically.

However, because my pawn is being placed by a PlayerStart object, I don’t think I can do that. Can someone tell me what the command is to apply a texture programmatically from the Content folder?

To be clear, my texture was created from a PNG file.

I’m confused… You have a pawn with a mesh that doesn’t have a texture. Then you place that pawn on the map and then you drag a texture to apply the texture the pawn? Is that it?

I have a blueprint for a pawn that has an assigned mesh, but no texture. The pawn is spawned by a PlayerStart object, so I’m not clicking and dragging it into the map beforehand.

[EDIT] To provide a visual aid, I want the newEagleMap15 texture to be applied to the eagle skeletal mesh assigned to the pawn in the blueprint.
image

Why don’t you apply a material with a texture to the mesh instead?
Edit:
Create material with texture, open the mesh, apply the material.

There are several ways to “update the texture for a pawn.”
First, you typically want to actually apply a material instance, not just a “texture.”
Thus, prepare a material instance (or multiple material instances, if you want different looks) that can apply to the mesh.
Then, you have some options.

  1. Build a blueprint with the mesh. Apply the material to the mesh in the blueprint. The blueprint is now a “mesh with texture.” Set the blueprint as your Pawn. No need to apply the material manually after this.
  2. In the Pawn, either in BeginPlay or perhaps in Construction Script, apply the material to the mesh. You can make the material-to-apply a property on the Pawn, or you can calculate it using logic (e g, “team 1 == red, material team 2 == blue material, …”)
  3. In some other logic, get ahold of the pawn as an object, get ahold of the mesh sub-component, and update the material reference in the appropriate slot to be the material you want.

Okay, well it turns out I was able to combine a texture with the preexisting Material I had and it created a new material that I was able to assign to the pawn. Everything looks good now.