Runtime Physics Cooking for mobile ?

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:

  1. 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)
  2. (After fetching prerequisities and generating project files) uncomment line 274 in Engine\Source\ThirdParty\PhysX\PhysX.Build.cs (“PhysX3Cooking{0}”)
  3. Set the bRuntimePhysicsCooking on line 56 in Engine\Source\Programs\UnrealBuildTool\Android\UEBuildAndroid.cs to true
  4. 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");
}

  1. Fully build engine and launch project
  2. 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.

Hi Master Kenth,

Only the libraries in the default configuration are built and included. Runtime cooking and APEX are not supported on mobile.

Hi ,

Thanks for taking your time to respond :). Too bad about it not being supported and hopefully it will be soon (I wasn’t sure as some other threads seems to give the impression that it was supported), however as outlined in my latest edit it does work if you enable it in the source code! Could you think of any direct problems with my approach or is this just about how it would be done if it were to be enabled in the future? (minus potential bug fixes and what not)

The biggest reason it isn’t supported is performance; it is very slow to cook at runtime on mobile.

What if just cooking a small number of things?

Before I go building my road mesh by hand, is there an easy way to convert a spline mesh to a static mesh in the editor via blueprint?

Runtime cooking for mobile is coming in a future release as an option.

Hi , thank you for your time and contribution to this forum…

Forgive my ignorance, but I am a novice programmer, and I still have a lot to learn with regard to UE4:

I am relying a lot on blueprints. What is the practical significance of runtime cooking with regard to working with blueprints? I’ve been working with various iterations of a game deployed to android and I do notice a big difference in the way physics is handled versus the PC version, especially as it relates to enabling or disabling physics within blueprint event graphs. What exactly does runtime cooking mean within the context of blueprints? Does this mean I cannot change physics related settings while the game is running? I assume that’s what it means, but I’m not sure.

Runtime cooking refers to updating the collision volumes for the rigid bodies dynamically instead of during the cooking phase in the editor for packaging or launch.

Has there been any new information on this?