Unreal.js
Unreal.js copied to clipboard
CreateDefaultSubobject must be called within ctor
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
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.
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.
Looks like this code was changed 6 months ago in a big merge from commit 44dfabd4e9cef12fa15c8007b849020b7a7687d2
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
I tried prector ()
and it crashed.
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.
I will dive in to this as well thanks @thejustinwalsh for your input. Do you have any luck running this in 4.25?
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:
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.