Open Xkonti opened 5 months ago
@jmgomez demonstrated that you can do pretty chaining with a different variant of ueCast
that takes a type without using generics:
proc getPlayerPawn(): APlayerCharacterBasePtr =
self
.getActorOfClass(APlayerCharacterBase.Subclass)
.ueCast(APlayerCharacterBase)
ueCast
is equivalent of Cast
in UE C++ (notice it's just using it behind the scenes) and it should be used for casting UObject
based types. The reason why it isnt called cast
, its because it is already a reserved word in Nim. The try
version is just a helper to wrap it around an Option
. Nothing special. There is also castField
which should be used for FProperties
at such and it has the direct equivalent in UE C++
When it comes to the common topic of casting in UE, currently there's only an example of using
ueCast
.We should expand on the topic. This includes investigating other ways to cast:
tryUECast
-func tryUECast*[T : UObject](obj:UObjectPtr) : Option[ptr T]
- wraps the cast pointer inOption[ptr T]
tryCast
-func tryCast*[T: SomePointer](pntr: SomePointer): Option[T]