Implementation:CARLA simulator Carla Disable UE4 Macros
| Knowledge Sources | |
|---|---|
| Domains | Build System, Unreal Engine Integration |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
disable-ue4-macros.h is a utility header that saves and undefines Unreal Engine 4/5 preprocessor macros to prevent conflicts when compiling third-party or LibCarla code alongside UE4/UE5 headers.
Description
This large header (~6763 lines) serves as a macro isolation boundary. When LibCarla code needs to include non-UE headers (such as Boost, MsgPack, or other third-party libraries) while being compiled within the Unreal Engine build system, UE macros can cause naming conflicts. This file:
- Includes Carla.h to ensure UE macros are defined
- Sets BOOST_ERROR_CODE_HEADER_ONLY for header-only Boost error codes
- Pushes MSVC and Clang warning states and disables relevant warnings (e.g., 4668, 4191, -Wundef, -Wshadow)
- Uses #pragma push_macro / #undef for hundreds of UE macros (e.g., GET_AI_CONFIG_VAR, IMAGE_BRUSH, SAFE_RELEASE, CHECK_HR, etc.)
- Defines LIBCARLA_INCLUDED_FROM_UE4 to signal that code is being compiled in the UE context
This is always used in matched pairs with enable-ue4-macros.h which restores all saved macros.
Usage
Include this header before any non-UE header includes in code that compiles within the Unreal Engine build. Always pair with enable-ue4-macros.h afterward.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/util/disable-ue4-macros.h
Signature
// Guard and UE4 inclusion
#ifndef LIBCARLA_INCLUDED_DISABLE_UE4_MACROS_HEADER
#define LIBCARLA_INCLUDED_DISABLE_UE4_MACROS_HEADER
#include "Carla.h"
#endif
#define LIBCARLA_INCLUDED_FROM_UE4
// Push and undefine hundreds of UE macros:
#pragma push_macro("GET_AI_CONFIG_VAR")
#undef GET_AI_CONFIG_VAR
// ... (hundreds more macro push/undef pairs)
// Disable compiler warnings
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4668 4191 4647)
#endif
Import
#include <util/disable-ue4-macros.h>
// ... include non-UE headers here ...
#include <util/enable-ue4-macros.h>
I/O Contract
| Action | Effect | Scope |
|---|---|---|
| Include this header | Saves and undefines all UE macros; suppresses compiler warnings | All code until corresponding enable-ue4-macros.h |
| Defines LIBCARLA_INCLUDED_FROM_UE4 | Signals that code is compiled within UE context | Global preprocessor scope |
Usage Examples
// In a CARLA RPC header compiled within UE:
#ifdef LIBCARLA_INCLUDED_FROM_UE4
#include <util/enable-ue4-macros.h>
#include "Carla/Vehicle/VehicleControl.h"
#include <util/disable-ue4-macros.h>
#endif
// Non-UE code can now be included safely
#include <boost/asio.hpp>
#include "carla/rpc/Server.h"