Skip to main content
January 22, 2015

Changing materials in realtime

I have a script that just cycles some gameobjects (roughly 20) through different materials on key press.

In the editor the materials change instantaneously and smoothly with no lag. When I do a build and run direct to Rift, any time I change materials there is a 1 second hiccup where the screen freezes. It runs at a constant 75fps before and after switching materials. Anyone know of a workaround that might prevent this?

I thought it could be caching the materials but the lag never changes.
    This topic has been closed for replies.

    3 replies

    Inspiring
    January 22, 2015
    Does this happen if you disable the OVR Camera and just build with a regular camera?
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Up and Coming
    January 22, 2015
    Its because when you run the build it doesnt have the materials loaded into video memory yet.
    you could have a frame where all materials are seen so they load into memory.
    There might be a way to do this with scripting, but i havnt found a way yet
    Ambient Flight Eagle Flight Experience Dinosaur Voyage Running from Dinosaurs
    January 26, 2015
    Just wanted to post an update that this wasn't an Oculus issue. I tried adding a cube with each material to "pre-cache" the materials and that still didn't fix it. Had the same problem with a normal non-OVR build.

    It was either referencing the length of my materials array every switch, or a debug.log statement at each switch, or a combination of both. After caching the array length in a variable and removing the debug.log statements there is no delay.

    What was really confusing me was why it wasn't happening in the editor, which I guess may point to it being the debug.log times 30.