# Store a list of function

**URL:** <https://forums.unrealengine.com/t/store-a-list-of-function/487176>\
**Category:** C++\
**Tags:** unreal-engine, delegates, pointer, CPP, question\
**Created:** [August 8, 2021, 12:18am UTC](https://forums.unrealengine.com/t/store-a-list-of-function/487176 "2021-08-08T00:18:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LightCanadian](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LightCanadian](https://forums.unrealengine.com/u/LightCanadian)\
**Post date:** [August 8, 2021, 12:18am UTC](https://forums.unrealengine.com/t/store-a-list-of-function/487176/1 "2021-08-08T00:18:46Z")

</div>

I am trying to create a parser that can call functions. I would like to store specific functions that can then be iterated through and call.  
To store my function, I created this class, however, I crash when I tried to add the function to my class:

```
DECLARE_DELEGATE_RetVal(FString, FFunction);

UCLASS()
class UParseFunction:public UObject
{
	GENERATED_BODY()
public:
	UParseFunction(){};	

	UPROPERTY()
	TArray<FName> PossibleStringName;

	//UPROPERTY()
	FFunction FunctionToCall;
};

```

Actor constructor:

> See edit

Also open to idea if you have other technics to call functions by text.

EDIT:  
After more testing, I had to make some changes but still get an error. I moved the construction in begin play since after reading the doc, during construction time the pointer to the function does not exist supposedly. Also, since i’m no longer in the constructor, I replaced the CreateDefaultSubObject() with NewObject()

Tester.cpp

```
void AParserTester::BeginPlay()
{
	Super::BeginPlay();

	auto obj = NewObject<UParseFunction>(this);
	
	if (obj)
	{
		UE_LOG(LogTemp,Warning,TEXT("[ParserTester] OBJ existe"))
		obj->PossibleStringName = { "Test", "test", "Test()" };
		obj->FunctionToCall.BindSP(this, &AParserTester::Test);//This line make me crash
		Functions.Add(obj);	
	}	
}

```

Tester.h:

```
UCLASS()
class THAGAME_API AParserTester : public AActor , public IParserObject, public TSharedFromThis<AParserTester>
{
	GENERATED_BODY()
public:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

	UFUNCTION()
	FString Test();
}

```

And now i get this error:

> Assertion failed: SharedThis.Get() == this [File:D:\Unreal\Engine\UE\_5.0EA\Engine\Source\Runtime\Core\Public\Templates/SharedPointer.h] [Line: 1329]

> UnrealEditor\_ThaGame\_0001!TSharedFromThis::AsShared() [D:\Unreal\Engine\UE\_5.0EA\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h:1329]  
> UnrealEditor\_ThaGame\_0001!TDelegate::CreateSP() [D:\Unreal\Engine\UE\_5.0EA\Engine\Source\Runtime\Core\Public\Delegates\DelegateSignatureImpl.inl:228]  
> UnrealEditor\_ThaGame\_0001!AParserTester::BeginPlay() [D:\Unreal\Project\UE5\ThaGame\Source\ThaGame\Parser\ParserTester.cpp:30]  
> UnrealEditor\_Engine

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [August 8, 2021, 10:06am UTC](https://forums.unrealengine.com/t/store-a-list-of-function/487176/2 "2021-08-08T10:06:12Z")

</div>

Hello! Can you provide error message?

---

<div class="post-metadata">

**Author:** ![LightCanadian](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LightCanadian](https://forums.unrealengine.com/u/LightCanadian)\
**Post date:** [August 8, 2021, 5:58pm UTC](https://forums.unrealengine.com/t/store-a-list-of-function/487176/3 "2021-08-08T17:58:18Z")

</div>

Assertion failed: SharedThis.Get() == this [File:D:\Unreal\Engine\UE\_5.0EA\Engine\Source\Runtime\Core\Public\Templates/SharedPointer.h] [Line: 1329]

UnrealEditor\_ThaGame\_0001!TSharedFromThis::AsShared() [D:\Unreal\Engine\UE\_5.0EA\Engine\Source\Runtime\Core\Public\Templates\SharedPointer.h:1329]  
UnrealEditor\_ThaGame\_0001!TDelegate::CreateSP() [D:\Unreal\Engine\UE\_5.0EA\Engine\Source\Runtime\Core\Public\Delegates\DelegateSignatureImpl.inl:228]  
UnrealEditor\_ThaGame\_0001!AParserTester::AParserTester() [D:\Unreal\Project\UE5\ThaGame\Source\ThaGame\Parser\ParserTester.cpp:16]  
UnrealEditor\_HotReload  
UnrealEditor\_HotReload  
UnrealEditor\_HotReload  
UnrealEditor\_HotReload  
UnrealEditor\_HotReload  
UnrealEditor\_HotReload  
UnrealEditor\_CoreUObject  
UnrealEditor\_CoreUObject  
UnrealEditor\_CoreUObject  
UnrealEditor\_Core  
UnrealEditor\_Core  
UnrealEditor\_Core  
UnrealEditor\_HotReload  
UnrealEditor\_HotReload  
UnrealEditor\_HotReload  
UnrealEditor\_Core  
UnrealEditor  
UnrealEditor  
UnrealEditor  
UnrealEditor  
UnrealEditor  
kernel32  
ntdll

---

<div class="post-metadata">

**Author:** ![LightCanadian](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LightCanadian](https://forums.unrealengine.com/u/LightCanadian)\
**Post date:** [August 9, 2021, 12:16am UTC](https://forums.unrealengine.com/t/store-a-list-of-function/487176/4 "2021-08-09T00:16:35Z")

</div>

I got it, I followed an example on how to create a Delegate and the example was using **BindSP()** to bind the function, after getting errors for that function, I inherited from **TSharedFromThis\<\>** after looking up the error on the net not knowing what it was used for.

After a lot of pain, I realized that **BindSP()** probably stands for Bind Shared Pointer(which I don’t know how to use)

I re-read the doc for delegates and saw that there were other way’s of binding, after changing **BindSP** for **BindUObject()** all the error were gone and it was working

```
obj->FunctionToCall.BindUObject(this, function);
```
