Casting Quick Start Guide

Quick Start for the Casting communication method.

Windows
MacOS
Linux

구현 방법 선택

블루프린트

C++

Overview

Casting is a common communication method where you take a reference to an Actor and try to convert it to a different class. If the conversion is successful, then you can use Direct Actor communication to access its information and functionality.

This method requires a reference to the Actor in your Level so you can use the Cast node to try to convert it to a specific class. This communication method uses a one-to-one relationship between your working Actor and your target Actor.

Goals

In this Quick Start guide, you will learn how to use Casting to access information from a target Actor.

Objectives

  • Create an Actor that rotates based on the value of a variable.

  • Modify the ThirdPersonCharacter Blueprint to cast to the rotating Actor on overlap.

  • Create several child Actors from the rotating Actor to show how casting works with many Actors that share the same parent.

1 - Required Setup

  1. In the New Project Categories section of the menu, select Games and click Next.

    image alt text

  2. Select the Third Person template and click Next.

    image alt text

  3. Select the Blueprint and With Starter Content options and click Create Project.

    image alt text

Section Results

You have created a new Third Person project and are now ready to learn about casting.

2 - Creating a Rotating Actor

For this example, you will create an Actor that begins rotating a Static Mesh when the player is nearby.

  1. Right-click in the Content Browser and click Blueprint Class under the Create Basic Asset section.

    image alt text

  2. Select Actor as your Parent Class and name the Blueprint BP_RotateObject.

    image alt text

    image alt text

  3. Open the Blueprint by double-clicking it in the Content Browser. Then in the Blueprint editor window, go to the Components panel and click the Add Component button. Search for and select Static Mesh. This will add a Static Mesh component to the Blueprint.

    image alt text

  4. With the Static Mesh component selected, go to the Details panel and click the Static Mesh dropdown. Search for and select Shape_Cube.

    image alt text

  5. Right-click in the Event Graph to open the context sensitive search window and search for and select AddActorLocalRotation to add this node to the graph.

    image alt text

  6. Connect the AddActorLocalRotation node to Event Tick. Set the Z value to 2.0.**

    image alt text

  7. Compile and Save the Blueprint.

  8. Drag the BP_RotateObject Actor into the Level and press Play. You should see the cube rotate continuously.

    image alt text

    image alt text

  9. Now you will add a condition so the object spins only when the player is nearby. Right-click the Event Graph and add a Branch node. Connect the node between the output pin of Event Tick and the input pin of AddActorLocalRotation nodes.

    image alt text

  10. Create a variable of type Boolean called Can Rotate and connect it to the Condition pin of the Branch **node, as shown below.

    image alt text

  11. Compile the Blueprint and set the Default Value of CanRotate to False.

    image alt text

  12. Go to the My Bueprints tab and click the + Function button to create a new function. Name the function OverlappedPlayer.

    image alt text

  13. With the function selected, go to the Details panel and click the + New Parameter button. Name the new boolean parameter Begin Overlap.

    image alt text

  14. Drag the CanRotate variable inside the function and select Set CanRotate. Connect the Overlapped Player node to the Set Can Rotate node. Connect the Begin Overlap pin of the Overlapped Player node to the Can Rotate pin of the Set Can Rotate node, as seen below.

    image alt text

  15. Compile and Save the Blueprint.

Section Results

In this section you created an Actor that rotates a Static Mesh when the CanRotate variable is set to True.

3 - Modifying the Player Blueprint

In this section, you will modify the ThirdPersonCharacter Blueprint to cast to the BP_RotateObject Actor and set its Rotate variable to True when you are nearby.

  1. With your ThirdPersonCharacter Blueprint selected, go to the World Outliner and click Edit ThirdPersonCharacter to open the Blueprint.

    image alt text

  2. In the Blueprint editor window, go to the Components panel and click the Add Component button. Search for and select Sphere Collision. This will add a Sphere Collision component to the Blueprint.

    image alt text

  3. With the Sphere Collision component selected, go to the Details panel and set the Radius to 200.

    image alt text

  4. Right-click the Sphere Collision component and select the OnComponentBeginOverlap and OnComponentEndOverlap events to add them to the Event Graph.

    image alt text

    image alt text

  5. Drag from the On Component Begin Overlap node's Other Actor pin, then search for and select cast to BP Rotate Object.

    image alt text

  6. Drag from the As BP Rotate Object pin and search for and select Overlapped Player. Enable the Begin Overlap pin of the Overlapped Player node.

    image alt text

    image alt text

  7. Repeat steps 5 and 6 to attach the same nodes to the On Component End Overlap node. Disable the Begin Overlap pin of the Overlapped Player node.

    image alt text

  8. Compile and Save the Blueprint.

  9. Press Play and approach the BP_RotateObject Actor to see it rotate only when the player is nearby.

    image alt text

