# Trying to call function from C++ which overrided in Blueprint.

**URL:** <https://forums.unrealengine.com/t/trying-to-call-function-from-c-which-overrided-in-blueprint/1922738>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [July 1, 2024, 1:01pm UTC](https://forums.unrealengine.com/t/trying-to-call-function-from-c-which-overrided-in-blueprint/1922738 "2024-07-01T13:01:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebrebzzeeere](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ebrebzzeeere](https://forums.unrealengine.com/u/ebrebzzeeere)\
**Post date:** [July 1, 2024, 1:01pm UTC](https://forums.unrealengine.com/t/trying-to-call-function-from-c-which-overrided-in-blueprint/1922738/1 "2024-07-01T13:01:30Z")

</div>

Hello, I have a DDM(DialogueDataManager) class and BP\_DDM(DDM class based).  
Here is how they are.

DDM.h

```auto
	UFUNCTION(BlueprintNativeEvent)
	void SelectDialogueName();
	void SelectDialogueName_Implementation();

```

DDM.cpp

```auto
void UDialogueDataManager::SelectDialogueName_Implementation()
{
	UE_LOG(LogTemp, Warning, TEXT("bonita"));
}

```

 ![Screenshot 2024-07-01 214753](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/1/c/21c8ae59c870d1148b1eb7a6407a3063a3ba2c86.png)

Everytime I call SelectDialogueName() in C++, I get out put “LogTemp: Warning: bonita”. But it should be “LogTemp: Warning: Hello”.

I mean this answer doesn’t work for this case.  
[Call Blueprint functions from C++](https://forums.unrealengine.com/t/call-blueprint-functions-from-c/296119/3)

I may missing something fundamental. Any point out would be appreciated. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![gh0stfase1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/gh0stfase1/32/1194639_2.png) [@gh0stfase1](https://forums.unrealengine.com/u/gh0stfase1)\
**Post date:** [July 1, 2024, 2:14pm UTC](https://forums.unrealengine.com/t/trying-to-call-function-from-c-which-overrided-in-blueprint/1922738/2 "2024-07-01T14:14:06Z")

</div>

On the surface, everything looks as it should. That said, remove your declaration of the \_Implementation method. The UFUNCTION macro does that for you so declaring it yourself might be messing something up. Also make sure you’re not doing any sort of live coding. Make your change, build then bring the editor up.

Beyond that, I don’t see anything out of the ordinary.

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [July 1, 2024, 2:25pm UTC](https://forums.unrealengine.com/t/trying-to-call-function-from-c-which-overrided-in-blueprint/1922738/3 "2024-07-01T14:25:47Z")

</div>

> [@ebrebzzeeere](#):
>
> ```auto
> void UDialogueDataManager::SelectDialogueName_Implementation()
> {
> UE_LOG(LogTemp, Warning, TEXT("bonita"));
> }
> 
> ```

The function \_Implementation needs to be `virtual` so that it can be overriden via blueprints.  
That way once implemented in bp you will only get “Hello”

in header:

```auto
	UFUNCTION(BlueprintNativeEvent,BlueprintCallable)
	void SelectDialogueName();
	virtual void SelectDialogueName_Implementation();

```

cpp can remain unchanged

---

<div class="post-metadata">

**Author:** ![ebrebzzeeere](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ebrebzzeeere](https://forums.unrealengine.com/u/ebrebzzeeere)\
**Post date:** [July 2, 2024, 1:54am UTC](https://forums.unrealengine.com/t/trying-to-call-function-from-c-which-overrided-in-blueprint/1922738/4 "2024-07-02T01:54:23Z")

</div>

Thank you for sending reply.  
I tried delete declaration of the \_Implementation method and make it virtual did not resolve the problem.

Actually I call this function from another class MyUserWidget.

MyUserWidget.h

```auto
	UDialogueDataManager* DDM;

	UPROPERTY(BlueprintReadWrite)
	TSubclassOf<UDialogueDataManager> DDMClass;

	UFUNCTION(BlueprintCallable)
	void ConstructDDM();

```

MyUserWidget.cpp

```auto
void UMyUserWidget::ConstructDDM()
{
	DDM = NewObject<UDialogueDataManager>(DDMClass);
	DDM->SelectDialogueName();
}

```

BP\_MyUserWidget(MyUserWidget based)

 ![Screenshot 2024-07-02 103709](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/6/f/66fa0451756b8b5058357f9a2479c6359e1cd434.png)  
 ![Screenshot 2024-07-02 103730](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/8/b/d8b1ce0a7451ca7dc252b098eb24d7ecf4925c8e.png)

I think the problem is the data type of UDialogueDataManager\* DDM.  
Constructing with DDMClass surely, but the actual data type could be UDialogueDataManager\* not BP\_DialogueDataManager.

All I want to do is just call SelectDialogueName() or SelectDialogueName Event from BP\_MyUserWidget. I’m not persist to use C++ code, then I tried this.

 ![Screenshot 2024-07-02 104822](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/a/e/caedaf15dbd293e525d15c6053d70bcffa0cfa8b.png)  
 ![Screenshot 2024-07-02 104935](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/d/d/6dd7c0e23067260ce6aeee70812896f6de812758.png)

And I got error.

“Blueprint Runtime Error: “Accessed None trying to read property CallFunc\_SpawnObject\_ReturnValue”. Node: Select Dialogue Name Graph: EventGraph Function: Execute Ubergraph BP My User Widget Blueprint: BP\_MyUserWidget”

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [July 2, 2024, 7:44am UTC](https://forums.unrealengine.com/t/trying-to-call-function-from-c-which-overrided-in-blueprint/1922738/5 "2024-07-02T07:44:35Z")

</div>

![1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/2/4/6247ef94c2fd1cf527fe1aa4473032aefd15360f.png)

Data manager  
.h =\> just needed function

```auto
UFUNCTION(BlueprintNativeEvent,BlueprintCallable)
void SelectDialogueName();
virtual void SelectDialogueName_Implementation();

```

.cpp

```auto
void UDialogueDataManager::SelectDialogueName_Implementation()
{	
	GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Orange, TEXT("SelectDialogueName called from C++"));
}

```

my user widget  
.h

```auto
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "DialogueDataManager.h"
#include "MyUserWidget.generated.h"

/**
 * 
 */
UCLASS()
class YOUR_API UMyUserWidget : public UUserWidget
{
	GENERATED_BODY()

public:
	
	UPROPERTY(BlueprintReadWrite, EditAnywhere)
	TSubclassOf<UDialogueDataManager> DDMClass;

	UFUNCTION(BlueprintCallable)
	void ConstructDDM();

	UFUNCTION(BlueprintCallable)
	UDialogueDataManager* GetDDM();
	
private:
	UDialogueDataManager* DDM;	
};

```

.cpp

```auto

#include "MyUserWidget.h"

void UMyUserWidget::ConstructDDM()
{
	DDM = NewObject<UDialogueDataManager>(DDMClass);
	DDM->SelectDialogueName();
}

UDialogueDataManager* UMyUserWidget::GetDDM()
{	
	return DDM;
}

```

When BP does not override function  
 ![cpp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/a/b/3aba167563eba139b4d0f255bd5152993d8c70ee.png)

Then override  
 ![override](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/f/6/5f661ec47dd7840acb90964782f3caedb9cf2c3c.png)  
Adding the function call action  
 ![override2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/a/d/2ad32f2fbcc7386856bd536a855d343f9cb6dfa4.png)  
 ![overrideText](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/b/0/4b029c28e5690253522a6215dd53428c554d7320.png)

If you want to call c++ even then the blueprint override is present just “Add call to parent function” (right click on overridable event)  
 ![need cpp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/f/3/8f3460c5d9d52e76b5fb9b40896a1998c9ab4fdb.png)

 ![parent](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/d/afd46903ba4bc959ccb51d065a73436ae2fedafd.png)

Both calls  
 ![both](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/3/0/230e2176bbc181eaf3529d65cc62a245b13fefb8.png)

---

<div class="post-metadata">

**Author:** ![ebrebzzeeere](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ebrebzzeeere](https://forums.unrealengine.com/u/ebrebzzeeere)\
**Post date:** [July 2, 2024, 1:02pm UTC](https://forums.unrealengine.com/t/trying-to-call-function-from-c-which-overrided-in-blueprint/1922738/6 "2024-07-02T13:02:30Z")

</div>

I’m very impressed your kindness. Thank you again.  
I perfectly mimicked your codes and BPs, only I get “SelectDialogueName called from C++”.

Overriding function in BP may being fail?  
May DDM class have a problem potentially?

DDM.h

```auto
UCLASS(Blueprintable)
class MYPROJECT_API UDialogueDataManager : public UObject
{
	GENERATED_BODY()

public:

	UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
	void SelectDialogueName();
	virtual void SelectDialogueName_Implementation();
};

```

DDM.cpp

```auto
#include "DialogueDataManager.h"

void UDialogueDataManager::SelectDialogueName_Implementation()
{
	GetWorld();
	GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Orange, TEXT("SelectDialogueName called from C++"));
}

```

Can the property UCLASS(Blueprintable) or inheriting UObject be a problem?  
Now I have totally no idea, so I pointed out what I found.

I found World Context Object pin in PrintString node whitch your sample did not have.  
 ![Screenshot 2024-07-02 214639](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/1/a11ffb2e24967e66072c1ecd3d529b53956cc7d8.png)  
So I pinned a variable whitch is current Level. But that was not the matter.

I wanted to place these specific functions outside of MyUserWidget, if I place them in MyUserWidget this problem cannot be exist though.

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [July 2, 2024, 1:07pm UTC](https://forums.unrealengine.com/t/trying-to-call-function-from-c-which-overrided-in-blueprint/1922738/7 "2024-07-02T13:07:57Z")

</div>

Ok so seeing that UDialogueDataManager extends UObject changes the situation bit. I will try to rework the solution to work within the confines of the base class UObject.

---

<div class="post-metadata">

**Author:** ![GarnerP57](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GarnerP57](https://forums.unrealengine.com/u/GarnerP57)\
**Post date:** [July 2, 2024, 2:30pm UTC](https://forums.unrealengine.com/t/trying-to-call-function-from-c-which-overrided-in-blueprint/1922738/8 "2024-07-02T14:30:02Z")

</div>

Here you are creating the C++ variant not the subclass (Blueprint class). You are only using the DDMClass as the Outer class for the DDM lifetime.

```auto
void UMyUserWidget::ConstructDDM()
{
	DDM = NewObject<UDialogueDataManager>(DDMClass);
	DDM->SelectDialogueName();
}

```

You need at least 2 parameters where the second parameter is the class you want to spawn. The first might be `this` or something else that determines its lifetime.

```auto
void UMyUserWidget::ConstructDDM()
{
	DDM = NewObject<UDialogueDataManager>(this, DDMClass);
	DDM->SelectDialogueName();
}

```

---

<div class="post-metadata">

**Author:** ![ebrebzzeeere](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ebrebzzeeere](https://forums.unrealengine.com/u/ebrebzzeeere)\
**Post date:** [July 3, 2024, 6:15am UTC](https://forums.unrealengine.com/t/trying-to-call-function-from-c-which-overrided-in-blueprint/1922738/9 "2024-07-03T06:15:57Z")

</div>

Solved! Thank you so much all of you. Arigato!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [August 2, 2024, 6:16am UTC](https://forums.unrealengine.com/t/trying-to-call-function-from-c-which-overrided-in-blueprint/1922738/10 "2024-08-02T06:16:38Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
