Setting a mesh via ConstructionScrip and keep the mesh if the script is not trigged

Hello,

Situation:

  • I created a blueprint with a single static mesh component.
  • Add two variables “New Static Mesh” and “Current Static Mesh” of Variable Type: Static Mesh.
  • Wrote the code on Construction Script to change the Static Mesh Component only if “Current Static Mesh” is not equal to “New Static Mesh”. (See image)

  • Spawned the Blueprint on map, and setup the “New Static Mesh” to any mesh. When it was done, the mesh became what I select.
  • Move the object (construction script was triggered again) and the mesh disappear.

I didn’t “tell” the blueprint to set the static mesh to null. It seems every time Construction Scrip triggers, it’s necessary setup again the static mesh, otherwise it will be set to default value (in this case is null).

My objective with this test was fire construction scrip to change only new settings, whiteout losing the information that was configurated before. I wanted the blueprint understand that now it has a static mesh attached to it, and will keep it until another command to change this mesh is trigged.

In a situation like my example, trigger the construction script to setup the mesh every time I move is fine, but I had a case that are lots of meshes spawned via construction script and it cause a lot of performance cost every time change the actor.

The variables with “Instance Editable” save the information by instance of each blueprint, but the blueprint components follow their default parameter if none Construction Scrip tell him to be different.

I would appreciate it if someone could clarify more about it.
Thank you.

So yeah, the problem here is that the New Static mesh is null on every instance of the actor until you specify it. So your bool isn’t going to give you the result you want because you’re asking the engine if Current Static mesh (nothing) is not equal to New Static mesh (Nothing). Which means it will only read as true if the Current static mesh is specified.
Easier solution would be to create a custom bool called “UsingNewMesh?” and then use this in your opening bool and set it to false by default, run your code off of False, and set the bool to true at the end of your code, after you set the new static mesh. Then every time CS runs it will check to see if you’re using the new mesh, and if not, it will change the current mesh to the new one.

The result of what you posted will always be New Static Mesh because you are telling it to change if its not equal to it.

Suggest you consider having a static mesh component, a variable with the default static mesh and the instance editable static mesh: check if NewStaticMesh is valid (not empty), if it’s not valid, spawn Default SM, else spawn NewStaticMesh.

1 Like

I think using a bool it is just a simpler way to get the same result. Please check my video.

When I move the actor it recognize with a mesh, so the CS don’t run again and the engine brings the StaticMesh Component to it’s default value (that is null).

Is there a way to keep the mesh information with no running CS over and over, every movement or click on the mesh?

Try turning this off in the Class Settings:
image

Try this in construction:


ConstructionSoftRef


This option helped. Now the CS don’t run all along the drag, just when it’s finished and it saves some performance. Thank you.