← 返回
安全合规

Unreal Engine

Avoid common Unreal mistakes — garbage collection, UPROPERTY macros, replication authority, and asset reference pitfalls.
避免常见的 Unreal 错误——垃圾回收、UPROPERTY 宏、复制权限和资源引用陷阱。
ivangdavila
安全合规 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 4
Stars
📥 1,549
下载
💾 169
安装
1
版本
#latest

概述

Garbage Collection

  • Raw pointers to UObjects get garbage collected — use UPROPERTY() to prevent
  • UPROPERTY() marks for GC tracking — without it, pointer becomes dangling
  • TWeakObjectPtr for optional references — doesn't prevent collection, check IsValid()
  • NewObject() for UObjects — never raw new, GC won't track it

UPROPERTY and UFUNCTION

  • UPROPERTY() required for Blueprint access — and for GC tracking
  • UFUNCTION() for Blueprint callable/events — also required for replication
  • EditAnywhere vs VisibleAnywhere — edit allows changes, visible is read-only
  • BlueprintReadWrite vs BlueprintReadOnly — controls Blueprint access level

Actor Lifecycle

  • BeginPlay after all components initialized — safe to access components
  • Constructor runs on CDO (Class Default Object) — don't spawn actors or access world
  • PostInitializeComponents before BeginPlay — for component setup
  • EndPlay for cleanup — called on destroy and level transition

Tick Performance

  • Disable tick when not needed — PrimaryActorTick.bCanEverTick = false
  • Use timers instead of tick + counter — GetWorldTimerManager().SetTimer()
  • Tick groups for ordering — PrePhysics, DuringPhysics, PostPhysics
  • Blueprint tick expensive — move hot logic to C++

Replication

  • Server is authority — clients request, server validates and replicates
  • UPROPERTY(Replicated) for variable sync — implement GetLifetimeReplicatedProps
  • UFUNCTION(Server) for client-to-server RPC — must be Reliable or Unreliable
  • HasAuthority() to check if server — before executing authoritative logic
  • Role and RemoteRole for network role checks — ROLE_Authority is server

Asset References

  • Hard references load with parent — bloats memory, use for always-needed
  • Soft references (TSoftObjectPtr) load on demand — for optional or large assets
  • LoadSynchronous() or AsyncLoad for soft refs — don't access until loaded
  • Blueprint class references: TSubclassOf — type-safe class selection

Memory and Pointers

  • TSharedPtr for non-UObjects — reference counted, auto-deletes
  • TUniquePtr for exclusive ownership — can't copy, moves only
  • MakeShared() for creation — single allocation for object and control block
  • Never mix raw new/delete with smart pointers — choose one pattern

Common Mistakes

  • Accessing null actor in Blueprint — use IsValid() node before access
  • PIE (Play In Editor) vs packaged build differ — test shipping build
  • Hot reload corrupts Blueprints — close editor, build, reopen
  • GetWorld() null in constructor — world doesn't exist yet, use BeginPlay
  • Spawning in constructor crashes — defer to BeginPlay or later
  • FString for display, FName for identifiers — FName is hashed, faster comparison

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-29 01:51 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

productivity

Word / DOCX

ivangdavila
创建、检查和编辑 Microsoft Word 文档及 DOCX 文件,支持样式、编号、修订记录、表格、分节符及兼容性检查等功能。
★ 438 📥 147,522
security-compliance

MoltGuard - Security & Antivirus & Guardrails

thomaslwang
MoltGuard — OpenClaw 安全守卫,由 OpenGuardrails 提供。安装 MoltGuard,保护您和您的用户免受提示注入、数据泄露和恶意攻击。
★ 116 📥 30,713
security-compliance

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,215 📥 266,438