Open boristsr opened 5 years ago
I've been unable to solve this issue. It seems to be with any class that using the Subclassing API. Any blueprint or C++ class used as a parent to a python class causes this cooking error for me.
I have worked around it by refactoring my code so that I have implemented the CustomProceduralMesh in C++, and the actors that then showed similar problems I've changed to using the PyActor method.
We ran into something similar in our project. Below are a few things to try - they are not official fixes, are kinda hacky, and may not work for you, but might be worth a shot (they worked for us).
(1) There's a chance that the problem is specific to cooking and won't happen once your project is fully packaged, and depending on how you're using Python in your project, there might not really be a need for your Python classes to be invoked during cooking. So one option is to simply not import your classes during cooking.
In our project, for example, we have our build script set an environment variable like 'BUILD_IS_UNDERWAY=1' and then our ue_site.py has something like:
import os
if os.environ.get('BUILD_IS_UNDERWAY') == '1': # note that it's a string not an int here
pass # do nothing, since the build is underway (maybe log a message so you know what's happening)
else:
# otherwise, proceed with importing your classes
(2) If the above gets you through cooking, but the problem still happens when you run the packaged game, it might be that simply delaying your import a little longer will do the trick. Continuing in ue_site.py you could do something like:
def FinishInit():
pass # this is where you import your py classes
import os
if os.environ.get('BUILD_IS_UNDERWAY') == '1': # note that it's a string not an int here
pass # or log a message
else:
def CallFinishInit(*args):
ue.create_and_dispatch_when_ready(FinishInit)
import threading
t = threading.Thread(target=CallFinishInit)
t.daemon = True
t.start()
The above asks the engine to call FinishInit once it is more ready (the background thread is to work around some problem where I think it detects we're already on the game thread, so it refuses to wait - so we introduce a thread just so the call happens from another thread, and that is enough to make it wait to call our code back).
If this works, then one modification you'll want to make is to make it so that you do the thread-based call to FinishInit only if you are running a packaged build. If you are running in the editor, then you really want to just call FinishInit() right away instead of starting a thread. So if the above works, lemme know and I can help you with that.
(3) There's a good chance that one of the above options will work. If neither work, however, then a more invasive workaround is to temporarily override the engine global variable GIsInitialLoad
while creating your class default object. This requires modifying UnrealEnginePython, so I won't go into details unless you need them, but basically you change things so that when creating the CDO for any Python classes, you save the current value of GIsInitialLoad, set it to false, call Super::CreateDefaultObject(), and then restore GIsInitialLoad to its saved value. This feels gross and hacky... but it worked for us. :)
Maybe one of the project devs will chime in with better advice too!
from unreal_engine.classes import ProceduralMeshComponent, KismetProceduralMeshLibrary
but it shows NameError: name 'UKismetProceduralMeshLibrary' is not defined, seems that unreal_engine.classes doesn't have KismetProceduralMeshLibrary, how can I use this class?
On the main readme.md check out the section called Referencing Objects, it has a sample like below which might work for you.
texture_class = ue.find_class('Texture2D')
a_specific_texture = ue.load_object(texture_class, '/Game/Textures/logo2')
I am having problems when cooking. The project is very barebones. Things work as expected in the editor, however when cooking I get this error:
Full error log:
The code for CustomProceduralMeshComponent looks like this:
I've tried filling out my ue_site.py to no avail. Currently it looks like this:
Any help would be much appreciated. Thanks.