【UE】UE5 Study Notes

UE5 study notes (continuously updated)

interface

hot key

hot key describe
F Locate the level one card object: Double-click the name of the game object or select the name of the game object
middle mouse button mobile view
alt + left mouse button to move rotating field of view
scroll mouse wheel zoom field of view
alt + right mouse button drag the mouse zoom field of view
Left mouse button to move the mouse Roam back and forth
WASD + right mouse button free roam
Swipe the mouse wheel while roaming Adjust roaming speed
Select the object to be cloned, hold down the Alf key and drag clone game object
Select the game object and press END drop to platform
  1. Selected object:
    Locate one card Object: Double-click the name of the game object or select the name of the game object, press F
  2. Field of view operation related card shortcut keys:
    Move field of view: press and hold the middle mouse button, move the mouse
    Rotate field of view: press and hold the right mouse button to move the mouse or press and hold alt+left mouse button to move the mouse
    Zoom field of view: slide the mouse wheel
    to zoom field of view 2: hold down alt+mouse Right-click and drag the mouse
    Roaming scenes forward and backward: Press and hold the left mouse button to move the mouse
    Free roaming scene: Press WASD + right mouse button to move the mouse
    Adjust roaming speed: Slide the mouse wheel when roaming
  3. Clone game object: Select the object to be cloned, hold down the Alf key, and drag any axis to achieve dragging
  4. Fall to the platform: select the game object, press END

UI

  1. Create a UI Widget Blueprint: Right-click in the Content Browser → User interface -> Widget Blveprint
  2. The UI editing interface is mainly divided into: toolbar, controls, hierarchical panel, work area, screen size adaptation, property bar, animation area

The widget control is used

Display UI controls to levels

By default, the UI control blueprint will not be rendered into the level, and it needs to be created by creating a control blueprint:

Step 1: Create a specified control blueprint by creating a control node

Step 2: Display the Widget Blueprint to the level by adding to the viewport node

Show Mouse Cursor

By default, when we click the game area, the mouse will be hidden, so that the UI cannot be operated well, and the mouse pointer needs to be displayed by default to control.

  • Get the player controller in the level blueprint Show the mouse pointer through the player controller
  • The display and hiding of the mouse can be controlled by FlipFlop

Dynamically set the value of the control

  1. Get control modification by variable
  2. Modification by binding creation function

Types of widget controls

rich text block

Multi-format text, also known as rich text, mainly expresses the appearance of multiple text styles (font, size, color, format) in a single-text segment and can also be mixed with image content

Create a text block data table; select the data table→RichTextStyleRow arrow and the first row must be named Default.

Example of use这是个<Red>多格</>的文本

custom control

We create our own controls that can also be used as sub-controls of other UI controls

The steps to customize the control are:

  • Create a custom control blueprint
  • Set controls and styles
  • In other U, the use of controls is realized through user creation

Named Slot

When the UI created by the user becomes a sub-control of other UI, it cannot have sub-controls by default. If you want to have sub-controls, you must add a named slot to U|, so that this UI can have sub-controls

The implementation steps are:

  • Step 1: Create UI Controls with Named Slots
  • Step 2: Import UI controls into other U| panels, and add corresponding controls to the slots

Border

  • A border control is a container that can only contain one child element, which can be used as the background of the element
  • After adding sub-controls to the boundary control, the sub-controls will not have the freedom to set the anchor point, position, size and other characteristics

Text Box

A control used to provide the user with input text

ComboBox (String) (ComboBoxString)

Used to implement dropdown options

Overlay

It is used to let the U controls stack together layer by layer. There can be stacking between multiple child controls

Widget Switcher

Used to display the child element at the specified index

  • has multiple child elements
  • Display child elements by index
  • index starts from 0

Wrap Box

A box packed for multiple sub-controls, when the sub-controls cannot fit in the package box, it will wrap automatically

  • Can have multiple child controls
  • You can set the spacing between child controls by setting slot padding
  • You can set the wrapping width of the wrapping control by setting the wrapping size

Uniform Grid Panel

Manage multiple sub-elements, the size of the sub-elements is the same size, all sub-elements are stacked together by default, you can control the position of the element by adjusting up, down, left, and right.

Grid Panel

Manage multiple sub-elements. The size of sub-elements can be set individually. By default, all sub-elements are stacked together, and the position of the element can be controlled by adjusting up, down, left, and right.

Horizontal Box

It is used to manage multiple sub-elements in the horizontal direction. The size of sub-elements can be set separately. The types of sub-elements can be different. The position of sub-elements can only be switched left and right

Vertical Panel (Vertical Box)

It is used to manage multiple sub-elements in the vertical direction. The size of sub-elements can be set separately. The type of elements can be different. The position of sub-elements can only be switched up and down.

Size Box

Used to set the size of the child control, there can only be one child control

  • When the size to content is not checked, the sub-layout is invalid, and the size of the sub-control is consistent with the size of the size box
  • When the size reaches the content, the size of the sub-control can be set or controlled through the sub-layout

Scroll Box

When the total width or height of the child control exceeds the scroll box, the excess part is hidden and the scroll bar is displayed

Select box (CheckBox)

Used to indicate whether a specific state is selected or not selected, prompting the user for True/False or/No choice

There are two states

  • Check box: You can add explanatory text, and the size of the selection box needs to be set in the image
  • Toggle button: generally do not add explanatory text

Binding value: You can add a Boolean value to the selection box to control selection and cancellation

blueprint

blueprint function

note

Select the corresponding node and press c to comment

disconnect

atl + left mouse button

blueprint classification

Level Blueprint

Each level corresponds to a level blueprint, the level blueprint cannot be created, only the default level blueprint can be opened and used.

Game Instance

  1. A data management blueprint that will not be destroyed when switching levels.

  2. Store global game information.

Game Mode _

  1. Manage basic information such as input controls and cameras of all players, which will be destroyed when switching levels.
  2. Each mini-game in the game can be regarded as a different game mode. Usually, loading a mini-game is also an act of loading a new level.
  3. Store the information under this level. Such as the current event time and role ranking.

Pawn/Character (game character)

  1. Manage input controls and real-time information for a single player. It is destroyed when the character dies, and a new one is generated after resurrection.
  2. Store character data at the current moment, such as character position, real-time blood volume, skill CD, each remaining card in hand, etc.

blueprint node

●Event node
●Function node
●Variable node
●Reference node

logical node

The role of the sequence node (Sequence) is to divide a long sequence of execution code into segments, which is easier to manage. Note: Sequence nodes are single-threaded. Segmentation will be performed in the order of the pins.

Branch ( Branch ) node: used to determine whether the specified condition is met, if the condition is true, execute the logic of the true output node, and if the condition is false, execute the logic of the false node.

ForLoop node : A node that executes a function a specified number of times. You need to pass in the loop start value and end value
ForLoopWithBreak node : When the break is not executed, it is the same as the function of the ForLoop node. When the break is executed, the loop terminates

WhileLoop node : As long as the loop condition is met, the node will be executed directly

Do N node : After the execution reaches the Nth time, the function will no longer be executed. To execute again, you need to perform a Reset reset

Do Once node : Execute only once, if you want to execute it again, you need to execute Reset

Flip Flop node : Also known as a flip node, it can output two functions, execute function A for the first time, execute function B for the second time, and execute function A again for the third time

Gate node : also known as a gate node, that is, when the gate is opened, it can perform functions at any time, and when the gate is closed, it cannot perform functions

**Multi Gate (multi-gate)** node: By default, the output will be executed sequentially. When all the outputs are completed, the output will not be executed. Output nodes can be added, looped and randomized

ForEachLoop : ForLoop for arrays

ForEachLoopWithBreak : ForLoopWithBreak for arrays

Timeline node ( Timeline ) is a special node in the blueprint, its function is to change the specified value to the target value within the specified time

Interpolation ( Lerp ) node: returns the value between A and B according to the value of Alpha, and the value range of Alpha is 0-1

Deactivata : Disable components

Activate : enable the component

Delay : Delay

function node

**Open Level**Open a new level

** Generate an Actor from a class (Spawn Actor from Class) ** Generate an Actor

Pause the game (Set Game Paused)

Interaction between blueprint classes

Add Control Action Mapping

  1. Add variables of other blueprints to the blueprint.

Blueprint classes interact with level blueprints

  • Define custom events in the level blueprint
  • Execute level blueprint events by executing the Exgecute Console Command node in the blueprint class
    • Note that the event must be a custom event, otherwise the call will fail
    • Enter the ce event name in Command, and it must start with ce, ce is the keyword, and a space needs to be added after ce

blueprint application

variable

Get and set variables:
Get variables: hold down ctr and drag the variable into the event graph
Set variables: hold down alt and drag the variable into the event graph

array

  1. Find item ( Findltem ): Find the subscript of the specified element

  2. Get the array length ( Length )

  3. Get the subscript of the last element of the array: lastindex

  4. insert array elements ( insert )

  5. Determine whether there are elements in the array ( Contains )

  6. removeElement()

Functions and custom events

Same point:

  • Yes, it is possible to encapsulate the - segment logic as a function

  • can receive parameters

  • Other blueprints can be called directly

difference:

  • Functions can have local variables, custom events do not
  • Functions can define return values, custom events do not have return values
  • The logic of the custom event is defined in the event graph, and the function needs to use a graph alone;
  • Functions cannot use delay (delay function), but custom events can. It is because the function call needs to wait for the result before there will be follow-up actions, and the event will continue to execute as long as it is triggered;
  • From a logical point of view: as long as the event is triggered, the processing logic has nothing to do with the event itself; while the function generally passes some data, and finally outputs the result, focusing on the processing result, from the input of parameters to the execution of the logic to return the data Procedures are what the function body needs to pay attention to.

choose:

  • When only this function needs to be executed and has a delay function, use a custom event
  • When you need to do calculations and return results, use functions

Functions and Macros

The overall function of the blueprint macro is similar to that of a function. It encapsulates some functional algorithms, and multiple input pins and output pins can be added according to the situation.

  • A function has only one pin, and a macro can have multiple input and output pins;
  • Other blueprints can call functions, but not macros

macro library

It is used to manage multiple macro library files. Since it is a file, a macro library needs to be created. We can call the macros in the macro library in all blueprints

event dispatcher

delegate-like usage

Define an event dispatcher

assignment event dispatcher

Call the event dispatcher

Usage of event dispatcher in ui

When creating a ui control, you need to inherit the trigger method of ui, then you can use the event dispatcher.

  1. Binding events into the graph;
  2. Create an event dispatcher and call it through the event.

components

read interface method

math

Quaternion

Create Quaternion (Make Quat)

Euler angle to quaternion (Make from Euler(Quat))

Split Quaternion (Break Quat)

Quaternion rotation vector (Rotate Vector(Quat))

Type conversion (Cast To)

  • Get Play Pawn Get Player

Ordinary blueprints can be written to special blueprints, which can be directly obtained and type converted.

For example: GetPlayPawn, GetPlayCharacter, GetPlayController

  • Animation blueprint (record this before you encounter it)

When converting to an animation blueprint, you need to get an instance of the animation blueprint first, and the target of this instance is to get it on the animated Mesh.

  • Game Model (GameMode)

Game priority is the highest. You can get GetGameMode directly

  • Collision detection (On Component Begin Overlap)

Actor is obtained through collision to perform type conversion.

including radiography

  • Traversal hard lookup (Get All Actors of Class) consumes more performance

Look in all referenced classes

include:

  • Get All Actors With Tag
  • Get All Actors With Interface
  • Get Actors of Class (when only one is determined)

Replenish:

When looking for UICalss, use Get All Widgets Of Class

find by get

通过For Each Loop with Break

  • indirect reference (common)

It is to store the blueprint that needs to be used in a variable, and then refer to it when calling this blueprint.

The case is to get two blueprints that need to communicate in the level, and assign the blueprint variables to the communication blueprint

blueprint case

X-ray inspection

important nodes used

Convert Mouse Location To World Space (mouse screen coordinates to world coordinates)

Line Trace By Channel (ray detection)

interface operation

Add to Viewport loaded to the interface

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-B6UnQF0s-1681438840906)(null)]

UI image modification

