Files
PalUIExtension/Reflection/UnrealObjectRef.hpp
2026-09-07 19:33:58 -04:00

46 lines
1.1 KiB
C++

#pragma once
#include <optional>
#include <type_traits>
#include <DynamicOutput/DynamicOutput.hpp>
#include <Unreal/UObjectGlobals.hpp>
#include <Unreal/UObject.hpp>
#include <Unreal/UClass.hpp>
#include <Unreal/CoreUObject/UObject/Class.hpp>
#include <Unreal/CoreUObject/UObject/UnrealType.hpp>
#include <Static/ClassCache.hpp>
namespace PalUIExtension::Reflection
{
using namespace RC;
using namespace RC::Unreal;
class UnrealObjectRef
{
public:
explicit UnrealObjectRef(const TCHAR* Path, const TCHAR* DebugTag)
: m_path(Path), m_debug_tag(DebugTag) {
Static::ClassCache::RegisterSlot(&m_cached);
}
auto Get() -> UObject*
{
if (m_cached) return m_cached;
m_cached = UObjectGlobals::StaticFindObject<UObject*>(nullptr, nullptr, m_path, false);
if (!m_cached)
{
Output::send<LogLevel::Warning>(STR("[{}] could not resolve '{}'\n"), m_debug_tag, m_path);
}
return m_cached;
}
private:
const TCHAR* m_path;
const TCHAR* m_debug_tag;
UObject* m_cached{};
};
}