Section Results

In this section you added a sphere overlap component to the ThirdPersonCharacter Blueprint that uses the Cast node on any Actor it overlaps.

The ThirdPersonCharacter Blueprint uses the overlapped Actor reference to Cast to BP_RotateObject and sets the CanRotate variable to True when nearby. If the overlapped Actor is not an instance of the BP_RotateObject class, then the node will fail and no variable will be set.

4 - Adding Different Rotating Shapes

You will now create several child Actors from the BP_RotateObject Actor class to add different shapes that react to the player. This will demonstrate how you can use child Actors to make changes or add additional functionality, while still retaining the ability to cast to the common parent class.

  1. Right-click BP_RotateObject in the Content Browser and select Create Child Blueprint Class. Name the Blueprint BP_RotateObject_Cone.

    image alt text

  2. Repeat the above step two more times and create BP_RotateObject_Pyramid and BP_RotateObject_Torus.

    image alt text

  3. Open BP_RotateObject_Cone and select the Static Mesh component in the Components window. From the Details panel, click the Static Mesh dropdown and search for and select Shape_Cone.

    image alt text

  4. Set the Y Rotation to 90 degrees.

    image alt text

  5. Compile and Save the Blueprint.

  6. Repeat the above steps for BP_RotateObject_Pyramid and select Shape_Quad_Pyramid as the Static Mesh.

  7. Repeat the above steps for BP_RotateObject_Torus and select Shape_Torus as the Static Mesh. Rotate the mesh by 90 degrees in Y.

  8. Drag each shape into your Level and press Play to verify they all rotate when the player is nearby.

    image alt text

    image alt text

Section Results

In this section you created several child Actors from the BP_RotateObject Actor and assigned a different Static Mesh to each.

You also learned that you can cast to an Actor's parent class to access common functionality. In this case, you overlapped each separate child Actor and casted to its parent class to trigger the rotation.

Next Steps

Now that you know how to use casting, take a look at the other types of communication referenced in the Actor Communication documentation page.

Overview

Casting Blueprint classes is a common communication type, in which you use a reference to an Actor class Blueprint and convert it to a different class. If this conversion is successful, then you can use Direct Blueprint communication to access its information and functionality.

This method requires a reference to the Actor class Blueprint in your Level so you can use the Cast node to try to convert it to a specific class. This communication type uses a one-to-one relationship between your working Actor class Blueprint to your target Actor class Blueprint.

Goals

In this Quick Start guide, you will learn how to create an Actor in C++, that has the Blueprint casting functionality used to access information from a target Blueprint.

Objectives

  • Create a Blueprint that rotates based on the value of a variable.

  • Modify the ThirdPersonCharacter Blueprint to cast to the rotating Blueprint on overlap.

  • Create several child Blueprint clases from the rotating Blueprint to show how Blueprint casting works for many Blueprint classes that share the same parent.

1 - Required Setup

  1. In the New Project Categories section of the menu, select Games and click Next.

    image alt text

  2. Select the Third Person template and click Next.

    image alt text

  3. Select the C++ and With Starter Content options and click Create Project.

    image alt text

Section Results

You have created a new Third Person project and are now ready to learn about casting with Actor class Blueprints.

2 - Creating a Rotating Actor

