Hi,
I’m looking for best practices to understand when IsValid / IsValidLowLevel should be used. What’s the design purposes and main differences between them? Looks like documentation doesn’t cover this question (or may be I don’t look the correct page?)
As I understood: Unreal object has several lifetime phases:
- It is created.
- It is initialized
- It is going to be destroyed.
- It is destroyed.
An we can use it only when it is initialized and not going to be destroyed. So that is the purpose of IsValid.
The question 1: may I propose that object is initialized (and valid) after it’s C++ constructor finished?
The question 2: what are the best practices for validity checking?
- If UObject A stores strong reference to an UObject B (stored as UPROPERTY member) and B is never destroyed before A destructor, can I rely only on checking B against nullptr inside methods of A? For example, A is an only owner of B.
- If A stores strong reference to an UObject B, but B can be destroyed before A destructor, does this require IsValid call before usage of B inside methods of A?
- If A gets object B as UPROPERTY of some another class (for example, GameStateBase subclass), does programmer have to use IsValid function and checking of B against nullptr is not correct because of B lifetime contract is not defined?
The question 3: what is the difference between IsValid, IsValidLowLevel, IsValidLowLevelFast, which one should be used?
Thanks in advance.
Hope, this question will help more newbies as me.