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"

C++ - Extending and Initializing UObjects.

Hello everyone.

I created a third person template project (C++), added a few classes, and I'm now trying to call a function of one of these newly added classes. I can call that function NP through C++ IF the class do not extend UObject. If it does, UE simply crashes when the function is called. I need it to extend UObject because I need to retrieve some variables, as well as execute some functions, from blueprints.

The error I'm getting when hitting the function while its holding class is a child of UObject: http://puu.sh/oAFag/198a3e5465.png

The function triggering the UE4 crash when called while its class extends UObject:

 UNetworkConnection& UNetworkConnection::GetLoginInstance()
     static UNetworkConnection instance(new ULoginPacketHandler());
     return instance;

It likely is something pretty simple yet I can't seem to figure it out. Been trying on and off for a few days but being new to both Unreal and C++, I'm struggling.

Please help!

Product Version: UE 4.11
more ▼

asked May 01 '16 at 03:30 PM in C++ Programming

avatar image

3 2 3

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

1 answer: sort voted first

If you get crash, check logs in Saved/Logs it should also apper in output tab... because you error is very simple and engine should inform you :p

You can't use "new" on UObject, they have diffrent creation process, to instatiate UObject use this insted:

 static UNetworkConnection instance(NewObject<ULoginPacketHandler>());

You also should not use delete on UObject, you can only use those on non-UObject and non-reflected objects

more ▼

answered May 01 '16 at 04:00 PM

avatar image

37.3k 936 172 1117

avatar image CallMeMax May 01 '16 at 08:23 PM

Thanks for the answer, that was it!

(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