Unreal.js icon indicating copy to clipboard operation
Unreal.js copied to clipboard

CreateDefaultSubobject must be called within ctor

Open A-Paterson opened this issue 5 years ago • 9 comments

Hi,

I am new to the Unreal engine and Unreal.js. After copying the first person example on the wiki, I got this error:

CreateDefaultSubobject must be called within ctor

This was caused by:

let tempCamera = CameraComponent.CreateDefaultSubobject("FP_Camera")

It is inside the ctor function.

Thanks for any help, Alex

A-Paterson avatar Dec 20 '19 15:12 A-Paterson

I am looking at the same code and running into the same error. To me it looks like the code that was calling the ctor in Javascript got moved to // move to javascriptgeneratedclass_* according to some commented out code sitting in JacvascriptContext_private.cpp around line 761. From what I can tell prector() is being called when the ObjectInitializer is valid, and the ctor() function is being called after the object has already initialized. So unless that is a bug try creating your component in prector() instead.

thejustinwalsh avatar Mar 10 '20 05:03 thejustinwalsh

If I restore the code in JavascriptContext_private.cpp and comment out the call of the ctor() in JavascriptGeneratedClass.cpp all of my code that was working in 4.21 is now working in 4.23.

If I move all my CreateDefaultSubobject calls to prector() I get all kinds of fun invalid memory access crashes.

I think we have a bug on our hands, or a new pattern for calling CreateDefaultSubobject, that I do not see documented anywhere.

thejustinwalsh avatar Mar 10 '20 05:03 thejustinwalsh

Looks like this code was changed 6 months ago in a big merge from commit 44dfabd4e9cef12fa15c8007b849020b7a7687d2

thejustinwalsh avatar Mar 10 '20 05:03 thejustinwalsh

There are no examples in the repository that actually use CreateDefaultSubobject although the following wiki entries will all fail unless resolved:

https://github.com/ncsoft/Unreal.js/wiki/Creating-a-component https://github.com/ncsoft/Unreal.js/wiki/Android https://github.com/ncsoft/Unreal.js/wiki/Creating-a-custom-component https://github.com/ncsoft/Unreal.js/wiki/First-Person-Template-in-Unreal.js https://github.com/ncsoft/Unreal.js/wiki/Third-Person-Template-in-Unreal.js

thejustinwalsh avatar Mar 10 '20 15:03 thejustinwalsh

I tried prector () and it crashed.

A-Paterson avatar Mar 10 '20 17:03 A-Paterson

I can submit a PR but without any kind of tests I am not sure if it was intended to break this functionality in an attempt to enable something else.

thejustinwalsh avatar Mar 10 '20 23:03 thejustinwalsh

I will dive in to this as well thanks @thejustinwalsh for your input. Do you have any luck running this in 4.25?

Master244 avatar May 19 '20 12:05 Master244

I am avoiding 4.25 until the first point release. I was evaluating Unreal.js for a project I was working on but after giving it some thought, I think I won't be using Unreal.js and probably won't try to get it working in 4.25 at any point in time. :disappointed:

thejustinwalsh avatar May 19 '20 14:05 thejustinwalsh

If I restore the code in JavascriptContext_private.cpp and comment out the call of the ctor() in JavascriptGeneratedClass.cpp all of my code that was working in 4.21 is now working in 4.23. https://github.com/ncsoft/Unreal.js/issues/264#issuecomment-596912992

Thanks @thejustinwalsh I'm on UE 4.24.3 and this workaround seems effective, too.

j-devel avatar Dec 03 '20 10:12 j-devel