Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Does anyone know how to access OcclusionCullingData and manually get/set it?

Discussion in 'Editor & General Support' started by snarlynarwhal, Mar 14, 2019.

  1. snarlynarwhal

    snarlynarwhal

    Joined:
    Jan 16, 2014
    Posts:
    27
    For our project we use prefabs for our maps instead of scenes since they have less overhead. The con is that we have to manually export scene-specific data like LightmapData. We easily built tools to do this thanks to the wonderful Lighting APIs. However, Occlusion Culling does seem to not provide access to OcclusionCullingData nor an API to set/get a camera's OcclusionCullingData. Does anyone know of how we might accomplish this?
     
  2. drcrck

    drcrck

    Joined:
    May 23, 2017
    Posts:
    321
    You can't, even with reflection
     
  3. snarlynarwhal

    snarlynarwhal

    Joined:
    Jan 16, 2014
    Posts:
    27
    Oh man :/ alright thanks for the confirmation!
     
  4. TurboHermit

    TurboHermit

    Joined:
    Dec 20, 2011
    Posts:
    40
    I've been looking around for something similar and couldn't find any other forum posts on it. I started experimenting today, so maybe this info is useful for anyone still hitting this post in their searches.

    You CAN access OcclusionCullingData through the use of SerializedObjects and SerializedProperties, at least to read the data directly from the assets. It's very unwieldy of course and an accessible API would be a good feature request.

    My use-case is only for in the editor though, so not sure if it's useful to you, but here's what I do:
    1. Get the OcclusionCullingData.asset file through AssetDatabase.Load or through EditorGUILayout.ObjectField as a UnityEngine.Object
    2. new SerializedObject and pass the OcclusionCullingData Object as parameter
    3. Iterate through the property names using SerializedObject.GetIterator and SerializedProperty.Next
    4. Check the names of the properties and use that info to get/set what you want
    5. SerializedObject.ApplyModifiedProperties if you want to save the changes
     
unityunity