How to toggle the visibility of a static mesh on a spline?

Hey there,

I made BP class with a spline and added a static mesh component to it. I would like to toggle the visibility of the static mesh. But the static mesh does not disapear when I make the spline invisible? The only way is to set the static mesh invisible in the “add static mesh component” node, but i don´t know how to toggle it this way.

Am I missing something, or is this even the way to do it??
In the end i want to be able to toggle the visibilty with an “OnComponentOverlap” etc.

Thanks for your help,
have a great day!

Hey there, when you use Add Static Mesh Component you are creating a new Static Mesh Component and adding it into your actor but it doesnt belong or is parented by the spline, that is why it is still visible when you hide the spline. To make this work you should create an array variable and store all of the static meshes you create so when you want to toggle visibility you just do a for loop in the array and call Toggle Visibility node for each of the meshes. Another way of doing this is by using FindComponentByClass and get all Static Mesh components, so no need for the array, the only problem with this is that it might include some static meshes that were not created by the construction script, so you would need another way to filter them, maybe having a certain tag or something like that.

Thanks for the quick answer.
I tried the way with the array and it kind of works. The thing is, only the last mesh is toggling, the rest ist still visible.
What is my mistake?

This is what the spline looks like

This is what i changed in the construction Script and in the Event Graph.

You have to call the Add function in the static mesh array instead of that make array and set nodes. The problem with that is that its only adding the last one.

Got it!
Thanks a million! You are the hero of my day!!!

No problem :slight_smile: