Unreal Blueprint Learning Notes

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

<Part1>

EventBeginPlay:

When you hit the play button in the editor this function will run.

How to make reference to an object:

Click the object in the scene and then in the blueprint level right click and click reference to …

StaticMeshComponent.GetMass:

It’s a two node first is the class static mesh component which is a class for each object in the
scene and then the GetMass is a function member of this class.

StaticMeshComponent.GetDisplayName:

It’s a two node first is the class static mesh component which is a class for each object in the
scene and then the GetDisplayName is a function member of this class.

SpaceBar:
event node, to be played when space bar key is pressed.

AddImpulse:

Either add impulse by changing speed, or add force by change acceleration.

SpawnActorfromClass:

This will create an actor from a BP-class during the play mode.

GetPlayerPawn:

This will give us reference to the pawn that will be created automatically after clicking the play
button.

GetActorLocation:

It’s a function of the class Transformation that will return the location of the player.

*Note that almost all of the object have the Transformation class which is location, rotation and scale.

*Note that by default the GetActorRotation is not influenced by rotation of camera. i.e the cameria
rotation and actor rotation are two different things.
GetControlRotation:
this node is reflected by the rotation of camera. It’s a function of the class Pawn.

GetActorForwardVector:

Forward vector is basically the rotated x axis of an actor which has the magnitude of 1.

GetForwardVector(static mesh):

This one also is similar as the GetActorForwardVector.

*Note that for projectile in a direction first we get the rotation of the camera, then we apply this
rotation to the projectile before adding impulse. Then with the Forward direction which is the x axis of
the projectile object after rotation we add impulse on that direction.

Multiply:

To multiply integers, vectors, etc.

Subtract:

To do subtraction.

*Variables has set and get functions. You can create variable from left menu bar. If you have nothing in
your blueprint then go to Window at the top menu bar and then check My Blueprint.

Branch:

It’s a node to control the flow. It’s exactly like if statement.

Less, LessEqual, Greater, GreaterEqual, Equal :


<, <=, >, >=, ==

*Pure functions have no side effect. They don’t have execution pin.

Get a reference to self:

Return a reference to the instance…

It’s used when you create function member for a class or blueprintclass.
GetCurrentLevelName:
return us the name of the current level.

Delay:
make a delay in time.

OpenLevel(byname):

Reload the level that is indicated by name.

*you can’t collapse delay node into function (nodes which take time can’t be collapsed into function)

=====================================================================================
=====================================================================================

<Part2>

Details panel is the panel shown in this picture. Basically it’s in the right side and each actor and
blueprint class have this panel. Via this panel you can adjust different things like transformation class,
material, and other functionality. If you add a new class to an actor, the class will be appeared in this
details panel.
“Create Child Blueprint Class” is used to create a blueprint class from the existing blueprint class but as a
child. So if you make changes to the child it doesn’t change the base class. ( good way to avoid changing
the base class ).

AutoPossessPlayer:

It’s inside details panel, in the section Pawn. ( via this functionality you can set the number of
player as zero so later the editor will start the game from player 0. (note that you can adjust the
Player number as any number you want and tell the indicator to start playing from what player
number).

UPROPERTY(EditAnywhere):
this should be before any variable that you want to make it appear in the detail panel. If you
don’t write it before then the variable wouldn’t be appear in the detail panel. In addition this
shouldn’t end with semicolon (;)

FVector():
for the vector class of 3D. i.e (X, Y, Z)

SetActorLocation(FVector):

Will set the location of the actor to the location of given FVector.

UPROPERTY(EditAnywhere, Category = “stringname”)

This line of code (without ; at the end) make a category of the name “stringname” and put the variable
that you define after this line on that category.
DeltaTime

It’s a parameter of the unit time/frame. You can use it to make the movement independent to
the frame.

Frame dependent -> (a pc that run 10 frame per second) -> current position += shift;

In this way each frame the current position will be increased by shift and in 1 second this will 10
time so we can say after a second ( current position = current position + 10 shift).

Now if the pc was more powerful (100 frame / second) then the result was as below:

Current position = current position + 100 shift.

Now Frame independent way (10 frame per second) -> (0.1 = delta time):

Current position += shift * deltatime;

In this way after a second (current position = current position + shift * 10 * 0/1)

So the shift will be added based seconds and not frame.

UPROPERTY(VsibileAnywhere)

This doesn’t allow to edit the variable defined after this line and just make it visible.

Scope Resolution Operator ( :: ):


remember that in c++, you have a class and some data member and data functions.
Now if you want to access those data member or data function you use dot operator with an
object of that class. And some times you have data function or data member that doesn’t belong
to an instance or object. In fact they are belong to all object of that class, ( for example they are
static). Now In game development you can consider this concept as a way that you don’t have
an object or instance of the class but still you can have access to some functionality of that class.
You use :: operator with the name of the class before it and you can access those operations.

GetSafeNormal():

It’s a function member for the class FVector and it return the direction of the FVector in which
this function is called but with the size of 1, no magnitude.

Making BP_class from a c++ class will let you have objects with the same behavior and manage all of
them via the Unreal Editor. For example when you create a c++ class with a variable FVector in its
header file then you create a BP class from this c++ class. Now you can put the instance of this BP class
into the scene by just drag and drop them from the content panel and for each instance that have a
variable FVector you can adjust it if the variable defined as (EditAnywhere).

MoveUpdatedComponent:

It’s used to debug the collision and if there was the collision update the position of third person.
But I don’t get how exactly it works??????

GameMode:

It’s in fact an actor that manage some rules in the game. For example it manages how many
player can be in the game, how they come into the scene and etc. so it’s kind of base class (but
always actor) and its job is to manage some rules.

We use it to add the ability to our game to let the third person player start playing from
everywhere that we select “Play from here”.

Practice number 3.

GetOwner()

Return a pointer to AActor type. AActor is the baba type of Actors in your game and through this
command you can have access to the actor that own a component and then you can control
that actor inside your component.
Component 1
Actor

Component 2

Component 3

GetOwner()
ToCompactString()

This will give you a textural representation of FVector in string format.

What is the difference between, GetActorRotation() and GetComponentRotation() ???

Line Trance, Shape Trance, Geometry Trace, Trance Channel


DrawDebugLine():

It will draw a line that help you to debug the sweep function. If you have problem in using
sweep, you can use it.

IN C++ we have Reference and Pointer which are not the same.

In reference the syntax is -> like below:

Int a = 4;

Int& reftoa = a;

Now for you ‘reftoa’ is not an address is another name (reference to a ). Just it.

GetWorld():

It’s a function that return a pointer to UWorld object. Now I don’t know too much about it but
it’s used to have access to some other functions such as “SweepSingleByChannel”.

Sweep( a lot of parameters):

To hit the object.

The first parameter is a out parameter and return an object and through that object you
can access the actor. HitResult.GetActor() will return a pointer to the actor that is hit.

You need to define a trace channel (remember the grabber channel).

UFUNCTION(BlueprintCallable)

This is like UPROPERTY and this should be before any function that you want to use it in
blueprint.

UPhysicsHandleComponent

It’s the library for physics and grabbing object.


https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/PhysicsEngine/UPhysicsHandleComponent/
FindComponentByClass<T>():

It returns a pointer the the type object T inside the angle bracket. Basically the type T is the type of the component.

Always check that the pointer is not null. To avoid crashing.

FHitResult:

It is a structure that contains information about the object of trace that is hit.

Information such as location, etc.

DrawDebugSphere():

To draw sphere in some location for debug purpose.

Dependency injection : it is a method to have access to other component from one class with a pointer to those component.

Early return is the way that you return something before running any loop completely.

TArray<Type>: it’s the same as vector and array in unreal.

For example “ TArray<AActor*> ActorList “ is an array of pointer to AActor class.

GetOverlappingActors(TArray<AActor*>):

This function will fill the overlapped actors in the TArray argument.

ActorHasTag(FName):

This function will return true if the actor that is calling this function has the Tag with the same as FName string.

RootCompoenent is the componenet that is the location, rotation and scale. In other word the RootComponent is the component that define
the transform.

AActor::AttachToComponent(…..)

This function is called with an actor and the function will attach the RootComponent of this actor to another Component / supplied
component. For example RootComponent of status object (actor) to trigger component. The trigger component itself is attached to
another object/blueprint class object.

Cast<UPrimitiveComponent>(USceneComponent*):

This will cast/ convert the type of an object which is USceneComponent pointer to UPrimitiveComponent pointer. In other word this
cast will return a pointer which is UPrimitiveComponent that was before a USceneComponent pointer.

You should know that USceneComponent is the parent of UPrimitiveComponent and we do Casting becacsue we need some
functionality of the child which is not available in the parent. If the case was the reverse/ i.e if we had a child and we wanted to
access the functionality of parent then I think polymorphism could be used but now we have a parent and we need to convert it to
child! A bit confusing.
SOME FUNCTIONALITY OF THIS CHAPTURE MAY NEED MORE EXPLANATION or MAYBE THEY ARE MISSING FROM THIS DOC, SO DON’T
HESITATE TO REVIEW THIS CHAPTER.

=====================================================================================================================

TankProject

Pawn:

It’s a subclass of Actor and it’s used as avatar of the gameplay. If the pawn being control by some input then it’s possessed.

Character is a subclass of Pawn and has some more functionality such as collision and advanced movements.

When we want to add a component to our class, we need to decide what class, that component should be.

One of the class is SceneComponent, one other is StaticMeshComponent, and one other is UCapsuleComponent And so on.
By default a Pawn based class has a component called RootComponent. It is a pointer to USceneComponent.

Forward declaration:

Basically when we have an object of a C++ class in our code, the compiler doesn’t know what is that object unless we define it
through headers (#include NameOfClass). But this is going to make our code very huge in the size, especially when we want to
use an object that have very big class! One solution to define an object without having its header is Forward direction!

To do forward direction we put the keyword class before the type name, like so: class ObjectOfAClassWithoutHeader;

But we can’t still use this object to access functionality or data member of that class!!!!

Now you might ask "what is the reason to do forward declaration when you can’t use it?”.

Well check the video 112 which explain why this can be good practice.

We don’t need header file when we want to define a pointer to a class as long as we are using Forward declaration, but we need
header file if we want to use that pointer!

CreateDefaultSubobject<T>()

This is a template function to create a sub object. It means that we can construct a subcomponent based another father component.

Inside angle brackets (<T>) we put the component that we want to create based on that, and inside the parenthesis we put the
name of our sub component. This name is a string and not the same as the variable names!

For example:

UStaticMeshComponent* StaticMeshPointer = CreateDefaultSubObject<UStaticMeshComponent> (TEXT (“Cool Mesh”));

This template function returns the address of the newly created sub component so we can store it in a pointer that point the type
inside the angle brackets.

Recalling a bit of C++:

In inheritance of C++, it’s important to be aware of public, private and protected members.

Let’s say we have a base class.

If there is a drived class that inherits this base class (let’s say public inheritance type) then we can say that:

This drived class have access to the public members of base class. Just like any other program!

The object of this drived class can access the function members of base class that are defined in public section.

Just like the picture below:


As explained above about the inheritance in C++, the child object can access the public functions of the base class. Take this into consideration,
then we can say that an UStaticMeshComponent has access the public functions of USceneComponent.

USceneComponent has a child called UPrimitiveComponent and UPrimitiveComponent has a child called UMeshComponent and
UMeshComponent has a child called UStaticMeshComponent.

In brief UStaticMeshComponent is a child of USceneComponent!

Some UPROPERTY inputs:

-VisibleAnywhere

-EditAnywhere

-VisibleInstanceOnly

-VisibleDefaultsOnly

-EditInstanceOnly

-EditDefaultsOnly

Above Properties are about detail panel but not affecting the Event Graph panel (the place that we do blueprint programming). For blueprint land we
have following properties.

-BlueprintReadWrite

-BlueprintReadOnly

*note that you use UPROPERTY with multi properties. For instance UPROPERTY (VisibleAnywhere, BlueprintReadWrite)

Check the following link for more details:

https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/GameplayArchitecture/Properties/Specifiers/
If we want to use some properties for private section variables, we need to add a property as follow, otherwise it’s not going to
work and we will get an error. (You can give a try and see the error if you want to)

UPROPERTY(EditAnywhere, BlueprintReadWrite): it’s an error in private section.

UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = “true”)): it’s ok in private section.

Category keyword also used as property to make category of some variable (you used it before). Example is below:

UPROPERTY(EditAnywhere, category = “NAME OF CATEOGY”)

Possessing means to design some input to have some actions like movement from an actor.

It’s a bit complicated and try to read it again later via different links or videos.

For now I will just write down some key functions name:

-AxisInput is used inside the editor, project setting etc.

You should use AxisInput to bind a function to it. You can use the following functions for this job:

virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

AddActorLocalOffset():

This function is for the AActor class. This function moves the actor in local direction.

In this function sweep is used to avoid collision. What is sweep in game engine? Basically it’s an ability of game engine that it
can check each frame weather the next frame will be a collision of two actors or not. If there is collision at next frame, so the engine
handle it in a way that before the collision happening the actor moves back to the border of collision. (Figure below)

AddActorLocalRotation():

There is two types of this function, one that take a FRotator and the other that take FQuat.

The FRotator is handled by Roll, Pitch and Yaw angles.

bSweep parameter in this function and also function AddActorLocalOffset() is used for collision.

If it’s true, then when the engine has two or more actors, and it’s sweeping, it will stop the collision between the moving actors.

About the sweep I have explained above.

Casting is very common in programming. It’s used to convert directly different types to each other. But you can’t convert every types to each
other. Basically casting is used to convert a pointer to base class to a derived class.

For example if you have a function that is only for derived class and you want to access that function through a base class pointer, then you can
cast the pointer to base class to became a pointer to derived class and then you can use it to access the function.

Each Pawn has a controller. The controller can be either PlayerController or AIController. ( Check the pic below)
APawn::GetController():
return the controller of this actor.

The above function return pointer to Controller which is the parent of APlayerController. The function we want to access it is insidethe
APlayerController. From the other side it’s not possible in C++ to store a base class object into a pointer of derived class. It means that storing
the APawn::GetController() into the APlayerController pointer results in compilation error. To solve it we use casting as follow:

Cast<T>(P):

T -> is the type of pointer we want to cast to it.

P -> is the type that we want to cast.

Cast<APlayerController> (AController*) -> this will cast the pointer of ACtonroller to a pointer of the type APlayerController.

HitResult:

When we hit something we say that we have


Drawing invisible line like this called Line Trace
Trace Hit

If we do Line Trace and hit something, then the Trace Hit store some information in a structure called FHitResult.

This FHitResult structure contains information as follow:

The location of hit event.

The actor that being hit.

You might also like