Get a reference of a Mesh from Editor to C++ Code

Hi guys, I am new and am going though the video tutorials. In the LevelCreation tutorials there is a blueprint that implements an Auto-sliding Door with a box trigger. I was wondering how can I do that with C++ code only. I am comming from Unity and I was wondering, how I can get the reference of the door from the editor and give it to the C++ code directly (By drag and dropping - just like in Unity). This is a feature that I like very much in Unity and I was wondering if it is possible in Unreal. If it is not, can you tell me how I can get a reference to the door?

What exacly you mean by the door? Blueprint or Mesh etc.

The door is a static mesh. I want to take a reference of the door in the C++. I am actually confused a little. The door is a static mesh or and actor with a static mesh component? I just want to take a reference of the door that is currently in the Scene.

#ActorIterator

you’re better off giving your Door Actor a specific name via the F4 menu and then looking it up in C++ using the ActorIterator

in an AActor extending class

AStaticMeshActor* AMyActorExtendingClass::GetMyDoor()
{
  for(TActorIterator<AStaticMeshActor> Itr(()); Itr; ++Itr)
  {
   if(Itr->GetName() == YourDoorName)
   {
    return *Itr;
   }
 }
}

Enjoy!

This works. Thanks very much mate. Unfortunately now there is performance issue. I mean, I have a lot of static meshes in the scene. Is there a faster way to do it?

Actually I found a way. I Simply made an AStaticMeshActor* property with EditAnywhere flag. Now it is visible in the Editor and I Drag and Dropped the static mesh into the property.

I am trying to do something similar. I have two BPs with a mesh as one component and I want to set the my TSubclassOf<class AActor> WhatToSpawn; variable according to the variables set during runtime.

The goal is to simply be able to spawn different actors based on how many, the sizes, maps, what instantiated the spawning etc. Any tips?

I was hoping we could reference something by name or relative path, but I couldn’t find anything.

Thanks in advance.

If you already have the object in the level, you have to interact between the actors.
If you want to spawn and manage it from code, do something like this in the constructor:

//Declaration in .h file
UPROPERTY()
class UTexture2D* BarFillTexture;

//in .cpp constructor
static ConstructorHelpers::FObjectFinder<UTexture2D> BarFillObj(TEXT("/Game/UI/HUD/BarFill"));
BarFillTexture = BarFillObj.Object;

This applies to Textures (as in the example) as well as Meshes and other stuffs.

1 Like