I have a class definition as such:

class HORROR1_API UMyComplexObjectTest : public UObject


    UMyComplexObjectTest(int32 x, int32 y);

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyComplexTest")
    int32 row = 3;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyComplexTest")
    int32 col = 3;

    void setRow(int val);

And I am trying to create an instance of it in another class via :

UMyComplexObjectTest test1 = UMyComplexObjectTest();

This results in me getting the error :

Error   C2248   'UMyComplexObjectTest::UMyComplexObjectTest': cannot access private member declared in class 'UMyComplexObjectTest' Horror1 C:\Users\dogan\Documents\Unreal Projects\Horror1\Source\Horror1\Private\MazeGeneratorC.cpp  41

I am wondering if anyone can help me identify, why my constructor is still private under this circumstances. Thanks in advance!


1 Answer 1


I believe that the reason you're getting this error is because UE4 has stylized C++, if you go to "MyComplexObjectTest.generated.h" you can find the constructor declared as private in there. If you wanna create an object you need to use NewObject(outer), in this case that would be:

itemPtr = NewObject<UMyComplexObjectTest>(outer);

I recommend you research more about the subject because C++ programming tends to be quite different when doing it in UE4. Hope this helps :)

(I will leave the link I used for clarification maybe it will also help: https://stackoverflow.com/questions/58235175/create-uobject-from-another-class-with-constructor#58257876 )


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .