Monday, October 28, 2013


October 28, 2013

I watched a presentation given by the Oculus team at GDC last week. The emphasis was clearly on framerate and that it is the number one priority for developers.

Well... my focus has been on realism up to this point and my demo is a tad bit on the slow side unless your gaming rig breathes fire. This means I need to reduce the number of meshes on the screen but how do I do that? I can make my demo more and more scaled down or I can hide meshes based on performance/user-preference. I chose the later.

I just coded this last night so it still needs some work, but the initial results were super cool so I thought I'd share how to do it. Well... actually it blew me away. This code was able to hide 3000+ meshes instantaneously. I've never seen a map where you can make large portions of it just disappear. With the rift on it was incredible.

The easiest route is to bind a key to this code. I actually bound 3 keys to hide different meshes but we'll focus on just the "F" key since it is next to the movement keys.

In DefaultInput.ini:
1. Find this line and comment it out (semi colon in front)
2. Then add this line:

You will need a class that extends UTPlayerController.uc. I have already covered how to set up a sample set of code for custom footsteps. Read that first if you are unfamiliar with unrealscript. We will have a variable that holds the prior hide/show setting. the function HideMeshes will flip that setting and hide/show all meshes that are of the type you are looking for. In my case I wanted to hide all trailers of a specific type. You will need to change the meshClass to be your mesh.

This solution is based on what I found here:

As usual, the example in the forum didn't work but I beat the code into submission :)

Here you go:

Class CustomGamePlayerController extends UTPlayerController;

var bool bHideStackTrailers;

// You will need to change the meshClass to be your mesh.
exec function HideStackTrailers() {
    local StaticMesh meshClass;
    ClientMessage("HIDING TRAILERS");
     bHideStackTrailers = !bHideStackTrailers;
    meshClass = StaticMesh'ready_player_one.Meshes.trailer_a';
    ToggleStaticMeshActor(meshClass, bHideStackTrailers );

// Note that I also disable/enable the collision for the mesh
function ToggleStaticMeshActor(StaticMesh meshClass, bool hide) {
    local StaticMeshActor actor;
    foreach AllActors(class'StaticMeshActor', actor) {
        if (actor.StaticMeshComponent.StaticMesh == meshClass) {

No comments:

Post a Comment