Hello, I have a DDM(DialogueDataManager) class and BP_DDM(DDM class based).
Here is how they are.
DDM.h
UFUNCTION(BlueprintNativeEvent)
void SelectDialogueName();
void SelectDialogueName_Implementation();
DDM.cpp
void UDialogueDataManager::SelectDialogueName_Implementation()
{
UE_LOG(LogTemp, Warning, TEXT("bonita"));
}
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++
I may missing something fundamental. Any point out would be appreciated. Thanks in advance!
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.
3dRaven
(3dRaven)
July 1, 2024, 2:25pm
3
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:
UFUNCTION(BlueprintNativeEvent,BlueprintCallable)
void SelectDialogueName();
virtual void SelectDialogueName_Implementation();
cpp can remain unchanged
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
UDialogueDataManager* DDM;
UPROPERTY(BlueprintReadWrite)
TSubclassOf<UDialogueDataManager> DDMClass;
UFUNCTION(BlueprintCallable)
void ConstructDDM();
MyUserWidget.cpp
void UMyUserWidget::ConstructDDM()
{
DDM = NewObject<UDialogueDataManager>(DDMClass);
DDM->SelectDialogueName();
}
BP_MyUserWidget(MyUserWidget based)
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.
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”
3dRaven
(3dRaven)
July 2, 2024, 7:44am
5
Data manager
.h => just needed function
UFUNCTION(BlueprintNativeEvent,BlueprintCallable)
void SelectDialogueName();
virtual void SelectDialogueName_Implementation();
.cpp
void UDialogueDataManager::SelectDialogueName_Implementation()
{
GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Orange, TEXT("SelectDialogueName called from C++"));
}
my user widget
.h
// 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
#include "MyUserWidget.h"
void UMyUserWidget::ConstructDDM()
{
DDM = NewObject<UDialogueDataManager>(DDMClass);
DDM->SelectDialogueName();
}
UDialogueDataManager* UMyUserWidget::GetDDM()
{
return DDM;
}
When BP does not override function
Then override
Adding the function call action
If you want to call c++ even then the blueprint override is present just “Add call to parent function” (right click on overridable event)
Both calls
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
UCLASS(Blueprintable)
class MYPROJECT_API UDialogueDataManager : public UObject
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
void SelectDialogueName();
virtual void SelectDialogueName_Implementation();
};
DDM.cpp
#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.
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.
3dRaven
(3dRaven)
July 2, 2024, 1:07pm
7
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.
1 Like
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.
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.
void UMyUserWidget::ConstructDDM()
{
DDM = NewObject<UDialogueDataManager>(this, DDMClass);
DDM->SelectDialogueName();
}
1 Like
Solved! Thank you so much all of you. Arigato!
system
(system)
Closed
August 2, 2024, 6:16am
10
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.