For this example, you will create an Actor class Blueprint that has the functionality to rotate its Static Mesh Component when the player is nearby.

  1. From the C++ Class Wizard, create a new Actor class named RotatingActor.

    image alt text

  2. In the class defaults of your RotatingActor.h implement the following code.

    public: 
    
        void SetbCanRotate(bool value);
    
    protected:
    
        // Called when the game starts or when spawned
        virtual void BeginPlay() override;
        void RotateActor();
        bool bCanRotate;
    
        UPROPERTY(EditAnywhere, BlueprintReadWrite)
        UStaticMeshComponent* MeshComp;
  3. Navigate to your RotatingActor.cpp and declare the following code in the constructor ARotatingActor::ARotatingActor

    RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneComponent"));
    MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
    MeshComp->SetupAttachment(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
    bCanRotate = false;
  4. Implement the following code for your ARotatingActor::RotateActor method.

    AddActorLocalRotation(ActorRotation);
  5. Navigate to the ARotatingActor::Tick method and implement the following code.

    void ARotatingActor::Tick(float DeltaTime)
    {
        Super::Tick(DeltaTime);
    
        if (bCanRotate)
        {
            RotateActor();
        }
    }

Finished Code

RotatingActor.h

#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "RotatingActor.generated.h"

UCLASS()
class BPCOMMUNICATION_API ARotatingActor : public AActor
{
GENERATED_BODY()

public: 
    // Sets default values for this actor's properties
    ARotatingActor();
    void SetbCanRotate(bool value);

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

    UPROPERTY(EditAnywhere, BlueprintReadWrite)
    UStaticMeshComponent* MeshComp;

    //Rotation Rate for our Actor.
    const FQuat ActorRotationRate =(FQuat(FRotator(0,2,0));

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

RotatingActor.cpp

#include "RotatingActor.h"

// Sets default values
ARotatingActor::ARotatingActor()
{
    // Set this actor 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("SceneComponent"));
    MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
    MeshComp->SetupAttachment(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
    bCanRotate = false;
}

void ARotatingActor::SetbCanRotate(bool value)
{
    bCanRotate = value;
}

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

void ARotatingActor::RotateActor()
{
    AddActorLocalRotation(ActorRotation);
}

// Called every frame
void ARotatingActor::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    if (bCanRotate)
    {
        RotateActor();
    }
}
  1. Compile your code.

  2. In the editor, navigate to your C++ Classes folder, right-click your RotatingActor and from the C++ class actions dropdown menu, select Create Blueprint class based on RotatingActor named BP_RotatingActor.

    image alt text

  3. In the class defaults for your BP_RotatingActor Blueprint, navigate to the Components tab, select the MeshComp Static Mesh Component, then navigate to the Details panel and from the Static Mesh category,select the arrow next to the Static Mesh variable. Lastly, from the dropdown menu, select the Shape_Cube static mesh.

    image alt text

  4. Compile and save your Blueprint.

  5. From the Content Browser, drag an instance of your Bp_RotatingActor into the Level.

    image alt text

Section Results

In this section, you created a Rotating Actor class Blueprint that includes the functionality to rotate a Static Mesh on tick when the bCanRotate variable is set to True.

3 - Modifying the Third Person Character Class

In this section, you will modify the BPCommunicationCharacter classto cast to the Rotating Actor class and set the bCanRotate variable to True when your player is nearby.

  1. Open your BPCommunicationCharacter.h and implement the following.

    protected:
        virtual void NotifyActorBeginOverlap(AActor* OtherActor);
        virtual void NotifyActorEndOverlap(AActor* OtherActor);
        class USphereComponent* SphereComp;
  2. In your BPCommunicationCharacter.cpp include the following class libraries

    include "RotatingActor.h"

    include "Components/SphereComponent.h"

  3. From the constructor ABPCommunicaionCharacter::BPCommunicationCharacter declare the following code.

    SphereComp = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComp"));
    SphereComp->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform);
    SphereComp->SetSphereRadius(200);
  4. Next, implement the ABPCommunicationCharacter::NotifyActorBeginOverlap, and ABPCommunicationCharacter::NotifyActorEndOverlap.

    void ABPCommunicationCharacter::NotifyActorBeginOverlap(AActor* OtherActor)
    {
        if (ARotatingActor* RotatingActorCheck =Cast<ARotatingActor>(OtherActor))
        {
            ActorCheck->SetbCanRotate(true);
        }
    }
    
    void ABPCommunicationCharacter::NotifyActorEndOverlap(AActor* OtherActor)
    {
        if (ARotatingActor* RotatingActorCheck = Cast<ARotatingActor>(OtherActor))
        {
            ActorCheck->SetbCanRotate(false);
        }
    }
  5. Compile your code.

Finished Code

BpCommunicationCharacter.h

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "BPCommunicationCharacter.generated.h"

UCLASS(config=Game)
class ABPCommunicationCharacter : public ACharacter
{
    GENERATED_BODY()

    /** Camera boom positioning the camera behind the character */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
    class USpringArmComponent* CameraBoom;

    /** Follow camera */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
    class UCameraComponent* FollowCamera;

    public:
        ABPCommunicationCharacter();

        /** Base turn rate, in deg/sec. Other scaling may affect final turn rate. */
        UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
        float BaseTurnRate;

        /** Base look up/down rate, in deg/sec. Other scaling may affect final rate. */
        UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
        float BaseLookUpRate;

    protected:
        virtual void NotifyActorBeginOverlap(AActor* OtherActor);
        virtual void NotifyActorEndOverlap(AActor* OtherActor);

    UPROPERTY(EditAnywhere, BlueprintReadWrite)

        class USphereComponent* SphereComp;

        /** Resets HMD orientation in VR. */
        void OnResetVR();

        /** Called for forwards/backward input */
        void MoveForward(float Value);

        /** Called for side to side input */
        void MoveRight(float Value);

        /** 
         * Called via input to turn at a given rate. 
         * @param Rate  This is a normalized rate, i.e. 1.0 means 100% of desired turn rate
         */
        void TurnAtRate(float Rate);

        /**
         * Called via input to turn look up/down at a given rate. 
         * @param Rate  This is a normalized rate, i.e. 1.0 means 100% of desired turn rate
         */
        void LookUpAtRate(float Rate);

        /** Handler for when a touch input begins. */
        void TouchStarted(ETouchIndex::Type FingerIndex, FVector Location);

        /** Handler for when a touch input stops. */
        void TouchStopped(ETouchIndex::Type FingerIndex, FVector Location);

    protected:
        // APawn interface
        virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
        // End of APawn interface

    public:
        /** Returns CameraBoom subobject **/
        FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }

        /** Returns FollowCamera subobject **/
        FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
};

BpCommunication.cpp

// Copyright Epic Games, Inc. All Rights Reserved.
#include "BPCommunicationCharacter.h"
#include "HeadMountedDisplayFunctionLibrary.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/InputComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/Controller.h"
#include "GameFramework/SpringArmComponent.h"
#include "CeilingLight.h"
#include "RotatingActor.h"
#include "Components/SphereComponent.h"

//////////////////////////////////////////////////////////////////////////
// ABPCommunicationCharacter

ABPCommunicationCharacter::ABPCommunicationCharacter()
{
    // Set size for collision capsule
    GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);

    // set our turn rates for input
    BaseTurnRate = 45.f;
    BaseLookUpRate = 45.f;

    // Don't rotate when the controller rotates. Let that just affect the camera.
    bUseControllerRotationPitch = false;
    bUseControllerRotationYaw = false;
    bUseControllerRotationRoll = false;

    // Configure character movement
    GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...   
    GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate
    GetCharacterMovement()->JumpZVelocity = 600.f;
    GetCharacterMovement()->AirControl = 0.2f;

    // Create a camera boom (pulls in towards the player if there is a collision)
    CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
    CameraBoom->SetupAttachment(RootComponent);
    CameraBoom->TargetArmLength = 300.0f; // The camera follows at this distance behind the character   
    CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller

    // Create a follow camera
    FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
    FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
    FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm

    SphereComp = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComp"));
    SphereComp->SetupAttachment(GetMesh(), FAttachmentTransformRules::KeepRelativeTransform);
    SphereComp->SetSphereRadius(200);

    // Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) 
    // are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++) 
}

