How to save copies of components with their materials? Nested arrays.

Hello,
I am making a blueprint which will change some objects’ materials to one single material and then turn their materials back to the initial ones.

For that I am making a copy of an array of components trying to save their initial information before changing. Then I change materials of the initial components, and come back to the copy of the components to extract their materials back. But their materials are already vanished and all are called like Material Instance Dynamic 90 instead of real different materails.

How to save the copy of components as a fully separete copy with all materials?

This is the blueprint, but probably it is not very clear. However I am attaching. Thank you.
This is a full size of the image: question.jpg - Google Drive
I’ll be very thankful for your help.

1 Like

I think it’s because you change the materials, but when you go back over the array of components, the getmaterial call

is getting the actual current material, which is your replacement material.

In order to get the functionality you’re looking for, you also need to save the materials in an array :slight_smile:

1 Like

Thank you @ClockworkOcean, I indeed already tried to save materials as well but for some reason in this case it applied marerials randomly in not the right order. Like Arrays are getting mixed inside for some reason. Can it be? And what can be the reason? I am also going to try to save materials in arrays inside arrays, maybe it will allow to save the order. Before I saved them in a single array. I will update you asap probably tonight.

1 Like

It’s a messy process. You would need a map of type

Primitive component object reference: StructA

Where StructA is an array of material interface object references

That way you can easily look the component up in the map, and automatically get the list of materials.

Why do you need to do this, btw? :slight_smile:

1 Like

@ClockworkOcean thank you for your replys. I make a functions where by pressing “X” some but not all objects turn to X-Ray material, let’s say like an X-Ray Glasses function. It is a transparent material with Fresnel on opacity. So, some objects become like holograms or under X-ray. Honestly there are a lot of objects which I have already placed in the scene so it would be difficult to reasamble them into a bluprint, that is why I try to retrieve them right from the scene.

About your StructA advice, do you mean I should create a structure to keep the materials? Well, I already tried it for components, and it works absolutely the same way as a variable. Frankly I am pretty new in UE5, so I never used structures before. However, it turns out that it looks almost the same like a variable for me, just in a separate file.

I was just trying to make an example, it’s worse than I thought :slight_smile:

Will come back in a while…

@ClockworkOcean thank you bro :slight_smile: Can I ask, is there a way to create something like arrays into arrays in BluePrints? UE5 advises exactly what you said, to use a struct. But I can’t find the way of adding new variables via BP to a struct. So like adding a new array into an array, I hope you understand what I mean. So mainly I am going to use a struct like an array or arrays you know. And I need a way of adding new arrays to this struct, could you give me a tip of how to do it please? Thanks in advance.

1 Like

You can have nested arrays, and how you do that is using structs.

But I think you can have an easier system, will come back…

1 Like

@ClockworkOcean thank you, I am looking forward to hearing from you.

Recording the materials goes a bit like this

and playing them back, like this

AllMats is an array of ComponentMaterials struct.

image

That is a map of static mesh component, and MaterialList. And MaterialList is a struct, which is an array of material interface object refs

Totally untested. I don’t think you need the actor refs, because you have the components.

2 Likes

In addition to your solution,
I can suggest at least three ways to avoid structures (untested too):

  1. Use Components Map and materials array

image

Pack material indices into string:

Return materials:

  1. You can use the mesh asset materials:

  1. Also you can use json as a dynamic structure:

image

Hope this helps.

My Products

2 Likes

Oh God, guys, @ClockworkOcean and @Supremative thank you very much for your help. Now I will explore both of your options and will update you after finishing it.
Many thanks for your guys again.

1 Like

Hello @ClockworkOcean
So, I used your option and maan, it has gave me good knowledge about using maps as nested arrays. Thank you very much. It totally works. I wish you all the best man :slight_smile: You have very helped. Can I ask, what do you do for living? Do you develop games for a company or maybe do it as an indie studio?

1 Like

Hello @Supremative
Your option is just incomprehensible :slight_smile:
It looks like you are very smart :slight_smile:
I am more than sure that it works well, but I’ve not tested it since the first option of @ClockworkOcean works well, and I am fine with using structures. However, your option is very impressive, thank you very much for it.

Just indie games :smiley:

@ClockworkOcean
Wow, cool, do you think someday we could make something together?
I am mainly a 3D Artist and a Web Developer, but I’ve been studing UE5 for a year and can make simple levels. My websites are: https://naiuma.com and https://designeling.com
I would like to create a shooter about distant technologocal future.
So, if you think you have time and desire to join together for work, please let me know.

1 Like

Nice designs :sunny:

Thank you for your offer, but I am very busy at the moment… :slight_smile:

@ClockworkOcean
Yeah, no problems, I totally understand. :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.