Xkonti / NimForUE-docs

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

Explain getters and setters for booleans #22

Open Xkonti opened 4 months ago

Xkonti commented 4 months ago

Explain how getAbc(): bool and setAbc(bool) ufuncs will get compiled into abc. Because of that uprop abc: bool should be named bAbc: bool instead to avoid conflicts.

[!NOTE] There are plans to generate fields instead of getters/setters for the uprops. The setProp is already taken because of a C++ interop issue with the bindings.

Example:

uClass UDirectInteractionComponent of UActorComponent:
    (Blueprintable, BlueprintType, BlueprintSpawnableComponent)

    uprops(BlueprintReadWrite, EditAnywhere):
        bEnabled: bool

    ufuncs(BlueprintCallable):
        proc getEnabled(): bool =
            self.bEnabled

        proc setEnabled(newValue: bool) =
            let prevEnabled = self.bEnabled
            self.bEnabled = newValue
            if prevEnabled != self.bEnabled:
                self.onEnabledChanged.broadcast(self.bEnabled)

        proc toggleEnabled() =
            # Use `setEnabled` on Nim side of things
            self.setEnabled(not self.bEnabled)