//////////////////////////////////////////////////////////////////////////
// Input

void ABPCommunicationCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
    // Set up gameplay key bindings
    check(PlayerInputComponent);
    PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
    PlayerInputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping);
    PlayerInputComponent->BindAction("Use", IE_Pressed, this, &ABPCommunicationCharacter::ToggleCeilingLight);
    PlayerInputComponent->BindAxis("MoveForward", this, &ABPCommunicationCharacter::MoveForward);
    PlayerInputComponent->BindAxis("MoveRight", this, &ABPCommunicationCharacter::MoveRight);

    // We have 2 versions of the rotation bindings to handle different kinds of devices differently
    // "turn" handles devices that provide an absolute delta, such as a mouse.
    // "turnrate" is for devices that we choose to treat as a rate of change, such as an analog joystick
    PlayerInputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput);
    PlayerInputComponent->BindAxis("TurnRate", this, &ABPCommunicationCharacter::TurnAtRate);
    PlayerInputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput);
    PlayerInputComponent->BindAxis("LookUpRate", this, &ABPCommunicationCharacter::LookUpAtRate);

    // handle touch devices
    PlayerInputComponent->BindTouch(IE_Pressed, this, &ABPCommunicationCharacter::TouchStarted);
    PlayerInputComponent->BindTouch(IE_Released, this, &ABPCommunicationCharacter::TouchStopped);

    // VR headset functionality
    PlayerInputComponent->BindAction("ResetVR", IE_Pressed, this, &ABPCommunicationCharacter::OnResetVR);
}

void ABPCommunicationCharacter::NotifyActorBeginOverlap(AActor* OtherActor)
{
    if (ARotatingActor* RotatingActorCheck =Cast<ARotatingActor>(OtherActor))
    {
        ActorCheck->SetbCanRotate(true);
    }
}

