Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Can't access public constructor

I'm creating a plugin for Unreal with a BlueprintFunctionLibrary. Since I don't want to have functions that are too long, I want to delegate the different tasks to different classes according to OOD. I'm rather new to C++, so this might be a stupid question. So I've created this class which holds some positions with methods to get them : I've created the class with Unreals ClassWizard and made it private. However I want the constructor to be public so i can create an instance of it inside my BPFunction.

 class UTracePosition : public UObject
         FVector start;
         FVector end;
         FVector Forward;
         USceneComponent* arrow = nullptr;
         UTracePosition::UTracePosition(USceneComponent* Arrow);
         FVector getForwardVector()
             return Forward;
         FVector getStart() 
             return start;
         FVector getEnd() {
             return end;

And here's the .cpp

 #include "TracePosition.h"
 UTracePosition::UTracePosition(USceneComponent* Arrow)
     arrow = Arrow;
     start = arrow->GetComponentTransform().GetLocation();
     end = arrow->GetComponentTransform().GetLocation();
     start.Z += 20.0f;
     end.Z -= 20.0f;
     Forward = arrow->GetForwardVector();

When I try to create an instance of this class inside my BPFunction it says the constructor is inacessable. Another error says "'{ctor}': illegal qualified name in member declaration" in UTracePosition::UTracePosition(USceneComponent* Arrow);

 UTracePosition pos = UTracePosition(Arrow);

What's the mistake here?

Product Version: UE 4.17
more ▼

asked Nov 12 '17 at 01:17 PM in C++ Programming

avatar image

17 4 6 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Might be easier to just use a struct to hold that data instead:

 struct FTracePosition
     FTracePosition() {}
     FTracePosition(const FVector& InStart, const FVector& InEnd, const FVector& InForward, USceneComponent* InArrow)
         Start = InStart;
         End = InEnd;
         Forward = InForward;
         Arrow = InArrow;
     FVector GetForwardVector() { return Forward; }
     FVector GetStart() { return Start; }
     FVector GetEnd() { return End; }
     FVector Start;
     FVector End;
     FVector Forward;
     USceneComponent* Arrow;

Then you can use FTracePosition NewTrace = FTracePosition(Variables In Here); and not have to deal with creating a pointer reference or using the 'new' keyword to create a class instance.

more ▼

answered Nov 13 '17 at 05:17 PM

avatar image

1.9k 52 40 200

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I am not sure about the UE4 classes, some enforce use of SNew or the like.

For normal C++ there are two ways to use a class. As normal variable on the stack or create it with "new" on the heap and point to it with a pointer.

 class A
 int main(int nArgCount, char* pSzArgs[])
    A a;
    A* pA = new A;
    return 0;

In your case that would be:

 UTracePosition pos(Arrow);


 UTracePosition* pPos = new UTracePosition(Arrow);

Like I said, I don't know if you need to use something different than new or if UE4 prohibits you to create an UObject on the stack. They have a lot of rules you have to know, there is no way to guess it. Sorry. Perhaps someone with more knowledge about UE4 can help, if this is not working for you.

more ▼

answered Nov 13 '17 at 08:43 AM

avatar image

210 9 14 20

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question