'Unreal > BP & UE Library' 카테고리의 다른 글

code 내장 함수  (0) 2024.05.17
BP Interface  (0) 2024.05.16
BP node list 1  (0) 2024.05.16
UE Dispatch & Delegate  (0) 2024.05.16
BP Node 리스트  (0) 2024.05.16
  • #pragma once : 다중상속 중 일부클래스 중첩 시 에러(중복적용)을 막기 위해, 1번만컴파일 선언 ( 헤더의 최상단에 입력 )
  • Kismet/GameplayStatics.h
    • UGamePlayStatics
      • GetPlayerController
  • ObjectGlobals
    • NewObject<template>(owner, template::StaticClass());
  • APlayerController*
    • → GetViewTarget()  #해당 컨트롤러의 view가 빙의한 Camera 참조
    • SetViewTarget(arg)  #해당 PC의 view를 arg(Camera)에 빙의
    • SetViewTargetWithBlend(arg1, arg2)  #위와동일, arg2는 blend time
    • GetViewportSize(int&, int&)
    • SetMouseLocation(int, int)
    • GetAudioListenerPosition(FVetor&, FVector&, FVector&) : 위치, 앞방향, 오른쪽방향
    • ULocalPlayer* ( 접근 : Cast<ULocalPlayer>(Player) )
      • ViewportClient
        • ShouldAlwaysLockMouse()
    • GetHitResultAtScreenPosition(FVector2 ViewportClient→GetMousePosition(넣을 FVector2D), TEnumAsByte<ECollisionChannel> APlayerController::CurrentClickTraceChannel, bool (trace complex여부), FHitResult (HitResult 반환할 변수))
  • UParticleSystemComponent*
  • USphereComponent*
  • CreateDefaultSubobject<Component타입>(TEXT(Component네임))
  • RootComponent  #해당 actor의 rootComponent_ set/get
  • SetupPlayerInputComponent(UInputComponent)
  • PlayerInputComponent : UInputComponent형의 플레이어 입력 저장 큐
    • BindAxis(프로젝트세팅_Input_AxisMapping 이름(str), this, &호출함수), 입력명의 Scale(float)값을 호출함수의 인자로 전달 ( 호출함수는 float arg를 하나 가져야 함 )
  • Actor
    • (T) GetComponentByClass(T::StaticClass()) : return actor의 T형 component
    • (T) FindComponentByClass(T::StaticClass()) : return actor의 T형 component ( 차이는 모름 )
  • Cast<T>(component*) : return component의 T형변환Pawn : APawn형
    • Controller : 제어자, AController형
      • → GetControlRotation() : FRotator형
    • Character
      • AddControllerYawInput : 마우스좌우효과 (화면돌리기)
      • AddControllerPitchInput : 마우스 상하효과 (화면돌리기)
      • bPressedJump : Bool형, 점프효과(true 점프를 누르고있는 상태 → false 후 다시 true로 변해야 점프효과 발생)
    • AddMovementInput(방향, 속도)
    • SetupPlayerInputComponent(UInputComponent* PlayerInputComponent);
  • UE
    • FMath
      • TRotationMatrix<double>
      • Clamp(value1, min, max)
  • USkeletalMeshComponent
    • → SetOnlyOwnerSee(bool)
  • UObject
    • CreateDefaultSubobject<type>(name)
  • RotationMatrix(Rotatior)
    • .GetScaledAxis(EAxis::축)
  • F(Scale)(Rotation)(Translation)Matrix([vector]scale, [rotator]rotation, [vector]translation).transform[Position/Vector] : 좌표계 변환 ( 직교좌표계 → 직교좌표계 한정 )
  • GEngine→AddOnScreenDebugMessage(타입-1, int 시간, FColor::색상, TEXT 내용)
  • GetPawn() : controller가 빙의한 pawn을 return. 비어있을 시 nullptr 반환
  • World : GetWorld( )
    • DeltaSeconds : GetDeltaSeconds( )
  • 통합
    • DrawDebugDirectionalArrow(월드_GetWorld(), FVector(시작위치), ~~ )

 

'Unreal > BP & UE Library' 카테고리의 다른 글

Class Name 접두  (0) 2024.05.17
BP Interface  (0) 2024.05.16
BP node list 1  (0) 2024.05.16
UE Dispatch & Delegate  (0) 2024.05.16
BP Node 리스트  (0) 2024.05.16

BluePrint Interface(BPI)

BP 내 interface 상속

 

BP 내 Interface 함수 호출

 

Cast와 달리 타입정보가 불분명하거나 다양할 때 Type 체크 없이 Message로 Call 시도할 수 있음

