I have a member function (in C++) which has several inputs and a delegate, also as an input, declared as const reference. So everything works fine. After compile and dropping that node in BP, delegate’s pin appears as expected. However, I need to add some default values to other function’s arguments, but then compiler asks for default value of that delegate too and refuses compilation.
Is there a way, to somehow assign default value to that delegate in declaration of that function which would automatically create another BP node of proper function coresponding to that delegate and binds it to pin of delegate of that member function? So when user in BP create node of member function, actually two nodes appear, bound together.
As long as you move the parameters that do not have default values before the ones that do it should compile fine.
I don’t think the reflection system allows to expose to blueprints a function that has a delegate passed as a parameter though (it compiles fine without UFUNCTION)
You usually just use a blueprint assignable delegate like this
delegate
property
Setting any type of default value is ignored for the parameters.
It does if it’s a DYNAMIC_DELEGATE
and not a DYNAMIC_MULTICAST_DELEGATE
.
Unfortunately even then you can’t provide a default value and have it be blueprint callable. The best you can do is to move it earlier in the parameter list so that it’s in front of the optional parameters.
No. If you want behavior like that it’s significantly more complicated than default values or UFUNCTION markup.
It’s not exactly what you’re asking for, but I’ve done a lot of the heavy lifting in my Starfire Utilities plugin with this basic node so that you can pick a function from a dropdown instead. Basically combining the two nodes into a single one. But it does require a bit more effort to use than some additional markup.
Interesting. I didn’t know this was possible.
Tried passing in a custom struct with default values. Seems to do the work.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor2.generated.h"
USTRUCT(BlueprintType,Blueprintable)
struct FMyStruct
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite)
int32 testNumber = 44;
FMyStruct()
{
testNumber = 44;
}
};
DECLARE_DYNAMIC_DELEGATE_OneParam(FMyDelegateEvent, FMyStruct, test);
UCLASS()
class YOUR_API AMyActor2 : public AActor
{
GENERATED_BODY()
public:
AMyActor2();
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
UFUNCTION(BlueprintCallable)
void DoSomethingDefault(const FMyDelegateEvent del, FMyStruct passedStruct, bool isOn = true)
{
del.ExecuteIfBound(passedStruct);
};
};
Gives printout
And if you hook up a struct via the make command
Its not about defaults inside a delegate. Its about defaults of arguments of some function which among it’s arguments has a delegate as const reference, as argument too. For visual sake in BP, it is convinient that argument holding delegate input, be the last one, because its pin in BP is usualy linked to the top-right pin of bound function. So if it doesn’t appear as last one, its “wire” is going to cross other input’s “wires”. However, it seems that I have to live with that delegate argument be the first one (since other arguments have default values, so they have to appear after those without default value). If there would exist some meta tag for reordering appearance of arguments in BP node regardles of their order in function declaration…
Also, for general solution, how would I approach the following:
- Detect when user pick MyFunc from the list in BP and drops it in graph (there must be some event generated by editor when editing Blueprints and that happens. I would like to catch that event and I am aware that code handler of that is only meaningful (will be runing) when editor is active (same as meta behavior) and doesnt impact runtime.
- In my custom handler of that event, create a NEW node in BP with coordinates close to MyFunc node (the same as if user click on that delegate pin and chose create new event from the menu, then renamed it to some meaningfull name)
- Bind that node to MyFunct delegate pin
Is there any meta tag which would allow such customization on spawning some node in BP graph?
No.
- You’d want to use the BlueprintInternalUseOnly meta. This would prevent the default CallFunction node from being generated for your function.
- Get a hold of the
FBlueprintActionDatabaseRegistrar
. I’m not really sure how to do this in general. I always get it as part of theUK2Node::GetMenuActions
virtual function when creating a custom node. So you could always create a custom node derived fromUK2Node_CallFunction
as one way to do it. - You create a blueprint spawner and configure it. It looks like there are some delegates, virtuals and protected functions that you can use but I’ve never done anything particularly complicated there so I can’t give you any further step by step details. But searching the engine for other implemenations of GetMenuActions will probably find the bits and pieces that you would need.