Xkonti / NimForUE-docs

Documentation page for NimForUE Unreal Engine plugin
https://nimforue.pages.dev
MIT License
4 stars 2 forks source link

Expand on casting #12

Open Xkonti opened 5 months ago

Xkonti commented 5 months ago

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:

Xkonti commented 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)
jmgomez commented 5 months ago

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++