'Unreal > BP & UE Library' 카테고리의 다른 글

Class Name 접두  (0) 2024.05.17
code 내장 함수  (0) 2024.05.17
BP node list 1  (0) 2024.05.16
UE Dispatch & Delegate  (0) 2024.05.16
BP Node 리스트  (0) 2024.05.16
  • Time
    • Get world delta seconds : global delta sec
    • Get time Seconds : global stacked sec
  • Is Valid
    • 할당여부 판정 ( isNull / isNone )
  • (F/R/T/V) Interp
    • deltaTime + TotalTime 받아서 보간시켜줌 ( float, rotator, transfrom, vector? )
    • deltaTime값 알아서 누적시켜줘서 편함
  • dot
    • 내적
  • 흐름제어
    • Switch
    • Branch
    • Sequence
    • DoN ( DoOnce )
      • N번까지만 flow True, 이후 reset 전까지 flow False
    • FlipFlop : A부터 시작해서 호출될때마다 다음 시퀀스 A ↔ B 스위치
    • For Loop ( For Loop With Break )
    • While Loop
    • Gate
      • 별개 flow에 의해 Trigger되어 Open/Close가 switch 되는 Flow
    • MultiGate
      • 호출할때마다 순차적으로 다음 Flow 활성
        • Loop : 마지막 Flow 사용 시 첫 Flow 사용
        • IsRandom : 아직 이번Loop에서 안쓴 Flow중 랜덤 Flow 사용
  • PlayerController
    • Get current Mouse cursor : 마우스 커서 모양 get/set
      • Enum Type
  • Set View Target with Blend
    • 카메라 전환 ( to actor )
    • 타겟의 활성화된 맨 위 카메라컴포넌트 적용
  • Math::Transform : world loc to local loc
  • Math::Invert Transform : local loc to world loc
  • Draw material to render target
  • Timeline
 

타임라인

언리얼 엔진 4 블루프린트의 타임라인에 대한 개요서입니다.

docs.unrealengine.com

 

'Unreal > BP & UE Library' 카테고리의 다른 글

Class Name 접두  (0) 2024.05.17
code 내장 함수  (0) 2024.05.17
BP Interface  (0) 2024.05.16
UE Dispatch & Delegate  (0) 2024.05.16
BP Node 리스트  (0) 2024.05.16

구조

 

 

BP 샘플

부모 ( 호출자 ) < - > 자식 ( 반응자 )

 

코드 구성


부모 자식
부모.h 부모(호출).cpp 자식.h 자식(실행).cpp
DECLARE_MULTICAST_DELEGATE([Delegate 클래스명 선언]);
UClass()
{ [Delegate 클래스명]
[Delegate 객체]; }
호출
[Delegate 객체]
.
Broadcast(); ( multi일 경우 )
[Delegate 객체].ExcuteIfBound(); ( single일 경우 )
  [부모class]->[Delegate 객체].AddUObject([자식](타겟 함수를 보유한 class의 객체), &[타겟 함수]);
