🦀 ClawHub
Unreal Engine
by @ivangdavila
Avoid common Unreal mistakes — garbage collection, UPROPERTY macros, replication authority, and asset reference pitfalls.
TERMINAL
clawhub install unreal-engine📖 About This Skill
name: Unreal Engine description: Avoid common Unreal mistakes — garbage collection, UPROPERTY macros, replication authority, and asset reference pitfalls. metadata: {"clawdbot":{"emoji":"🎯","os":["linux","darwin","win32"]}}
Garbage Collection
UPROPERTY() to preventUPROPERTY() marks for GC tracking — without it, pointer becomes danglingTWeakObjectPtr for optional references — doesn't prevent collection, check IsValid()NewObject() for UObjects — never raw new, GC won't track itUPROPERTY and UFUNCTION
UPROPERTY() required for Blueprint access — and for GC trackingUFUNCTION() for Blueprint callable/events — also required for replicationEditAnywhere vs VisibleAnywhere — edit allows changes, visible is read-onlyBlueprintReadWrite vs BlueprintReadOnly — controls Blueprint access levelActor Lifecycle
BeginPlay after all components initialized — safe to access componentsPostInitializeComponents before BeginPlay — for component setupEndPlay for cleanup — called on destroy and level transitionTick Performance
PrimaryActorTick.bCanEverTick = falseGetWorldTimerManager().SetTimer()PrePhysics, DuringPhysics, PostPhysicsReplication
UPROPERTY(Replicated) for variable sync — implement GetLifetimeReplicatedPropsUFUNCTION(Server) for client-to-server RPC — must be Reliable or UnreliableHasAuthority() to check if server — before executing authoritative logicRole and RemoteRole for network role checks — ROLE_Authority is serverAsset References
TSoftObjectPtr) load on demand — for optional or large assetsLoadSynchronous() or AsyncLoad for soft refs — don't access until loadedTSubclassOf — type-safe class selectionMemory and Pointers
TSharedPtr for non-UObjects — reference counted, auto-deletesTUniquePtr for exclusive ownership — can't copy, moves onlyMakeShared() for creation — single allocation for object and control blocknew/delete with smart pointers — choose one patternCommon Mistakes
IsValid() node before accessGetWorld() null in constructor — world doesn't exist yet, use BeginPlayFString for display, FName for identifiers — FName is hashed, faster comparison