

'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 |
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 |
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 시도할 수 있음
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 |
타임라인
언리얼 엔진 4 블루프린트의 타임라인에 대한 개요서입니다.
docs.unrealengine.com
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 |
부모 | 자식 | ||
부모.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 등 존재 ) |
|
- static 함수로 BlueprintCallable함수를 만듬 ( delegate를 포함한 class의 생성 함수 )
- dynamic delegate는 BlueprintAssignable로 지정
class ADispatcherTest;
부모.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);
}
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 |
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 |