Need Help With Static Mesh Swapping

Hi All,
Apologies, I’ve only been working with Unreal for just slightly over a year and I’ve run into a bit of a pickle and I’m hoping someone can push me in the right direction:

I have an actor (BP_Corn_Actor) that I want to show it ‘grow’ over time by swapping out it’s static mesh component, through various stages of it’s growth cycle. I’ve gotten this to work! The variable (CornLife) is incremented over time till it reaches 100%.

Below, on ‘Event Tick’ the static mesh successfully swaps out, till it reaches its max stage Corn_4.

What I can’t seem to figure out is when the corn gets damaged. I can’t get it to go backward and display the previous stage. Using a print string, the math seems to work ok… the numbers go up and down as they should. But when I translate this to ‘switching on int’, the corn stays at the last stage it grew to. It doesn’t regress backwards to the previous integer ‘switch’.

Any thoughts? I’m on Unreal 4.27 for this project.

I think you can remove Set Corn Life after ++ because ++ increments and sets.
Set Static Mesh before Switch seems unnecessary, since you’re setting it right after.
As for why the mesh isn’t changing I’m not sure.
Could be a timing thing.
I’m not sure what the first 2 checks are for.
I’d simplify and the reason may show up.

Instead of Tick I’d make a function that sets mesh by int. And have the function check on the increment and when damaged. Unless there’s a reason to fire every frame.

Did you do a print string directly before Switch?
Is Switch going to Default for some reason? I’d print there too.

1 Like

When running the game in editor: Click the first branch after Tick, and press F9 to set a breakpoint. Select the corn instance that you will damage as the instance to break for in the “debug instance” popup menu, and forward the game once, to see the value of that particular instance. You can now single step the blueprint to see how it behaves.

Separately: Once your event delay loop ends, it doesn’t seem to get re-started again. And, in general, keeping a loop with delay like this is hard to manage correctly – I much prefer to have a single timer handle, that pulses at a given interval, and which gets canceled when I don’t want pulses. (And re-start the timer when I want them again.)

Thirdly: The code that “damages” the corn isn’t shown. Thus, it’s hard to guess what could be going wrong in your math or logic.

1 Like

Wonderful feedback. Thank you! I’ll work through it and see what I come up with. I really appreciate the notes on the blueprint as I can definitely see now how I’m doubling up on some things. Will circle back with what I figure out. :slight_smile:

Hey, thanks for posting this. I didn’t know about the F9 breakpoint. I’m going to work through your feedback as well and see what I discover.

Thanks again!