Rts how to add a construction time to buildings?

I’m working on an rts practice project and I’m pretty stuck on adding a construction time to my actors.

Right now I have a setup where the actors are bound to hud buttons, I click them they spawn in the world and follow your cursor, right click to cancel, some buttons mapped to rotation and they are transparent green if they can be placed and turn transparent red if they are on a slope or overlapping.

I’m trying to make it so when I click on the hud to spawn a building (this makes buildmode active) and then place in the world this will make the mesh transparent and have “x” amount of time and the building will be “built”. I’d like to eventually have a resource requirement for the buildings and make it so a worker has to build it. And have it go through multiple build meshes depending on completion %.

But for right now I’d just like a set value for the build time that could be changed depending on the mesh and would work with my ingame time.

This is probably the most stuck I’ve been on this project since trying to learn ue4 so any help appreciated.

Hi,

You can use the [timer nodes][1] for this. You can have the timer fire off a custom event (or bind it to an existing one) that will happen after the time you specify.

Additionaly, if you set the timer handle to a variable, you can interact with it as well.

That would be able to work with the ingame time and eventually actors right? Thanks for the help so far

Yes, it should be compatible with game time. And you can reference an actor as shown, so you can call a specific event in that actor when the timer fires. Although I would recommend putting the timer in each actor’s blueprint so it’s handled automatically after placing the building.

Something like an event in the building’s blueprint that starts the timer after the building’s been placed.

Would you happen to know why this isn’t working? The building ghost ref is the transparent mesh that gets placed in the world first, but after I click to place it changes to solid mesh.

So after the actor is spawned, (time * 60) seconds will pass before the Construction_Completion_Rate event is fired. That event will then increment CompletionProgress (add 1 to it then set it).

So after your event fires, CompletionProgress is going to be at 1 (assuming your default value is 0). When you convert a float to a string, you will get “1.0”, which your SwitchOnString will not find. Generally converting floats to strings to perform a float operation is not a good idea.

Why your mesh is changing to solid after you place I can’t say, because there’s nothing in this blueprint that would do that, considering your SetStaticMesh Nodes have no way to execute.

I would recommend a different approach, as shown below:

Happy to help, have a good day!

And please, if the answer worked for you, can you mark it as accepted? Thanks!

Wow. That is above and beyond man. I can’t thank you enough. Seriously thanks. I’m still really new to all this and have been stuck on this FOREVER. So just wow, thanks.

I think that’s a good solution, but I wondered if it could be done without using Event Tick.
So I did this:

I think it should work…
NOTE: SegmentNumber should be initialized as 0.

That way works too. :slight_smile: And if tick is an issue, you can always disable it after the building completes using SetActorTickEnabled.

Sorry, i’m still learning eu4, but how do you then implement this to your child blueprint and set all the stages? Tried different solutionsbut, but i haven’t quite figured it out… :confused: