The big change in Unreal Engine 5 is the introduction of double precision floats in blueprints. In blueprints you can only create doubles (64 bit floats). When declaring variables in C++ you can specify either a float or a double potentially saving memory. It is advisable in the future to declare your variables in C++, even if you decide to do your main logic within the blueprint.
In the Blueprints folder add a new Blueprint Class of type Actor and call it BP_Frac
.
Open up BP_Frac and press the Add component button add a TextRender component. Rename it to Fractional Text
.
Copy and paste the color of the text from BP_Int to BP_Frac so you have the exact text color (you can cntl-c (copy) and cont-v (paste) any literal in a blueprint). Change the World Size to 72
and ceter both the Horizontal Alignment and Vertical Alignment. Change the Text to Double
.
Drag the FractionalText to the graph. Pull off the pin of the Fractional Text and select the Set Text node.
Connect the Execution Pin between Begin Play and Set Text nodes. The white arrows represents the order of operations. It is like line number in C++.
Create a new Float variable and call it DoubleVar
. In Unreal 5 the float defaults to double. If you wanted to use a float, you need to create that variable in C++. Drag the DoubleVar onto the graph then put the curson on top of the output pin. You will see type double in the tooltip. Drag off of DoubleVar and select To Text(Float). Press the Compile button and set the default float. In this version I can only enter a float amount of digits and not the full 17 digits of a double. I assume this will be addressed in the future.
Connect the To Text | Return Value to the *Set Text | Value.
Go to the game and add BP_Frac to the room and place it next to the Int leaving enough room between the classes. Rotate the actor to face the camera.
Add a Format Text node between Text Text and Set Text. Add the text:
Double or Float
{A}
Rember newline is achieved by a Shift Return/Enter. The {A}
add a pin to the format text and will append the float to this Text.
Press the Compile button and go back to the game. Press the Start button. You should now see the
In the game you can navigate with the WASD keys to move along the ground and the Q (Up) and E (Down) keys to move up and down. Now the game starts where the camera last left off. We can also set a starting point for the game.
Press the Add Object button (box with arrow) and type in Player Start and add the player start actor to the level in front of your text.
Rotate the player start actor so it faces the text. Look at the blue arrow to know the front facing direction of the player when starting.
Press the Three Dots next to the Play button. Select Default Player Start. Press the Play button and adjust the position of the player start so you are well centered and happy with your starting position. This way you can now move around and you will always start at the same place every time.
Go back to BP_Frac and right click and select Keyboard Events | X node.
Drag another copy of the DoubleVar variable to the graph. Add a Random Float in Range node and set it from 2.0
to 5.0
. Then add a Multiplication node and multiply DoubleVar by the Random Float in Range.
Drag yet another copy of DoubleVar onto the graph and this time select Set DoubleVar node.
Connect the execution pin from the X node to the new Set DoubleVar node. Connect the output of the Multiply node to the input pin of the Set DoubleVar node. Add another copy of the Factional Text component to the graph. Pull off the pin and select a Set Text node. Finally connect the execution pin from the output of the DoubleVar to the SetText node.
Select all the nodes coming from begin play with the mouse. Press the C button and Unreal creates a group with a comment. Call it Set Initial Text
. Now when ouou move it around, all the nodes move with it. You can also customize the color of the node away from the default white.
Select all the nodes attached the X button pin and press the C button and call it Miltiply Text on X Button Press
. Organize the nodes to be clean and organized.
Press the Compile button and I get an error. Nothing is connected to the Set Text | Value pin.
Connect the To Text | Return Value and connect it to Set Text | Value. Press the Compile button and the error goes away. Also, lets set the Maximum Fractional Digits to 16
to see if we get double precision.
Now you will not be able to get the X event unless you allow the actor to receive input. Select the PB_Frac(Self) top component and turn Auto Receive Input to Player0
.
Add a Format Text node to match the title that is displayed before you press the X.
Change the default value of DoubleVar to a small number like 1.2
so we get a better idea of the precision. Press the Compile button.Press the Play button and then press the X and you will see fractions with the precision of a double!
DoubleBP.mp4
previous | home | next |
---|