Download

Can't instantiate C++ class within Blueprint

Trying to create an instance of a C++ class within Blueprint using Create Object from Class. The C++ class is derived from Actor, and I’ve added in Blueprintable and BlueprintType incantations in the C++ header. When I compile the Blueprint level, it fails with a “cannot construct objects of type…” Google suggested the need for the BlueprintType declaration, but I could’nt find anything else.
Any help would be appreciated.

A cut & paste of part of the C++ header is below, plus an uploaded screenshot of the Blueprint page

#pragma once

#include “CoreMinimal.h”
#include “GameFramework/Actor.h”
#include “RCButtonActor.generated.h”

UCLASS(Blueprintable, BlueprintType)
class MVH_BLANK1_API ARCButtonActor : public AActor
{
GENERATED_BODY()

public:
// Sets default values for this actor’s properties
ARCButtonActor();

…etc

if its a custom c++ actor class you created, the blueprint wont understand what you wrote, it only understands AActor that unreal has so whatever members and functions. In order to TELL a blue print (a blueprint that is not based off your custom actor class, like some random UI widget or a different actor class ) you have to CAST the AActor to your MYActor class before you can access any of its public members or functions.

And of course if you created the blueprint OFF your c++ actor class, it will obviously have full access to whatever members or functions right away.

Video example: https://www.youtube.com/watch?v=-CybtvNa2Ng at 9min mark

[Edit] Looks like for constructors you dont need to do any casting, blueprint should be able to see all available classes that are marked (BlueprintType)
Also if your class is an actor, I think you need to use spawn actor not create object.

I am a bit of a beginner, so I’m probably missing something really obvious here.
I created a new Blueprint class, which I’ve called CodeTestHander, I’ve derived it from my C++ class (RCButtonActor). However when I try to create an instance of this new Blueprint class using Construct Object from Class, and try to compile it in the Blueprint level, it fails in exactly the same way :- Cannot construct objects of type…

Sorry did’nt read the last bit of @ViperG’s post about using Spawn Actor from Class, not Create Object from Class. Now compiles OK, many thanks.