I have a Plugin created in C++, when adding my class to a blue print, I do not see the class under the variable type so I cannot create an array of the class elements to assign a value to

While my original problem is complex, I can repro the issue with a simple plugin I created. I created a plugin that will allow me to create a simple racing track, with two straights side by side and simple round semi-circles at the end of each straight to connect the loops.

The OvalTrack.h header looks like this (if I forgot something)

#pragma once

#include “CoreMinimal.h”
#include “GameFramework/Actor.h”
#include “Components/SplineComponent.h”
#include “OvalTrack.generated.h”

UCLASS(BlueprintType, Blueprintable)
class OVALTRACKGENERATOR_API AOvalTrack : public AActor
{
GENERATED_BODY()

public:
AOvalTrack();

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Track")
float StraightLength;

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Track")
float TrackWidth;

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Track")
float RoundedEndRadius;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Track")
USplineComponent* SplineComponent;

virtual void OnConstruction(const FTransform& Transform) override;

};

And the cpp file looks like this

#include “OvalTrack.h”
#include “Components/SplineComponent.h”

AOvalTrack::AOvalTrack()
{
// Do Something
}

void AOvalTrack::OnConstruction(const FTransform& Transform)
{

// Do something

}

The plugin compiles fine. The issue is that when I pick the class to create a basic blueprint from it, I then create a variable that will hold all the 3 elements that will define the track, but when I try to set the variable type, I cant find the AOvalTrack class in this case so I am unable to create an array that will have the elements that I can assign the track length, radius and width parameters.

I have

  1. Make sure your class has the UCLASS(BlueprintType, Blueprintable) macro. This tells Unreal Engine that the class can be used in Blueprints.
  2. Ensure your class has the correct API export macro, which should be the same as your plugin’s API macro, e.g., OVALTRACK_API or TRACKGENERATORPLUGIN_API, depending on your project and plugin names.
  3. Rebuild your project and plugin. You may need to delete the “Intermediate” and “Saved” folders, regenerate the Visual Studio project files, and then clean and build your project in Visual Studio.
  4. Restart the Unreal Editor after rebuilding to ensure the changes are detected.
  5. In the Content Browser, right-click and choose “Create Basic Asset” > “Blueprint Class.”

I also have

  1. Make sure that the OvalTrackGenerator.uplugin file has the "Type": "Runtime" setting in the “Modules” section. This ensures the plugin is loaded during runtime, which is required for the class to be exposed to Blueprints.
  2. Double-check the plugin is enabled in the Unreal Engine Editor by going to Edit > Plugins and searching for “OvalTrackGenerator”. If it is not enabled, enable it and restart the editor.
  3. Make sure that the project was compiled successfully after making changes to the code. This is important for the updated class information to be recognized by the editor.

Finally I have made sure that I did

	○ Open the "OvalTrack.Build.cs" file in a text editor.
	○ Add the following lines to the PublicDependencyModuleNames list:
	
	"CoreUObject",
	"Engine",
	"Slate",
	"SlateCore",
	"Kismet"

So I am out of ideas why I can’t set the correct class as the type of the variable that will let me assign values to my blueprint

1 Like

Hi dlpass1,

what about “OvalTrack” rather than “AOvalTrack” - in Blueprint the A is stripped…

When I use the search feature of the Variable Type, the only entry close to the name that I can see is a “Oval Track” entry, but even if I try using that one, its list of elements is empty when I convert it into an Array, so I still think I am missing something.

Try changing the “GENERATED_BODY()” to “GENERATED_UCLASS_BODY()” (the former is for USTRUCTS)

Unluckily that did not resolve the issue, I still can’t see the elements of the class when I try to add the class as the type of the variable. Maybe I am doing that incorrectly.

Here is what I do:

This is a super easy repro that anyone can try to see what I am doing wrong.

  1. Open Unreal 5 (or 5.1)
  2. Create a new Unreal Project As GAMES->Blank and choose C++ as the Project Default.
  3. go to Edit->Plugins to create a new Plugin
  4. Click on the Add button and select a Blank Plugin and name it (I just called this one OvalTrackPlugin) and Create it.
  5. Once its done, close the Unreal Engine.
  6. Go to your plugin private folder (in my case it was D:\Users\Carlos\Documents\Unreal Projects\OvalTrackProject\Plugins\OvalTrackPlugin\Source\OvalTrackPlugin\Private)
  7. Create two files, name them OvalTrack.h and OvalTrack.cpp, and copy the respective code above in the thread to the correct file.
  8. Double click on the .sln file to open the project in your development/compiler program, I use Visual Studio Community.
  9. Make sure that the .Build.cs file has the PublicDependecyModuleNames mentioned above in the thread, if not add the missing ones.
  10. Compile your code.
  11. Open Unreal Engine again
  12. Create the blueprint.
    1. I “Create Basic asset”->Blueprint Class
    2. I search for the Actor->OvalTrack and select it
    3. I open the blueprint and create a Variable
    4. Under Details I select the pulldown for “Variable Type” and search for
      AOvalTrack
      OvalTrack
      Oval Track
    5. Only find “Oval Track” and “Oval Track Project Game Mode Base”
    6. I try them both by themselves or one of the next 4 options that they can expand to
      Object Reference
      Class Reference
      Soft Object Reference
      Soft Class Reference
  13. I then select Array from the second pull down
  14. I go ahead and click the Compile button (othjerwise I can’t add Array Elements)
  15. I add an element, but the pulldown is disabled (e.g. I got no elements from the class)

So… what am I missing, how can I get those elements to show so I can add the settings to my Variable’s array?

The reason you’re seeing that greyed out is because you’ve set up a list of “References” to the OvalTrack Actor - You’ll need to “Instantiate” those objects at runtime first, or reference actors in your level.

It is exposing your data correctly in Blueprint though:

Interesting, as you can tell I am brand new to Unreal :slightly_smiling_face:, I will give it a shot. Stupid question, what did you choose as the variable type?

Just the “Reference to Oval Track”:

image

Note that to create and edit references from your level, you do that from an instance of your blueprint in the level.

trying to edit them from the blueprint editor has this error:
image
which makes sense as there are no “instances” without a level.

When you add your blueprint in your level, you can add them there (assuming you’ve added some OvalTrack Actors to your level) in the details window:

image

The other option is to create the OvalTrack actors in your constructor (in C++, just have “SpawnParams.bAllowDuringConstructionScript=true;” in your Spawn code)

Awesome, give me a day or two to test to answer this one as complete.

1 Like