Stanford UE4 + C++ Course Learning Record 23: Damage Value

Table of contents

1. Create the UI

2. Call the UI


1. Create the UI

        To display numbers, you need to use UMG to achieve. The part of creating the UI is very simple. Create a new DamagePopup_Widget control blueprint under the Ui folder, and only add a text box. The position and default value of the set text box are as follows, you need to pay attention to set the text box "Is Variable" for subsequent access.

Figure 23-1 Text box settings

        The damage value will be displayed on the object with magic particle Overlap and HP (that is, AttributeComp), so we need a variable to record this object. Create a variable AttachTo in the "Graph", set the variable type to Actor, and then check its "Editable Instance" and "Open when Generated", so as to expose the variable so that we can pass the value of this variable in other blueprints. Then create the following blueprint:

Figure 23-2 Display settings

        Figure 23-2 realizes the display of the digital UI, the key point of which is to use the "Project World To Screen" node to realize the conversion of the 3D in-game world coordinates to the 2D screen coordinates, and through the "Project World To Screen" node Get viewport zoom" to get the zoom ratio of the screen, so as to correct the position of the UI display.

        At the same time, we hope that the numerical UI will disappear automatically after being displayed for a certain period of time:

Figure 23-3 Automatically disappear

2. Call the UI

        The course takes the previously implemented blueprint class TargetDummyBP as an example (AttributeComp has been declared in SurTargetDummy.h). Looking back at the previous content, the OnHealthChanged event is declared in the SurAttributeComponent class, that is, all objects with blood volume attributes can trigger this event, and these objects with blood volume just need to display the damage value. Therefore, we can use this event to create a display UI.

        Open the TargetDummyBP blueprint to create the control. Relevant methods have been mentioned in UMG, so I won't repeat them here. The only thing to note is that after attachTo is exposed before, the object of Attach can be passed in here.

Figure 23-4 Create UI

        At this point, according to the progress in the course, the effect of displaying numbers should have been realized, but there is no response when I run it. Since the OnHealthChanged event is related to the blood volume, it is natural that I add the following node in TargetDummyBP to display the blood volume for debugging:

Figure 23-5 Print blood volume

        As expected, TargetDummy's health is always at 100, despite the special effect of the particle explosion. After a series of code inspections again, I found that the logic implemented following the course was very confusing: the damage caused by magic particles was implemented in the code, using the Overlap event, and included the Destroy statement; the explosion effect of magic particles was implemented in the blueprint, using the OnActorHit event . This will cause the magic particles to only deduct health after colliding with the Gideon character, instead of playing the explosion effect. So I added (not replaced) the Overlap event to trigger in MagicProjectile, which solved a historical bug.

        Also, "Simulate Physics" should be turned off to use the Overlap event. When I watched the course video again, I found that the box that was hit was indeed suspended in the air. It should be that the simulation physics option was turned off.

        The final effect is shown in the figure below:

Figure 23-6 Particle burst photo effect
Figure 23-7 Display value

         Finally, the course mentioned that the control of the damage value will be added later.

Guess you like

Origin blog.csdn.net/surkea/article/details/127760718