Hi,
How exactly does `Transient` work?
Default initialization confusion:
I thought every `UPROPERTY()`—even with no flags—is always zero-initialized at object construction. However, in PIE sessions, I have an actor filling a UPROPERTY array on `BeginPlay()`. Sometimes after restarting the match (same world instance reused), this array still contains old elements instead of clearing.
I’m specifically referring to plain `UPROPERTY()` vs `UPROPERTY(Transient)`, not properties edited or overridden via Blueprint defaults. Why might this happen?
Marking properties as `Transient`:
Some devs recommend marking everything possible as `Transient` if it doesn’t require serialization. Is this actually a good practice officially? Does it provide real benefits (memory savings, cook-time reduction), or is it only a defensive measure? Are there any downsides?
Engine code to study:
Which engine source files/functions best demonstrate:
- Zero-initialization logic for plain UPROPERTYs.
- How exactly `Transient` properties are skipped during serialization.
- Interaction between `Transient`, GC, and PIE world resets.
For example, I have a UWorldSubsystem class with an array of Actors that gets filled during gameplay:
UPROPERTY() TArray<TObjectPtr<AActor>> MyActors;
Should I explicitly mark `MyActors` as `Transient`, or does it not make sense in this context?
Thanks in advance for clarifying!
— Kirill Mintsev