Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: westingtyler on September 27, 2019, 05:04:36 PM

Title: Hash Table Proxy Prefill Type: MeshRenderer?
Post by: westingtyler on September 27, 2019, 05:04:36 PM
Hello. I am making a custom culling system and want to iterate through the _Landscape Cells game object root, getting each child, getting each mesh renderer component, and storing them in similarly-named keys in hash tables, to use for a custom culling fsm.

But I went to the Hash Table's prefill type and saw that Object is not an option like it is in FSMs. Am I missing something? I want to store a bunch of mesh renderer components. In a playmaker fsm array I can select Object, then select the Object Type, and find the Mesh Renderer component, but I can't do this for some reason in Hash Table Proxy scripts. Am I missing something?

someone told me to use GetComponent to get all I need and store them since GetComponent was expensive, but I'm not sure where the best place to store the MeshRenderers is. An FSM array?

I THINK i could add MeshRenderer into ArrayListProxy, and CollectionProxy, but in that one it says "public enum VariableEnum{ // WARNING: DO NOT INSERT ITEM: IT CORRUPTS EXISTING PROXIES SELECTION, only append

does that mean I can add entries but only at the end, rather than in the middle? or is "insert" and "append" some special script I have to make?
Title: Re: Hash Table Proxy Prefill Type: MeshRenderer?
Post by: djaydino on September 28, 2019, 08:14:58 AM
Hi.
Indeed there is no Object selection on hash table and array list.

But why do you need to get the Mesh Renderer Component?

If you need to change data on the Component you only need the GameObject.
Title: Re: Hash Table Proxy Prefill Type: MeshRenderer?
Post by: westingtyler on September 28, 2019, 10:23:00 AM
Hey! So here's what I'm doing: I'm dividing my game world terrain, custom-made in Blender, into a 20x20 grid of 250meter square game objects. And each cell is assigned a name like 11-15 or 1-18. As the player moves around, I have an fsm that gets the player's position, converts that into a cell name, then checks a list of hash tables (or array lists?) and simply enables or disables mesh renderers of the LOD0-3 meshes on the world cell game objects.

I currently have these game objects dropped into a hash table. (actually 20 "row" hash tables each with 20 column cell key entries.)

I COULD get the stored cell's game object, get its component, and disable its mesh renderer manually, but I was told that GetComponent was expensive, so running that 9 or 25 times (depending on number of LODS I create), every time the player walks 250 meters in a direction, seems expensive.

Otherwise, I COULD just enable and disable the world cell game objects entirely, but considering they often contain nav mesh data for far away characters, I feel I'd get the whole "nav mesh agents are no longer on a nav mesh" error.

Are you saying there's a better way to do this?

The whole point of using this simplified culling system, is that every frame the game doesn't need to scan 12000+ game objects (in my UN-decorated world map) to see if they need culling, but instead to do it based on a simple "where is the player" math operation. Potentially I could still use official occlusion culling inside that much smaller region, but the immediate area around the player will have far fewer objects to cull than, say, a random mailbox door 2 km away... plus another 400 static mail box game objects. I WISH the mega city "heirarchical culling" they used in that phone demo was a part of Unity, but I can't find it.

I learned the culling preparation was the big frame killer for me, by reading the profiler, and when I just disabled a bunch of the world, all of a sudden my frame rate was great again, so I came up with this idea to just have all far away map cells be simple 100 triangle, 1 material meshes, depending on LOD.

It's really weird because the  scene I checked the profiler stuff in, was using unity terrain and lots of grass, and I was confused by how non-performant the default terrains with sparse grass billboards, ended up being.

I'm making an open world game that has 90+ frames for VR, so I'm trying to improve performance a lot.
Title: Re: Hash Table Proxy Prefill Type: MeshRenderer?
Post by: djaydino on September 29, 2019, 12:31:23 PM
Hi.
Actually get component is not very expensive from what i have found/read.
Find calls are way more expensive.

if you only call them once every 250 meter you should have no  problem at all, even with 10.000 calls.

I did make an action (attachment below) to directly Enable/Disable the Mesh Renderer, so you do not need to do 'Get Component'

There is also an action on the Ecosystem called 'Activate Component' But it is mirroring and might be slightly slower that a dedicated action.

Also This might be interesting for you  :
https://docs.unity3d.com/Manual/OcclusionCulling.html