Get a reference to C++ actor #158
-
Hey community! Hoping someone can give guidance on this, was struggling to understand this from the documentation. I'm not sure if I'm misunderstanding something but I thought I'd be able to get a handle to Unreal instantiated native cpp actors using the UCLASS macro with Blueprintable + BlueprintType specifiers similar to how we get access BP actors, but when trying this doesn't seem to work. For instance, the cpp actors here returns null. Is this expected behaviour? I have a BP actor (created via editor using blueprint) and cpp create actor instantiated in my scene. I'm able to get a handle to the BP actor but I'm unable to get a handle to cpp actor. My aim is to be able to invoke a function on the cpp actor if possible. Currently the only way to do this is to invoke a function via the BP actor which seems a bit unnecessary to me. // cpp actor
#pragma once
#include "CoreMinimal.h"
#include "TestActor.generated.h"
UCLASS(BlueprintType, Blueprintable)
class ACppTestActor : public AActor
{
GENERATED_BODY()
public:
ATestActor(const FObjectInitializer& ObjectInitializer);
public:
void TestFunction();
}; // C# code
private static Actor BP_Actor; // Made as an editor BP actor
private static Actor CPP_TestActor; // Made as a cpp actor with UCLASS(BlueprintType, Blueprintable)
public static void OnWorldBegin()
{
BP_Actor= World.GetActor<Actor>("BP_Actor"); // Return Unreal.Framework.Actor type able invoke custom events as expected
TestActor = World.GetActor<Actor>("CPP_TestActor"); // Returns null
} Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Make sure that the name of the actor is correct, labels in the outliner are often misleading, it should work as long as actor is instantiated in the world. |
Beta Was this translation helpful? Give feedback.
-
Ah, thanks again @nxrighthere ! Indeed, the outliner misrepresented the ID name which had a "_1" appended to it. Hovering my mouse cursor over the label revealed this. All seems to work as it should now. I appreciate the response and help. Thanks for your work on this awesome tool! |
Beta Was this translation helpful? Give feedback.
Make sure that the name of the actor is correct, labels in the outliner are often misleading, it should work as long as actor is instantiated in the world.