void ABPCommunicationCharacter::NotifyActorEndOverlap(AActor* OtherActor)
{
    if (ARotatingActor* RotatingActorCheck = Cast<ARotatingActor>(OtherActor))
    {
        ActorCheck->SetbCanRotate(false);
    }
}

void ABPCommunicationCharacter::OnResetVR()
{
    // If BPCommunication is added to a project via 'Add Feature' in the Unreal Editor the dependency on HeadMountedDisplay in BPCommunication.Build.cs is not automatically propagated
    // and a linker error will result.

    // You will need to either:
    //      Add "HeadMountedDisplay" to [YourProject].Build.cs PublicDependencyModuleNames in order to build successfully (appropriate if supporting VR).
    // or:
    //      Comment or delete the call to ResetOrientationAndPosition below (appropriate if not supporting VR)

    UHeadMountedDisplayFunctionLibrary::ResetOrientationAndPosition();
}

void ABPCommunicationCharacter::TouchStarted(ETouchIndex::Type FingerIndex, FVector Location)
{
        Jump();
}

void ABPCommunicationCharacter::TouchStopped(ETouchIndex::Type FingerIndex, FVector Location)
{
        StopJumping();
}

void ABPCommunicationCharacter::TurnAtRate(float Rate)
{
    // calculate delta for this frame from the rate information
    AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds());
}

void ABPCommunicationCharacter::LookUpAtRate(float Rate)
{
    // calculate delta for this frame from the rate information
    AddControllerPitchInput(Rate * BaseLookUpRate * GetWorld()->GetDeltaSeconds());
}

void ABPCommunicationCharacter::MoveForward(float Value)
{
    if ((Controller != nullptr) && (Value != 0.0f))
    {
        // find out which way is forward
        const FRotator Rotation = Controller->GetControlRotation();
        const FRotator YawRotation(0, Rotation.Yaw, 0);

        // get forward vector
        const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
        AddMovementInput(Direction, Value);
    }
}

void ABPCommunicationCharacter::MoveRight(float Value)
{
    if ( (Controller != nullptr) && (Value != 0.0f) )
    {
        // find out which way is right
        const FRotator Rotation = Controller->GetControlRotation();
        const FRotator YawRotation(0, Rotation.Yaw, 0);

        // get right vector 
        const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);

        // add movement in that direction
        AddMovementInput(Direction, Value);
    }
}
  1. Press Play and approach the BP_RotateObject Actor to see it rotate only when the player is nearby.

    image alt text

Section Results

In this section you added a Sphere Component to the BPCommunicationCharacter class.

You also created the overlap logic necessary to cast into the RotatingActor class, and call its SetbCanRotate function, which sets the bCanRotate variable to True when the player Character's Sphere Component overlaps it.

4 - Adding Different Rotating Shapes

You can now create several child Blueprint classes from the BP_RotatingActor Blueprint to add different shapes that react to the player Character. This will demonstrate how you can use child Blueprint classes to modify or add additional functionality, while still retaining the ability to cast to the common parent class.

  1. From the Content Browser, right-click BP_Rotating Actor and select Create Child Blueprint Class. Name the Blueprint BP_RotateObject_Cone.

    image alt text

  2. Repeat step 1 two more times to create BP_RotateObject_Pyramid and BP_RotateObject_Torus Blueprint classes.

    image alt text

  3. Open BP_RotateObject_Cone in the Blueprint editor and select the Static Mesh component from the Components tab. From the Details panel, click the Static Mesh dropdown then search for and select Shape_Cone.

    image alt text

  4. Set the Y Rotation to 90 degrees.

    image alt text

  5. Compile and save the Blueprint.

  6. Repeat steps 3 - 5 for BP_RotatingActor_Pyramid and select Shape_Quad_Pyramid as the Static Mesh.

  7. Repeat steps 3 - 5 for BP_RotatingActor_Torus and select Shape_Torus as the Static Mesh. Rotate the mesh by 90 degrees in Y.

  8. Drag each shape into your Level and click Play to verify they all rotate when the player is nearby.

    image alt text

    image alt text

Section Results

In this section, you created several child Blueprint classes from the BP_RotateObject Blueprint and assigned a different Static Mesh to each.

You also learned that you can cast to a Blueprint Actor's parent class to access common functionality. In this case, you overlapped each separate child Blueprint and casted to its parent class to trigger the rotation.

Next Steps

Now that you know how to use Blueprint casting, take a look at the other communication types referenced in the Actor Communication documentation page.

언리얼 엔진 문서의 미래를 함께 만들어주세요! 더 나은 서비스를 제공할 수 있도록 문서 사용에 대한 피드백을 주세요.
설문조사에 참여해 주세요
건너뛰기