npruehs / ue4-rts

Real-time strategy plugin and showcase for Unreal Engine 4.
MIT License
747 stars 151 forks source link

Setting damage with variables? #144

Closed ScanTpede closed 3 years ago

ScanTpede commented 3 years ago

Hi, First of all, I thank you for the plugin, it will save much time. I am implementing the plugin to my game, and got a problem. Unit stats from my game is vary too much(I'd say my unit is combination of 20 units) and I don't know how to set stats(mostly stats in the RTS categoty in details panel) like damage, health with variables in the plugin. I'll have to make tons of units if I can't resolve this. Do you know how to? Thank you for your time and if you have a question or request, please put them in the comment. Regards,

npruehs commented 3 years ago

Hey @ScanTpede !

Right now, changing attack damage or health is not exposed, neither to blueprints nor to C++. If you're familiar with C++, you could change that in the RTSAttackComponent or RTSHealthComponent. In that case, I strongly recommend looking at Gameplay Abilities as well: https://docs.unrealengine.com/en-US/InteractiveExperiences/GameplayAbilitySystem/index.html

Best regards, Nick

coolyoshi commented 3 years ago

@npruehs

On the topic of gameplay abilities, I'm wondering how you managed to setup the ability system workflow? I've watched your presentation and I think I have a rough idea but I'm unsure about the more specific steps.

My current thinking for implementing lets say an AOE damage ability is the following:

  1. Use blueprints to call C++ cast method when AOE spell button is clicked
  2. In the cast method, spawn an "Order Preview" with a decal attached to it which shows the AOE radius of the spell for the player . Follow similar logic as how the building cursor works to make the order preview snap to the cursor.
  3. Bind click event and when player clicks, check if order preview exists for the player
  4. If order preview exists when player clicks, then get all actors within the radius of the order preview decal (currently struggling with this part)
  5. After getting all target actors, send the ability information including the targeted actors to behavior tree
  6. Initialize behavior tree to make the caster walk within range of target and cast the ability by sending an event with the ability info.
  7. Event gets caught by gameplay abilities blueprint which runs all the logic for the spell like visual effects, while C++ methods are also used for calculating and dealing damage, etc.

Do you think I'm on the right track?

Thanks for your time! Cheers

npruehs commented 3 years ago

Hey @coolyoshi !

You're right about steps 1-3. Then, for A Year Of Rain, we handled "Use Ability" as just another order (similar to Move, Attack, etc.). So, instead of issuing an order with data like

OrderClass: MoveOrder TargetLocation: (3, 4, 7)

We've been issuing something along the lines of

OrderClass: UseAbilityOrder TargetLocation (3, 4, 7) Index: 2

with TargetLocation referring to the location the player clicked, and Index referring to the index of the ability we want to trigger (which we know about from step 1 :) )

From here, everything's "as usual", with selected actors moving into range of the ability (similar to Attack orders), and then just activate the ability by the means of the AbilitySystemComponent.

You might want to take a closer look at the open source code of our presentation, i.e.

https://github.com/DaedalicEntertainment/ue4-orders-abilities/blob/develop/Source/OrdersAbilities/Private/Orders/RTSUseAbilityOrder.cpp

Hope that helps!

coolyoshi commented 3 years ago

Wow awesome thanks for the reply! I see, so I can use AbilityOrder and index of ability. l think I kind of get it now but will probably have to play around with the code a bit more, thanks again!

ScanTpede commented 3 years ago

After a week of research, I finally manage to set Maximumhealth as varible in Blueprint. I'll left resolve step so nobody gets suffer from this. Hit me if I am using wrong method. Here is the step:

  1. Set Visual Studio (https://docs.unrealengine.com/en-US/ProductionPipelines/DevelopmentSetup/VisualStudioSetup/index.html)
  2. Right click Yourproject.uproject in project folder and generate Visual Studio file.
  3. Open Visual Studio as admin and open Yourproject.sln.
  4. Open RTSHealthComponent.h.
  5. Change Maximumhealth line to: /* Maximum health of the actor. / UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RTS", meta = (ClampMin = 0)) float MaximumHealth;
  6. Move Maximumhealth line under public. so it should be, Public: /* Maximum health of the actor. / UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RTS", meta = (ClampMin = 0)) float MaximumHealth;
  7. Turn on UE4 and check if you can set varible in BP.

Thank you for the help. Regards,