The brush or style on the ui panel can modify the picture, you can use the blueprint SetBrush or SetStyle

Read model by Tag

After setting the tag to the model, you can get it through the tag

material

Press and hold 3, click on the panel to create a color node

Model

C++

Camera Control Script

AMyPawn.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "MyPawn.generated.h"

UCLASS()
class XZ_PROJECT_API AMyPawn : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	AMyPawn();
	UPROPERTY(VisibleAnywhere, Category = "My Pawn Component")
	class	UStaticMeshComponent* myStaticMesh;
	UPROPERTY(VisibleAnywhere, Category = "My Pawn Component")
	class	UCameraComponent* myCamera;
	UPROPERTY(EditDefaultsOnly, Category = "My Pawn|Vector")
	FVector CameraLocation;
	UPROPERTY(EditDefaultsOnly, Category = "My Pawn|Vector")
	FRotator CameraRotation;
	UPROPERTY(EditAnywhere, Category = "My Pawn|Vector")
		float MaxSpeed;
	FORCEINLINE UStaticMeshComponent* GetStaticMeshComponent() { return myStaticMesh; }

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
	void MoveRight(float Value);
	void MoveForward(float Value);
	void MouseLeft(float Value);
	void MouseRight(float Value);
	void MouseX(float Value);
	void MouseY(float Value);
	void MouseWheelAxis(float Value);
	float VelocityRight;
	float VelocityForward;
	FVector Velocity;
	FVector VelocityMouse;
	FVector VelocityMouseForward;
	float getMouseRight;
	float getMouseLeft;
	float getMouseX;
	float getMouseY;
	float getMouseWheelAxis;
	float MouseMoveSpeed;
};

MyPawn.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "MyPawn.h"
#include "Components/StaticMeshComponent.h"
#include "Camera/CameraComponent.h"

// Sets default values
AMyPawn::AMyPawn()
{
 	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
	myStaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("myStaticMesh"));
	myStaticMesh->SetupAttachment(GetRootComponent());

	static ConstructorHelpers::FObjectFinder<UStaticMesh>staticMeshAsset(TEXT("StaticMesh'/Game/s_Models/test1.test1'"));

	static ConstructorHelpers::FObjectFinder<UMaterialInterface>materialAsset(TEXT("Material'/Game/s_Models/Materials/black.black'"));

	if (staticMeshAsset.Succeeded() && materialAsset.Succeeded())
	{
		myStaticMesh->SetStaticMesh(staticMeshAsset.Object);
		myStaticMesh->SetMaterial(0, materialAsset.Object);
		myStaticMesh->SetWorldScale3D(FVector(1.0f));
	}

	myCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("myCamera"));
	myCamera->SetupAttachment(GetStaticMeshComponent());
	CameraLocation = FVector(-300.0f, 0.0f, 300.0f);
	CameraRotation = FRotator(-45.0f, 0.0f, 0.0f);
	myCamera->SetRelativeLocation(CameraLocation);
	myCamera->SetRelativeRotation(CameraRotation);
	AutoPossessPlayer = EAutoReceiveInput::Player0;

	MaxSpeed = 100.0f;
	VelocityRight = 0.0f;
	VelocityForward = 0.0f;
	Velocity = FVector(0.0f);
	VelocityMouse = FVector(0.0f);
	VelocityMouseForward = FVector(0.0f);
	getMouseRight = 0.0f;
	getMouseLeft = 0.0f;
	getMouseX = 0.0f;
	getMouseY = 0.0f;
	getMouseWheelAxis = 0.0f;
	MouseMoveSpeed = 0.0f;
}

// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AMyPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	MouseMoveSpeed = -FMath::Clamp(myCamera->GetRelativeLocation().X * 0.02f, -1000.0f, -10.0f);
	Velocity = RootComponent->GetRightVector() * VelocityRight + RootComponent->GetForwardVector() * VelocityForward;
	if (getMouseLeft == 1)
	{
		Velocity = RootComponent->GetRightVector() * -getMouseX * MaxSpeed * MouseMoveSpeed + RootComponent->GetForwardVector() * -getMouseY * MaxSpeed * MouseMoveSpeed;
		AddActorWorldOffset(Velocity * DeltaTime, true);
	}
	if (getMouseRight == 1)
	{
		FRotator PitchRotation = myCamera->GetComponentRotation();
		PitchRotation.Pitch = FMath::Clamp(PitchRotation.Pitch += getMouseY, -80.0F, 0.0F);
		myCamera->SetWorldRotation(PitchRotation);
		FRotator YawRotation = RootComponent->GetComponentRotation();
		YawRotation.Yaw = YawRotation.Yaw += getMouseX;
		RootComponent->SetWorldRotation(YawRotation);
	}
	if (getMouseWheelAxis != 0)
	{
		VelocityMouseForward.X = getMouseWheelAxis * MaxSpeed * MouseMoveSpeed;
		myCamera->AddLocalOffset(VelocityMouseForward * DeltaTime, true);
	}

}

// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
	PlayerInputComponent->BindAxis(TEXT("s_MoveForward"), this, &AMyPawn::MoveForward);
	PlayerInputComponent->BindAxis(TEXT("s_MoveRight"), this, &AMyPawn::MoveRight);
	PlayerInputComponent->BindAxis(TEXT("s_MouseLeft"), this, &AMyPawn::MouseLeft);
	PlayerInputComponent->BindAxis(TEXT("s_MouseRight"), this, &AMyPawn::MouseRight);
	PlayerInputComponent->BindAxis(TEXT("s_MouseX"), this, &AMyPawn::MouseX);
	PlayerInputComponent->BindAxis(TEXT("s_MouseY"), this, &AMyPawn::MouseY);
	PlayerInputComponent->BindAxis(TEXT("s_MouseWheelAxis"), this, &AMyPawn::MouseWheelAxis);
	}
	void AMyPawn::MoveRight(float Value)
	{
		VelocityRight = FMath::Clamp(Value, -1.0f, 1.0f) * MaxSpeed;
	}
	void AMyPawn::MoveForward(float Value)
	{
		VelocityForward = FMath::Clamp(Value, -1.0f, 1.0f) * MaxSpeed;
	}
	void AMyPawn::MouseLeft(float Value)
	{
		getMouseLeft = Value;
	}
	void AMyPawn::MouseRight(float Value)
	{
		getMouseRight = Value;
	}
	void AMyPawn::MouseX(float Value)
	{
		getMouseX = FMath::Clamp(Value, -1.0f, 1.0f);
	}
	void AMyPawn::MouseY(float Value)
	{
		getMouseY = FMath::Clamp(Value, -1.0f, 1.0f);
	}
	void AMyPawn::MouseWheelAxis(float Value)
	{
		getMouseWheelAxis = FMath::Clamp(Value, -1.0f, 1.0f);
	}



release

Aspect Ratio Change Settings

After windows is packaged, the drag window resolution ratio cannot be changed, Project Settings->Project description->settings->should window preserve aspect ratio ->false;

Select publishing mode

windows

development mode

After running the release package, click the ~ key to change the release settings.

such as changing the resolution

Windowed mode
r.setres 1920x1080w
Fullscreen mode
r.setres 1920x1080f

void AMyPawn::MouseX(float Value)
{
	getMouseX = FMath::Clamp(Value, -1.0f, 1.0f);
}
void AMyPawn::MouseY(float Value)
{
	getMouseY = FMath::Clamp(Value, -1.0f, 1.0f);
}
void AMyPawn::MouseWheelAxis(float Value)
{
	getMouseWheelAxis = FMath::Clamp(Value, -1.0f, 1.0f);
}

## 发布

#### 宽高比变化设置

windows打包后,拖拽窗口分辨率比例不能改变,Project Settings->Project description->settings->should window preserve [aspect](https://so.csdn.net/so/search?q=aspect&spm=1001.2101.3001.7020) ratio ->false;

#### 选择发布模式

##### **windows**

**开发模式**

运行发布包后点击~键,可以对发布设置进行更改。

比如修改分辨率

**窗口模式**
r.setres 1920x1080w 
**全屏模式**
r.setres 1920x1080f


Guess you like

Origin blog.csdn.net/dxs1990/article/details/130147531