# Binding to FCoreUObjectDelegates::PostDemoPlay

**URL:** <https://forums.unrealengine.com/t/binding-to-fcoreuobjectdelegates-postdemoplay/38097>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [August 10, 2015, 10:21am UTC](https://forums.unrealengine.com/t/binding-to-fcoreuobjectdelegates-postdemoplay/38097 "2015-08-10T10:21:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_89f0aa1e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_89f0aa1e](https://forums.unrealengine.com/u/anonymous_user_89f0aa1e)\
**Post date:** [August 10, 2015, 10:21am UTC](https://forums.unrealengine.com/t/binding-to-fcoreuobjectdelegates-postdemoplay/38097/1 "2015-08-10T10:21:36Z")

</div>

Got it working: See EDIT2 at bottom!

Hi!

I’m trying to bind to the FCoreUObjectDelegates::PostDemoPlay delegate.  
Currently, I have

```auto

FCoreUObjectDelegates::PostDemoPlay.AddUObject(this, &ATeamPlayerController::DemoStarted);

```

inside ATeamPlayerController  
which is executed upon an EXEC command from the console command in-game or directly at the start of the match (in the gamemode cycle when it goes to spectator mode).  
Unfortunately, it crashes at

```auto

FDelegateHandle Add( const FDelegate& Delegate )
	{
		FDelegateHandle Result;
		TDelegateInstanceInterface* DelegateInstance = (TDelegateInstanceInterface*)Delegate.GetDelegateInstance();

		if (DelegateInstance != nullptr)
		{
			Result = AddDelegateInstance(DelegateInstance->CreateCopy()); // CRASH HERE !!!
		}

		return Result;
	}

```

At least

```auto

.AddUObject

```

compiles…

Other variants:

```auto

.AddDynamic

```

yields the compiler error: /TeamPlayerController.cpp:100:45: no member named ‘\_\_Internal\_AddDynamic’ in ‘TMulticastDelegate’

```auto

.AddRaw

```

yields: /Engine/Source/Runtime/Core/Public/Delegates/DelegateInstancesImpl\_Variadics.inl:411:2: error: static\_assert failed “You cannot use raw method delegates with UObjects.”

```auto

.AddSP

```

yields: /Engine/Source/Runtime/Core/Public/Delegates/DelegateSignatureImpl\_Variadics.inl:155:64: error: no member named ‘AsShared’ in ‘ATeamPlayerController’

I suppose you can see that I’m rather unexperienced with delegates.  
Am I binding at the wrong point? In the wrong class?  
Probably it doesn’t matter which FSimpleMulticastDelegate from FCoreUObjectDelegates I take (tested

```auto

.AddUObject

```

with FCoreUObjectDelegates::PostLoadMap which results in the same crash).

So, obviously I’m doing something completely wrong. Just, what is it?

EDIT:  
Tried _.AddUObject_ in the exec command only. So I call:

1. exec command to bind to PostDemoPlay
2. demoplay test

The problem I guess is that _demoplay_ will call _UEngine::LoadMap_ which will destroy the player controllers and with them my bound functions…

Where would I then hook up the delegate binding? LocalPlayer?

EDIT2:  
Okay, I successfully bound to PostDemoPlay by subclassing ULocalPlayer and using

```auto

void UMyLocalPlayer::PostInitProperties()
{
    Super::PostInitProperties();
    
    FCoreUObjectDelegates::PostDemoPlay.AddUObject(this, &UMyLocalPlayer::DemoStarted);
}

```

which works great. Problem now is, I’d like to spawn another PlayerController. But in the demo it uses PendingPlayerControllerClass… Ui, I guess this is another story : /
