- jakub.hubacek
- Posts: 2
- Joined:
Using Delegate Commands with Noesis in UE4
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
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Using Delegate Commands with Noesis in UE4
Hi Jakub,
What is the purpose of extracting the functions to another class? In theory you would want to execute functions of the same view model from that DelegateCommand.
Right now we only support UFUNCTION (with 0 or 1 parameters) to be used as a Command property. And you can specify a pair of functions to have both Execute and CanExecute callbacks:
Could that work for you?
What is the purpose of extracting the functions to another class? In theory you would want to execute functions of the same view model from that DelegateCommand.
Right now we only support UFUNCTION (with 0 or 1 parameters) to be used as a Command property. And you can specify a pair of functions to have both Execute and CanExecute callbacks:
Code: Select all
UFUNCTION()
void ButtonPressed();
UFUNCTION()
bool CanExecuteButtonPressed();
- jakub.hubacek
- Posts: 2
- Joined:
Re: Using Delegate Commands with Noesis in UE4
I was thinking about extracting executive logic into another class which could be reused in another view model if suitable.
Solution you are providing works for us too :) I was just interested if there is another approach.
Thank you
Solution you are providing works for us too :) I was just interested if there is another approach.
Thank you
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Using Delegate Commands with Noesis in UE4
I guess you can still reuse some logic encapsulated in another class by accessing it from the view model functions.
I'll mark this as solved then.
I'll mark this as solved then.
Who is online
Users browsing this forum: Ahrefs [Bot], camimamedov and 61 guests