Event Hit - Get a materials texture file name?

Hi all… I’m pretty new to Unreal and BP but have been developing software for years.

Using the First Person Blueprint template, I’m trying to create a proof of concept where I have a “Plane”, that will display an image. Think road side billboard.
I dragged a JPG file into the project, right click, created a material. Assigned that material to the Plane. Created a BP out of that plane.

In the Plane Blue Print, I am subscribing to the On Component Hit event and printing a string when a projectile hits the plane. This is working.

Ultimately, what I want is the actual path and name of the JPG file that’s attached to the material, that’s attached to the Plane. Reason is, I need to take the JPG file and send it somewhere else for processing.

So basically, I shoot at the plane, On Component Hit fires, I need to get the StaticMeshComponent get the material, get the Texture, get the file name of the JPG file.

I was hoping that Get Material Index would help me out but, my lack of understanding how this function is working is stopping my progress. The documentation for this function does not say much. Which to be honest, I’m not even sure this would be the proper function in the first place.

This is the beginning of my Plane Blue Print. I know there is a LOT more to add.

Any help will be greatly appreciated!!!


I don’t know exactly what you are trying to do but why is getting the material not enough? You probably don’t need the name of the texture and you certainly don’t need the name of the .jpg. Get the material OnComponentHit and store that in a “Material Instance Variable”, then place that where ever you need it from there. Try a “Get Material” node in place of “Get Material Index”. The index will just give you a number, you want the material itself. You can define the index in the “Get Material Node”.

If you actually need the texture name itself I believe you will need to make a “Dynamic Material Instance”. That is a bit more complicated. If you can suffice with the material itself then that is pretty straight forward. Do the same set up as you have now but switch the “Get Material Index” node with a “Get Material” node. Create a variable of a Material Instance and set that with the material that you are getting from Static Mesh Component.

I don’t know your exact blueprint set up but remember variables have to be properly Set otherwise you will get “Access None” errors. These are pretty confusing errors for the first year or two of Unreal use (they were for me at least). From the looks of this set up though you shouldn’t get an Access None when storing the material.

Actually, I think I might. As mentioned I’m creating a proof of concept that will integrate with an external image processing tool. The POC is basically here to figure out the ins and outs of integrating with Unreal. But ultimately, we need to send the actually image out to an external source. Seems a little ahead of myself but at this point, I don’t know if I need to send a string (path) to a physical file on the hard drive or the raw bitmap array just yet. I’ll learn more about that later. For now, I’m going on the simple approach, figure out the file path to the physical texture/jpg and send it where it needs to go.

Thanks Allen, I will give this a shot.

Thanks for the heads up, I appreciate all the help. :slight_smile:

Hum… offhand. In the material you have to designate the texture as a parameter so that it can be exposed and accessed along with the material.

You may want to look I to material functions as well.

I’m assuming you are probably processing the actual JPG via custom cpp since you are using a jpg rather then better file formats.
I’m not sure how well a jpg swap would run at runtime though.

Also, in this tutorial they were shooting at the wall and changing it, so maybe you can get something off it.