Hey. I’m getting quite bad Performance on a Custom Editor which saves TreeInstances to Groups.
I’m imagine it’s connected to this this for loop… (But I’m out of Ideas how I could make it different…){
lets say saving 500 TreeInstances takes about 1/2 second. 2500 TreeInstances taking about 2 Seconds. but… all above 5000 take Ages. (Working on a MacPro late 2013) it’ freezes Unity for a Moment due to the Saving Process of those Instances.
Ok here is my suspected slow down save code:
void SaveGroup_CHECK(int TI_INDEX){
for(int i = 0; i<m_GO_Groups.Length;i++){
for(int ii = 0; ii < m_GO_Groups*.m_GameObjects.Count;ii++){*
-
for(int iii = 0; iii<m_ted.treePrototypes.Length;iii++){*
-
if(m_ted.treeInstances[TI_INDEX].prototypeIndex == iii){*
if(m_ted.treePrototypes[iii].prefab == m_GO_Groups*.m_GameObjects[ii]){
_ TreeInstance TI = new TreeInstance();_
TI = m_ted.treeInstances[TI_INDEX];
_ TI.prototypeIndex = ii;_
m_TI_Groups.m_TreeInstances.Add(TI);
_ }
}
}
}
}
}
and I’ve got two Main saving Lists:_
[System.Serializable]public struct list_GameObject {
[SerializeField]public List m_GameObjects;
_}*_
[System.Serializable]public struct list_TreeInstances {
[SerializeField]public List m_GameObjects;
}
// like this.
list_GameObject[] m_GO_Groups;
list_TreeInstances[] m_TI_Groups;
I could Provide the whole Code if needed…
----------
> EDIT:
----------
Ok i have a Custom Editor where you can Create Groups as many you want. In to a group i can Add Prefabs (Trees (TreePrototypes for Unity Terrain)). Now you can select the Groups you want and Load them in to Terrain. The Tree Prefabs are now showing up in the Terrain Component. Now if you Paint Trees on to the Terrain, TreeInstances are created by the Terrain. Those Instances hold the Position, Rotation, Height and more inside of it. But the most Important thing is the TreePrototypeIndex, which allows me to read which Prefab was used for each Instances.
If I change/load different Groups, or Clear out the Terrain, I want to save the TreeInstances in to a List, connected to the Groups I’ve made. I thought the easiest way is to create foreach Group, which I created a new List.
So in the End on to this Point, I have 2 Main Arrays which hold Lists.
The First Array holds a List of TreePrototypes and the Second Array holds a TreeInstance List. (See the Second Code snippet above).
----------
For Loading I want to call first the List with the Prototypes(Prefabs) and Load them to the Terrain. And then I’m loading the Instances in to Terrain, modifying the TreeInstance.prototypeIndex(int value), so it matches to the Correct TreePrototypes.* (If I’d do it reverse, an Error shows Up, that the TreeInstances is lacking a Prototype Index.).*
----------
First I worked with a List> but this didn’t work out because of I think SerializedProperty isn’t able to handle List>.(Didn’t figure out how to Digg inside the List with FindPropertyName/Relative)
[124834-tpgm-board.png|124834]