Having troubles with for each loop

Hello,

I am trying to develop a tool to help me doing certain tasks for my dev. Here, I have already created a function used to convert a dynamic mesh component into a static mesh.

Now I am trying to extend it with a new function to convert a group of dynamic meshes into a static mesh. I think my problem is with my loop because when I am executing it, I get too many iterations of what I am copying :

If anyone has any suggestions, thank you !

If I understand correctly, you want to create one dynamic mesh out of a group of meshes, to then convert that group into ONE Static Mesh?

This is your problem:

You are here trying to access something from inside the loop. This can only be done if you are still inside of it, but the Copy Mesh to Static Mesh is placed after the loop has been completed, which means you need another way of doing it:

You can create a variable Appended Mesh where all the meshes will be added to one. You can then use this mesh to convert them to ONE Static Mesh :slight_smile:

Thank you for your reply, but thats not exactly my issue. I get one static mesh with too many iterations of what I am copying. Let me show you :

Here I tried to merge those 2 dynamic meshes block into one static mesh, but I get 3 iterations of it plus a single one alone in the same static mesh, where I only want to get a single copy of those two blocks.

As @XxpiingyxX pointed out, your second loop is a mess. (it’s also not needed but that’s beside the point) I hope you’ve fixed that.

What sticks out to me is that you are always adding to that mesh. DMCs Fusion is a local variable so its created empty on every call but the dynamic mesh component… Where do you clean that out.

Also, since you are going for the loops, print some kind of a debug string to see how many iteration you are going through. It might be the case that you’ve selected more things than you think.

1 Like

Hey, I see your purpose, but I dont get how to do it without loop.

I created the first loop to get all the selected assets from viewport and the second to take all that assets and append them to a single one to then create a static mesh.

But if there is another proper and easier way to do this, dont hesitate to demonstrate it :slight_smile: .

Also, why do I need to “clear” my dynamic mesh component, what is the point to do this ?

Hey, I tried what you put in your screen, but I get another issue from “copy mesh to static mesh”.

The appended mesh seems to be empty. How did you manage to get the first array DMCsFusion directly from the first loop ? My array seems to be empty .

This is pretty much the same but it has a single loop.

Try it out.

I have no idea where you get your Dynamic Mesh Component from. I have none so I use a Temp Dynamic Mesh.

My function is not too stable though. Dynamic meshes typically want a component to live in and components require Actors not to be garbage collected.

Hope this helps and happy coding :slight_smile:

P.S.
It would probably be better to cache the result of Get Component By Class instead of calling it 3 times like I do.

Thank you for your help !

I tried your solution and I have to say it is way better than using 2 loops. I didnt know about those nodes !

By the way, I still have my duplication problem but I know from where it comes… beacause I call this function directly by clicking on it after selectionning many dynamic meshes, the function call itself as many times as I have selected DMCs… Thats why I always end up with too many iterations xD

I will work on that now :slight_smile:

1 Like