Various Deprecate Markup Syntaxes in Unreal Engine

Words: 494

Introduction

As a project grows, you may find that some logic needs to be refactored. For C++ this is relatively easy: mainstream IDEs all provide some refactoring support, so renaming and finding references are fairly convenient.

For Blueprint, however, a one-click operation is not really possible, and changing old logic directly may cause many problems. Especially for logic that already has a large number of references, a direct change may create unexpected amounts of work. In that case, one option is to build a new implementation and then gradually deprecate the old one. To do this gracefully, Unreal Engine provides several syntaxes for marking things as deprecated.

If your project uses an additional scripting language, you need to check the corresponding implementation to choose a refactoring approach.

Puerts is recommended as a type-safe scripting language; you may also want to read this article: Some knowledge about migrating from UnLua to PuerTS in Unreal Engine

Redirecting

If you need to rename something, prefer Unreal Engine’s redirect system: Relevant knowledge about redirecting in Unreal Engine.

Deprecation markers

UPROPERTY

For a property, you only need to rename the variable to the _DEPRECATED version and add the deprecation specifiers.

This does not affect the compilation of existing Blueprints, so you can remove references during that period.

cpp
1
2
UPROPERTY(EditAnywhere)
int32 Value;
cpp
1
2
UPROPERTY(meta=(DeprecatedProperty, DeprecationMessage="Use NewValue instead."))
int32 Value_DEPRECATED;

UFUNC­TION

For UFUNC­TION it is simpler: just add the DeprecatedFunction meta specifier to the function.

cpp
1
2
3
4
UPROPERTY(BlueprintPure)
int GetValue() const {
    return 0;
}
cpp
1
2
3
4
UPROPERTY(BlueprintPure, meta=(DeprecatedFunction, DeprecationMessage="Use GetNewValue() instead."))
int GetValue() const {
    return 0;
}

UCLASS

For UCLASS, renaming is also required.

cpp
1
2
3
4
UCLASS()
class UTestObject : public UObject {
    GENERATED_BODY()
};
cpp
1
2
3
4
UCLASS(Deprecated)
class UDEPRECATED_TestObject : public UObject {
    GENERATED_BODY()
};

UENUM & USTRUCT

The DEPRECATED_ syntax above does not seem to be supported for affecting Blueprint compilation, but for C++ the engine appears to have the UE_DEPRECATED marking syntax.

It is more recommended to rename it to a deprecated name and then handle it with the redirect system: Relevant knowledge about redirecting in Unreal Engine.

UE_DEPRECATED

Probably the most common deprecation marker, usually used to mark a function or variable as deprecated as of a certain engine version.

The syntax is UE_DEPRECATED(引擎版本号, 提示消息). When a deprecated variable or function is used in C++ on a version after the one in which it was deprecated, the compiler and IDE will report it.

Custom deprecation macros

Because whether something counts as deprecated with Unreal Engine’s UE_DEPRECATED depends on the engine version, it may be inconvenient in ordinary projects, so you can wrap your own deprecation macro.

cpp
1
2
3
4
#define META_DEPRECATED(...) [[deprecated(__VA_ARGS__ " This code has been marked as deprecated and may be deleted in subsequent versions. Please refer to the latest documentation for reference logic upgrade.")]]

#define META_DEPRECATED_DISABLE() META_WARNING_DISABLE(4996)
#define META_DEPRECATED_ENABLE() META_WARNING_ENABLE()

References

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...