Skip to content

Latest commit

 

History

History
216 lines (111 loc) · 10.1 KB

README.md

File metadata and controls

216 lines (111 loc) · 10.1 KB

Fractional Numbers

previoushomenext

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.



Step 1.|BPOVR|:small_blue_diamond:

In the Blueprints folder add a new Blueprint Class of type Actor and call it BP_Frac.

add BP_Frac blueprint

Step 2.|BPOVR|:small_blue_diamond: :small_blue_diamond:

Open up BP_Frac and press the Add component button add a TextRender component. Rename it to Fractional Text.

add textrender component called Fractional Text

Step 3.|BPOVR|:small_blue_diamond: :small_blue_diamond: :small_blue_diamond:

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.

format text and change to Double & Float

Step 4.|BPOVR|:small_blue_diamond: :small_blue_diamond: :small_blue_diamond: :small_blue_diamond:

Drag the FractionalText to the graph. Pull off the pin of the Fractional Text and select the Set Text node.

set text with fractional text node

Step 5.|BPOVR| 🔸

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++.

connect Begin Play to Set Text

Step 6.|BPOVR| 🔸 🔹

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.

add DoubleVar float then change ToText

Step 7.|BPOVR| 🔸 🔹 🔹

Connect the To Text | Return Value to the *Set Text | Value.

connect ToText float

Step 8.|BPOVR| 🔸 🔹 🔹 🔹

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 double float to game

Step 9.|BPOVR| 🔸 🔹 🔹 🔹 🔹

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.

alt_text

Step 10.|BPOVR| 🔷

Press the Compile button and go back to the game. Press the Start button. You should now see the alt_text

Step 11.|BPOVR| 🔷 🔹

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.

add player start actor to game

Step 12.|BPOVR| 🔷 🔹 🔹

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.

rotate player start actor to face text

Step 13.|BPOVR| 🔷 🔹 🔹 🔹

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.

select default player start

Step 14.|BPOVR| 🔷 🔹 🔹 🔹 🔹

Go back to BP_Frac and right click and select Keyboard Events | X node.

add X node

Step 15.|BPOVR| 🔷 🔸

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.

multiply DoubleVar by Random Float in Rage

Step 16.|BPOVR| 🔷 🔸 🔹

Drag yet another copy of DoubleVar onto the graph and this time select Set DoubleVar node.

set DoubleVar

Step 17.|BPOVR| 🔷 🔸 🔹 🔹

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.

multiply to set text node

Step 18.|BPOVR| 🔷 🔸 🔹 🔹 🔹

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.

add comments and organize nodes

Step 19.|BPOVR| 🔷 🔸 🔹 🔹 🔹 🔹

Press the Compile button and I get an error. Nothing is connected to the Set Text | Value pin.

compile then error

Step 20.|BPOVR| 🔷 🔷

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.

connect to text to set text

Step 21.|BPOVR| 🔷 🔷 🔹

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.

set auto receive input

Step 22.|BPOVR| 🔷 🔷 🔹 🔹

Add a Format Text node to match the title that is displayed before you press the X.

add Format Text node

Step 23.|BPOVR| 🔷 🔷 🔹 🔹 🔹

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

next up -

previous home next