( multi일 경우 )
( single은 BindUObject // UObject 외에도 TsharedReference, Function 등 존재 )
       

 

BP에서 delegate에 Binding 하기

- static 함수로 BlueprintCallable함수를 만듬 ( delegate를 포함한 class의 생성 함수 )

- dynamic delegate는 BlueprintAssignable로 지정

 

상호참조 ( circular dependency )

  1. 문제 : Header 파일은 상호참조가 불가능함 
  2. 예시
    1. A.h : # include B.h
    2. B.h : # include A.h

  3. 방법
    1. 한쪽에서는 소스파일에서 include
    2. 예시
      1. A.h : # include B.h
      2. B.cpp : # include A.h

 

 

전방선언 ( forward declaration )

  1. 문제 : 함수가 상호참조할 경우
    1. 같은 파일 내의 두 함수 중 하나는 상대방을 인식할 수 없음
    2. 다른 파일간의 두 함수 중 하나는 header에서 include를 못하므로, header에서 함수선언시 type을 정의할 수 없음

  2. 예시
    1. 본문의 경우, child.h에서 InitFunction 선언 시 argument로 dispatcherTest를 가질 수 없음

  3. 방법
    1. 동일한 명칭의 가상(더미) 클래스를 만듬
      1. 헤더파일에서만 사용됨
      2. 소스파일에서는 #include가 되어있을 경우, 자동으로 대체되는걸로 보임
      3. DisPatchChild.h - 
        class ADispatcherTest;

 

자신 클래스에 대한 참조 ( Self reference )

  1. 문제
    1. cpp에서 this는 const var* 형태 이므로 다른 class에 reference로 전달 시, 내부에 접근하지 못하는 문제

  2. 예시
    1. this를 통해 얻은 pointer를 그대로 전달 시, 해당 객체가 보유한 [delegate] 객체를 call만 가능하고 bind는 불가능

  3. 해결
    1. const_cast로 const 제거
      1. CustomClass* [var] = const_cast<CustomClass*>(this)

  4. 추가정보
    1. const [Ptr] : 해당 ptr을 통해 내용물의 set 불가
    2. [Ptr] const : 해당 ptr의 참조 대상(메모리 주소) 변경 불가(재할당 불가)
    3. const [Ptr] const 가능

 

샘플 코드

부모.h

더보기
// Fill out your copyright notice in the Description page of Project Settings.
 
#pragma once
 
#include "CoreMinimal.h"
 
#include "Components/BoxComponent.h"
#include "Components/SceneComponent.h"
#include "Components/ArrowComponent.h"
#include "DisPatcherChild.h"
 
#include "GameFramework/Actor.h"
#include "DispatcherTest.generated.h"
 
DECLARE_MULTICAST_DELEGATE(TurnLightDelegate);
 
UCLASS()
class MYPROJECT_API ADispatcherTest final : public AActor
{
    GENERATED_BODY()
     
public:
    // Sets default values for this actor's properties
    ADispatcherTest();
    UPROPERTY(EditAnywhere, blueprintReadWrite, Category = "Dispatcher")
        USceneComponent* RootComp;
    UPROPERTY(EditAnywhere, blueprintReadWrite, Category = "Dispatcher")
        UBoxComponent* BoxComp;
    UPROPERTY(EditAnywhere, blueprintReadWrite, Category = "Dispatcher")
        UArrowComponent* ArrowComp;
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dispatcher")
        UStaticMeshComponent* BoxMesh;
     
protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;
     
public:
    // Called every frame
    virtual void Tick(float DeltaTime) override;
     
    bool bIsOn = false;
    UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Dispatcher")
        TArray<ADisPatcherChild*> MyChildren;
     
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dispatcher")
        int32 ChildCount=5;
 
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dispatcher")
        TSubclassOf<ADisPatcherChild> ChildClass;
 
    UFUNCTION(BlueprintCallable, Category = "Dispatcher")
    void CreateChildActor(int Count, TArray<ADisPatcherChild*>& ChildrenArr) const;
 
    UFUNCTION()
        void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
            UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
            const FHitResult& SweepResult);
     
    TurnLightDelegate TurnLightDelegatePtr; // 1. Declare a delegate pointer
         
};

 

부모.cpp

더보기
// Fill out your copyright notice in the Description page of Project Settings.
 
 
#include "DispatcherTest.h"
 
#include "ActorReferencesUtils.h"
 
 
// Sets default values
ADispatcherTest::ADispatcherTest()
{
    // 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;
 
    RootComp = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
    RootComponent = RootComp;
    BoxComp = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxComp"));
    BoxComp->SetupAttachment(RootComponent);
    BoxComp->SetRelativeScale3D(FVector(2, 2, 2));
    ArrowComp = CreateDefaultSubobject<UArrowComponent>(TEXT("ArrowComp"));
    ArrowComp->SetRelativeRotation(FRotator(0, 90, 0));
    ArrowComp->SetupAttachment(RootComponent);
    BoxMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BoxMesh"));
    BoxMesh->SetRelativeScale3D(FVector(0.64, 0.64, 0.64));
    BoxMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
    BoxMesh->SetupAttachment(BoxComp);
 
    BoxComp->OnComponentBeginOverlap.AddDynamic(this, &ADispatcherTest::OnOverlapBegin);
}
 
// Called when the game starts or when spawned
void ADispatcherTest::BeginPlay()
{
    Super::BeginPlay();
 
    CreateChildActor(ChildCount, MyChildren);  
}
 
// Called every frame
void ADispatcherTest::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
 
}
 
