관리 메뉴

fatalite

Unreal C++ 기초 (1) 블루프린트와 C++ 본문

게임/Unreal

Unreal C++ 기초 (1) 블루프린트와 C++

fataliteforu 2023. 1. 11. 15:31

Unreal C++은 쌩 C++보다 쉽게 사용할 수 있도록 만들어져있다고한다.


핫 리로드

Visual Studio에서 소스코드를 수정해서 컴파일하거나, 언리얼 에디터에 컴파일 버튼으로 수정 내용을 반영할 수 있다.


C++과 블루프린트의 조화는 어떻게 이루어지는가?

# C++ 변수

C++ 변수를 블루프린트에서 볼 수 있게 하려면

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Damage")

와 같이 추가하면된다.

다음 코드를 보면, 만약 Property가 바뀌면 블루프린트의 프로퍼티에도 반영할 수 있게끔 하는 코드이다.

한 가지 더 생각할 점은, #if WITH_EDITOR 와 #endif로 둘러싸여 있다는 것이다. 

 

# 블루프린트 프로퍼티로 반영

void AMyActor::PostInitProperties()
{
    Super::PostInitProperties();

    CalculateValues();
}

void AMyActor::CalculateValues()
{
    DamagePerSecond = TotalDamage / DamageTimeInSeconds;
}

#if WITH_EDITOR
void AMyActor::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
    CalculateValues();

    Super::PostEditChangeProperty(PropertyChangedEvent);
}
#endif

# 블루프린트에서 만든 함수를 C++

UFUNCTION(BlueprintImplementableEvent, Category="Damage")
void CalledFromCpp();

 

#C++에서 만든 함수를 블루프린터에서 

UFUNCTION(BlueprintCallable, Category="Damage")
void CalculateValues();

 

#C++에서 만든 함수를 override 가능하게 하는 것

UFUNCTION(BlueprintImplementableEvent, Category="Damage")
void CalledFromCpp();
UFUNCTION(BlueprintNativeEvent, Category="Damage")
void CalledFromCpp();
"blueprintimplementableEvent" and "blueprintNativeEvent" are types of events in the Unreal Engine, a game engine developed by Epic Games.

A "blueprintimplementableEvent" is an event that can be overridden in Blueprints, the visual scripting system in Unreal Engine. This means that developers can create their own custom behavior for the event in Blueprints, without having to modify the C++ code of the engine.

A "blueprintNativeEvent" is similar to "blueprintimplementableEvent" but with the addition of a native (C++) implementation. This native implementation will be used unless blueprint overrides it.

Both "blueprintimplementableEvent" and "blueprintNativeEvent" are used to create custom events that can be triggered by code or by the designer in Unreal Engine.

중요!!
But the main difference is that blueprintimplementableEvent allows blueprint to completely override the function whereas blueprintNativeEvent allows blueprint to add new functionality to the native function.

 

 

추가적으로,

 

Yes, that's a good summary of how to define a "blueprintNativeEvent" in C++ using Unreal Engine.

To summarize:

  1. Use the "UFUNCTION(BlueprintNativeEvent, Category = "MyCategory")" macro to mark the function as a "blueprintNativeEvent" that can be called from Blueprints.
  2. Define the event function, which will act as the entry point for the event and can be overridden in Blueprints. In this function, you should call the implementation function that you will define next.
  3. Define the "*_Implementation" function, which contains the default implementation of the event and will be called by the event function if it is not overridden in Blueprints. This is where you would write the main logic of the event.

It's important to keep in mind that you can pass parameters and return values with those functions like normal C++ functions, the UFUNCTION Macro will handle all the Unreal Engine specific code for you.

Also, it's good practice to give descriptive and meaningful names to the functions and use comments to document the behavior of the event, to make it easier to understand and maintain the code.


Q. C++로 만든 블루프린트 클래스를 다른 사용자가 추가적으로 수정하고,
그 이후에 C++ 클래스를 누군가가 수정했다면 수정된 블루프린터에 수정된 C++ 내용이 들어가게 되나?  

If you are using a C++ class in a Unreal Engine project and another user modifies that C++ class and you have blueprint which is referencing this c++ class, then the modifications made to the C++ class will not be automatically reflected in the blueprint. To see the changes in the blueprint, you will have to re-compile the blueprint node that uses the C++ class. This is because when you modify C++ class the engine does not know about the changes and does not automatically update it's use in Blueprints.
Another way is to create a new version of that c++ class, then you have to go back to the blueprint and update it to use the new class, which will have your latest modification. This will not affect the previous version of blueprints or other usages of that C++ class.

Q. 그럼 C++ 수정할 때마다 디자이너는 블루프린트를 다시 수정해야해?

If you create a new version of the C++ class and update the blueprint to use the new class, then the designer who is working with the blueprint will have to update their blueprint to use the new class as well. This process will involve remapping any variables or functionality from the old class to the new class, which may require some work 
However, it depends on how the c++ class is used. if the c++ class has a lot of custom functionality that blueprint is using, then it might require more effort. But if it's small changes or simple class without complex logic then it might be just remapping and replacing the node, which will be easy.
It's generally a good idea to communicate with designers and other team members when making significant changes to C++ classes that are used in blueprints to minimize the impact on their work.