Using Delegate Commands with Noesis in UE4
Posted: 04 Feb 2021, 22:21
Hello.
We are trying to implement DelegateCommand with Unreal Engine. I know we can use UFUNCTION but I would like to have option to extract whole action into another class (eg AddItemDelegateCommand).
Here is example of view model implementation in c#. This is roughly something we aim for.
And here is our C++ variant of view model in UE4.
UDelegateCommand is our attempt to implement DelegateCommand for UE4.
Inspiration from this documentation page: https://www.noesisengine.com/docs/Gui.C ... omCommands
UDelegateCommand looks like this:
But we are not able to set execute function correctly via MakeDelegate.
Is this even possible with NoesisGUI for UE4? Maybe we are doing something wrong, I can share more snippets.
It would be great to have working example to look into, for second or third variant.
Can you please point me in the right direction to look? :)
Thank you,
Jakub Hubacek
We are trying to implement DelegateCommand with Unreal Engine. I know we can use UFUNCTION but I would like to have option to extract whole action into another class (eg AddItemDelegateCommand).
Here is example of view model implementation in c#. This is roughly something we aim for.
Code: Select all
public class TestViewModel : ViewModelBase {
public String name{ get; private set; }
public DelegateCommand DelegateCommand { get; private set; }
public DelegateCommandsViewModel() {
DelegateCommand1 = new DelegateCommand(
() => MessageBoxService.Show("This can be in "));
}
}
Code: Select all
UCLASS(Blueprintable)
class UTestViewModel : public UBaseViewModel
{
GENERATED_BODY()
public: // Properties
UPROPERTY(BlueprintReadWrite)
FString name;
//first variant - this works fine
UFUNCTION()
void ButtonPressedCommand1();
//second variant - this would be also handy
UFUNCTION() // or UPROPERTY()?
UButtonPressedCommand buttonPressedCommand2; // ButtonPressedCommand implements Noesis::ICommand
//third varinat - this is what we aimed for
UFUNCTION() // or UPROPERTY()?
UDelegateCommand buttonPressedCommand3;
};
Inspiration from this documentation page: https://www.noesisengine.com/docs/Gui.C ... omCommands
UDelegateCommand looks like this:
Code: Select all
UCLASS()
class UDelegateCommand final : public UObject, public Noesis::BaseCommand
{
GENERATED_BODY()
public:
typedef Noesis::Delegate<void(BaseComponent*)> ExecuteFunc;
typedef Noesis::Delegate<bool(BaseComponent*)> CanExecuteFunc;
UDelegateCommand() {};
UDelegateCommand(const ExecuteFunc& ExecuteMethod);
UDelegateCommand(const ExecuteFunc& ExecuteMethod, const CanExecuteFunc& CanExecute);
bool CanExecute(BaseComponent* Param) const override;
void Execute(BaseComponent* Param) const override;
void SetExecuteFunc(const ExecuteFunc& Method);
private:
ExecuteFunc MethodToExecute;
CanExecuteFunc CanExecuteMethod;
};
Is this even possible with NoesisGUI for UE4? Maybe we are doing something wrong, I can share more snippets.
It would be great to have working example to look into, for second or third variant.
Can you please point me in the right direction to look? :)
Thank you,
Jakub Hubacek