void ADispatcherTest::CreateChildActor(const int Count, TArray<ADisPatcherChild*>& ChildrenArr) const
{
    for (int i = 0; i <= Count; i++)
    {
        FVector TargetLoc = GetActorLocation() + FVector(0, 100*i, 0);
        TargetLoc -= this->GetActorLocation();
        TargetLoc = FRotationMatrix(RootComponent->GetComponentTransform().Rotator()).TransformPosition(TargetLoc);
        TargetLoc += this->GetActorLocation();
 
         
        AActor* TempChild;
        TempChild = GetWorld()->SpawnActorDeferred<AActor>(ChildClass, FTransform(TargetLoc), nullptr, nullptr, ESpawnActorCollisionHandlingMethod::AlwaysSpawn);
        TempChild->FinishSpawning(FTransform(TargetLoc));
 
        if (ADisPatcherChild* Child = Cast<ADisPatcherChild>(TempChild))
        {
            ADispatcherTest* SelfRef = const_cast<ADispatcherTest*>(this);
            Child->InitFunction( SelfRef );
            ChildrenArr.Add(Child);
        }
         
         
    }
    //ParentActor->TurnLightDelegatePtr.BindSP(this, &ADisPatcherChild::TurnLight);
}
 
 
void ADispatcherTest::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
    UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
    UE_LOG(LogTemp, Log, TEXT("Overlap Begin"));
    TurnLightDelegatePtr.Broadcast();
    //TurnLightDelegatePtr.ExecuteIfBound();

 

 

자식.h

더보기
// Fill out your copyright notice in the Description page of Project Settings.
 
#pragma once
 
#include "CoreMinimal.h"
 
//#include "DispatcherTest.h"
#include "Components/ArrowComponent.h"
#include "Components/SphereComponent.h"
#include "Components/SceneComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Components/PointLightComponent.h"
 
#include "GameFramework/Actor.h"
#include "DisPatcherChild.generated.h"
 
class ADispatcherTest;
 
UCLASS()
class MYPROJECT_API ADisPatcherChild : public AActor
{
    GENERATED_BODY()
     
public:
    // Sets default values for this actor's properties
    ADisPatcherChild();
 
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dispatcher")
        USceneComponent* RootComp;
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dispatcher")
        USphereComponent* SphereComp;
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dispatcher")
        UStaticMeshComponent* SphereMesh;
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dispatcher")
        UPointLightComponent* PointLightComp;
 
    bool bIsOn = false;
protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;
 
public:
    // Called every frame
    virtual void Tick(float DeltaTime) override;
     
     
    UFUNCTION(BlueprintCallable, Category = "Dispatcher")
        void TurnLight();
     
    void InitFunction(ADispatcherTest* ParentActor);
     
};

자식.cpp

더보기
// Fill out your copyright notice in the Description page of Project Settings.
 
#include "DisPatcherChild.h"
 
#include "DispatcherTest.h"
 
 
 
 
// Sets default values
ADisPatcherChild::ADisPatcherChild()
{
     
    // 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;
 
    RootComp = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
    RootComponent = RootComp;
     
    SphereComp = CreateDefaultSubobject<USphereComponent>(TEXT("sphereComp"));
    SphereComp->SetupAttachment(RootComponent);
 
    SphereMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("SphereMesh"));
    SphereMesh->SetRelativeLocation(FVector(0, 0, 0));
    SphereMesh->SetRelativeScale3D(FVector(0.5, 0.5, 0.5));
    SphereMesh->SetupAttachment(SphereComp);
    //SphereMesh->SetStaticMesh(ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("StaticMesh'/Engine/BasicShapes/Sphere.Sphere'")).Object);
 
    PointLightComp = CreateDefaultSubobject<UPointLightComponent>(TEXT("PointLightComp"));
    PointLightComp->SetRelativeLocation(FVector(0, 0, 100));
    PointLightComp->SetupAttachment(RootComponent);
    PointLightComp->SetIntensity(1000);
     
}
 
// Called when the game starts or when spawned
void ADisPatcherChild::BeginPlay()
{
    Super::BeginPlay();
     
}
 
// Called every frame
void ADisPatcherChild::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
 
}
 
void ADisPatcherChild::TurnLight()
{
     
    if (bIsOn == false) // 불켜기
    {
        UE_LOG(LogTemp, Log, TEXT("TurnOn"));
        PointLightComp->SetIntensity(100000);
        bIsOn = true;
    }
    else// if (bIsOn == true) // 불끄기
    {
        UE_LOG(LogTemp, Log, TEXT("TurnOff"));
        PointLightComp->SetIntensity(1000);
        bIsOn = false;
    }
}
 
void ADisPatcherChild::InitFunction(ADispatcherTest* ParentActor)
{
    ADispatcherTest* ParentIns = Cast<ADispatcherTest>(ParentActor);
    UE_LOG(LogTemp, Log, TEXT("Initted Child"));
     
    //ParentIns->TurnLightDelegatePtr.BindUObject( this , &ADisPatcherChild::TurnLight);
    //ParentIns->TurnLightDelegatePtr.BindUFunction(this, FName("TurnLight"));
    ParentIns->TurnLightDelegatePtr.AddUObject(this, &ADisPatcherChild::TurnLight);
    //ParentIns->TurnLightDelegatePtr.BindUObject(this, &ADisPatcherChild::TurnLight);
     
}

