Hi all,
I’m making an android/mobile game that relies heavily on procedural meshes using the ProceduralMeshComponent. The problem is that collision isn’t working for mobile. From what I can gather this is for performance reasons (or legal reasons with the libs?) however I still want to test it for myself. All the searches I have made seems to point me to outdated discussions as most of them seem to say that physics cooking doesn’t work flat out, however some time ago it was made to work with some platforms I believe (and my game does indeed work as expected when compiling and running a Win64 build) but not mobile.
It appears to have something to do with the WITH_RUNTIME_PHYSICS_COOKING define (which isn’t defined/true on mobile), though I’m not sure what libraries and stuff that also goes with it. I’ve also read that adding this line would help:
UEBuildConfiguration.bRuntimePhysicsCooking = true;
But I’m not sure where to add it. I’ve added it to my “.Build.cs” file, within the constructor, but it doesn’t appear to do anything.
So my question is, how do I make it work? Without procedural collision the only other way I can think of (which is extremely cumbersome) is to create a bunch of collision primitives and position/scale them correctly as well as doing some extra complicated math…
Edit 1
I’ve made minor progress but it’s still not working. I believe I’ve been able to succesfully build an apk and deploy with the PhysX cooking library compiled in, however I still cannot figure out how to get WITH_RUNTIME_PHYSICS_COOKING to work. I edited PhysX.Build.cs on line 248 and uncommented the “PhysX3Cooking” static library for Android. Then it complained about a missing library file, since because the libPhysX3PROFILE.a file is missing from Engine\Source\ThirdParty\PhysX\PhysX-3.3\lib\Android* (presumably because it isn’t used). I had to pull down the full UE4 source from Github and recompile it to get those library files. After that it worked.
Except WITH_RUNTIME_PHYSICS_COOKING is still undefined. Looking at the source, it is defined if an UEBuildConfiguration.bRuntimePhysicsCooking = true is encountered, however I put it in my .Target.cs (following the instructions/example from the docs), but whatever I put in my SetupGlobalEnvironment function doesn’t appear to do anything at all (I’ve tried other options just to try and get some result). My SetupGlobalEnvironment currently looks like this:
public override void SetupGlobalEnvironment(
TargetInfo Target,
ref LinkEnvironmentConfiguration OutLinkEnvironmentConfiguration,
ref CPPEnvironmentConfiguration OutCPPEnvironmentConfiguration
)
{
UEBuildConfiguration.bCompilePhysX = true;
UEBuildConfiguration.bRuntimePhysicsCooking = true;
OutCPPEnvironmentConfiguration.Definitions.Add("WITH_RUNTIME_PHYSICS_COOKING=1");
}
I noticed that in the full source there is also an UEBuildAndroid.cs which has an validate function that explicitely sets bRuntimePhysicsCooking = false, but I’m not sure if this occurs before or after my target file, or even at all. Any thoughts?
Edit 2
I’ve actually managed to get it work! Incredible. Still needs further investigation, and I’m not sure about the performance or if it works on all devices (it works on my Nvidia Shield, running at capped 60 fps). The steps to make it work were:
- Clone the full UE4 source from Github (the latest at the time was 4.11 but I used 4.10 during the first experiments, not sure if this matters)
- (After fetching prerequisities and generating project files) uncomment line 274 in Engine\Source\ThirdParty\PhysX\PhysX.Build.cs (“PhysX3Cooking{0}”)
- Set the bRuntimePhysicsCooking on line 56 in Engine\Source\Programs\UnrealBuildTool\Android\UEBuildAndroid.cs to true
- Edit/Add SetupGlobalEnviron your .Target.cs project file to also set the variables. Mine looks like this:
public override void SetupGlobalEnvironment(
TargetInfo Target,
ref LinkEnvironmentConfiguration OutLinkEnvironmentConfiguration,
ref CPPEnvironmentConfiguration OutCPPEnvironmentConfiguration
)
{
UEBuildConfiguration.bCompilePhysX = true;
UEBuildConfiguration.bRuntimePhysicsCooking = true;
OutCPPEnvironmentConfiguration.Definitions.Add("WITH_RUNTIME_PHYSICS_COOKING=1");
}
- Fully build engine and launch project
- Package to APK
I’m not sure if every step is necessary but at least that is what works. Interestingly enough, the game wouldn’t build (for Android, didn’t test others) when just adding the <game>.Target.cs edits, even when forcing them to false. It complained about “file not found” for IPhysXFormat.h (a physx cooking header).
So far I’ve only made minor checks to see if it works (generated proc meshes successfully triggers touch events when collision is built. Will update if anything major progress is made.