How to bind a ...SPARSE_DELEGATE? C++

I can’t find any example to bind a delegate of this type.

I have tried many ways but none work.

Can someone provide an example please.

Thank you so much!!

Most likely you already found this info about sparse delegates:

Advanced Delegates in C++ · ben🌱ui

It doesn’t show how to bind them, but it says it’s of type Dynamic Multicast.
I guess you should be able to use AddDynamic on it:

MyObject->OnDelegate.AddDynamic(this, &UMyObject::ResponseMethod);

UE5.2 ChildActorComponent.cpp does it with AddDynamic:

.cpp

ChildActor = World->SpawnActor(ChildActorClass, &Location, &Rotation, Params);
ChildActor->OnDestroyed.AddDynamic(this, &ThisClass::OnChildActorDestroyed);

.h

UFUNCTION()
void OnChildActorDestroyed(AActor* DestroyedActor);

Something else is wrong which I don’t immediately see. You are not missing any header includes? Of AActor? CoreMinimal?

1 Like

Hi Roy,
Thanks for answering!!

Yes, I have Actor.h and CoreMininimal.h in the header.

I think the problem is specific to:

FActorBeginOverlapSignature: (AActor::OnActorBeginOverlap)

And

FActorEndOverlapSignature: (AActor::OnActorEndOverlap)

Maybe it’s implemented in another way.

It’s the first time this has happened to me.
This usually works → AddDynamic();

The error I have is the following:

Cannot convert void(UCNiagaraDisolve:: * )(AActor*, AActor*) to parameter type TBaseDynamicDelegate<FWeakObjectPtr, void, AActor*, AActor*>::TMethodPtrResolver::FMethodPtr (aka void(__thiscall UCNiagaraDisolve:: * )(AActor*, AActor*))

I do not know what is the problem.
It should be a function like this

void Func(AActor*, AActor*)
However it fails.

Can you try these two specific delegates?
AActor::OnActorBeginOverlap
AActor::ActorEndOverlap

I am using UE5.2.0 too…

I tried this other way too but it didn’t work either… although there are no errors.

Thanks you so much your help

I’m Sorry, just realized it’s a JetBrain Rider problem.
I had a power outage and the computer shut down.

Some files needed by JetBrain Rider got corrupted or something like that.

2

But I can compile from the command line and there are no errors.

However JetBrain Rider is very crazy…

I can compile from the editor and there are no errors either.

Then AddDynamic( ) works fine.
There was never a problem with the delegates.

I deleted Save, Intermediate and .sln and regenerates the Visual Studio files and it didn’t fix the problem.

So now I have to find out what it is and how to fix that file Microsoft.Cpp.Default.props

Today is definitely not a good day for me…

I’m so sorry for the inconvenience.

And thank you very much for your help!!

1 Like

Never heard of this but files created for the unreal project can mostly be regenerated. Folders you can delete on the project level are Intermediate, Binaries, DerivedDataCache from your project and plugins (if you develop those). The .sln file, .idea folder, .vs folder can go. Then you right click on the .uproject and click “generate project files”. After that you should be able to compile. If it’s corruption of some sorts outside the project say on the VS or Rider level you need their installer to verify the installation.

Also, if you see any errors / warnings related to intellisense which are not build errors, ignore them. They are wrong.

1 Like

Yes, I did. The engine and project files appear to be fine.

It’s just Rider… well, if I can’t fix this file I’ll do a complete reinstall.

At least I know where it is:

“C:\Program Files\JetBrains\JetBrains Rider 2023.1\tools\MSBuild\Microsoft\VC\v170\Microsoft.Cpp.Default.props”

Thank you very much for your help Roy!!
You Rock!!

1 Like