'Unreal > BP & UE Library' 카테고리의 다른 글

Class Name 접두  (0) 2024.05.17
code 내장 함수  (0) 2024.05.17
BP Interface  (0) 2024.05.16
BP node list 1  (0) 2024.05.16
BP Node 리스트  (0) 2024.05.16

Space

  • Loacation
    • Actor Location ( get / set )

Physics

 

Logic

  • Input : 해당 blue print의 "Input" action node 활성화 여부
    • Enable input
      • target : 활성화 할 블루프린트
      • Player controller : 활성화할 플레이어 ( get player controller0 = 자신 )
    • Disable input
  • Array
    • set array elem (element) : array [ index ] = item ( input size to fit : allocate? )
  • Branch : if ( bool )
  • Sequence 순차실행
  • EventDispatcher : Inter BluePrint Call/Back 기능
    • Call EventDispatcher :
      • input : vars ( eventDispatcher의 설정에 따라 type/갯수 변경 )
    • Bind EventDispatcher : input
      • Call event dispatcher를 가진 class(component) ( type은 EventDispatcher가 포함된 )
      • Call 시 반응할 Event node
    • Custom Event
      • input 된 값을 받을 vars
  • Damage
    • apply damgage
  • Make Literal Name
    • AI-BB등 외부 변수를 이름으로 가져오기
  • Is valid : 해당 변수가 null or Err 인지 체크

 

AI

  • AI navigation
    • Move
      • simple move to location : location(var)로 controller(var)를 이동 (nav mesh 기반)
  • Controller
  • Pawn
    • Get Controlled Pawn : 현재(var) AI controller에 의해 제어되는 pawn들 return
    • Get controller : 해당 Pawn의 Controller component
  • Behavior Tree
    • Run Behavior tree : AI controller에서 behavior tree를 호출
    • BTTask_BlueprintBase : Behavior tree에서 task로 호출할 수 있는 logic의 blueprint
      • event receive execute AI : AI task로 호출당할 시 수행
      • Finish execute : task 종료를 알림. 상위 BT에서 다음 task로 넘어갈것 전달
    • Sequence : 순차실행. fail이 나올떄까지 실행. 하나라도 성공시 success 반환
    • Selector : 선택실행. true 나올때까지 실행, 하나라도 실패시 fail 반환
  • BlackBaord
    • (get/set) blackboard value as (type) : BTT(behavior tree task)의 블루프린트에서 black board 변수에 접근 ( var type = blackboard key selector ) → BT (behavior tree) 에서 match시켜줘야 함
    • (get/set) value as (type) : BTT/S/D가 아닌 AI controller에서는 blackboard 없이 그냥 value 함수를 사용 / 1. BB를 받고, 2. 변수명을 받아서, 3. 값을 입력(set)

Relation

  • Get
    • user widget object : 사용자지정 widget 블루프린트
    • controlled pawn (BP AI controller용) : 해당(기본 self) AI controller를 사용하는 BP Charactor
    • controller : pawn의 nav 관리 속성

Calculation

 

Common property

  • visibility : rendering 여부 ( input "renderable obj" / visibility(bool) / propagate to children(bool)-자식들에게 적용 여부
    • set visibility
    • is visible
  • Remove : actor 제거
    • remove from parents ( input "actor" )
  • player controller
    • player's control asignment ( multi_ player 0 == self )
    • get player controller ( var = int ( 멀티플레이시 플레이어 num. 자신 == 0 )
  • Cast to ~ : 형변환. 해당 type 속성을 뽑아내어 사용할 수 있는 형태로 전환
    • cast to 사용자지정
  • Spawn
    • spawn emitter at location
    • spawn actor from class
  • distroy
    • distroyActor

 

UI ( MGU / Canvas )

  • Add to viewport : 화면에 출력 ( input "Widget Object"(UI/MGU) )
  • mouse cursor : 마우스 커서 관련 숨김 등
    • Set show mouse cursor ( input "플레이어 컨트롤러" )
    • Set input mode Game / UI : UI만 조작가능 상태로 전환 / 기타 등등
  • Create
    • create widget : UI bp 생성

Console

  • print text : 콘솔에 text 출력 ( input "text" )
  • print string : 콘솔에 string 출력 ( input "string" )
 



'Unreal > BP & UE Library' 카테고리의 다른 글

Class Name 접두  (0) 2024.05.17
code 내장 함수  (0) 2024.05.17
BP Interface  (0) 2024.05.16
BP node list 1  (0) 2024.05.16
UE Dispatch & Delegate  (0) 2024.05.16

+ Recent posts