Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Anonymous's avatar
Anonymous
11 years ago

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.

3 Replies

Replies have been turned off for this discussion
  • Does this happen if you disable the OVR Camera and just build with a regular camera?
  • 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
  • Anonymous's avatar
    Anonymous
    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.