Improve instantiation performance #494
Daniel4144
started this conversation in
General
Replies: 1 comment 4 replies
-
Sounds like a great observation!
Solutions I could think of:
we also have to have a strategy how to deal with unknown components (might come from future injected extensions). Imagine a custom physics extension that adds a Collider component. I kinda prefer the first solution, since it allows you to do that stuff with querying the glTF JSON. Example in public void CreateNode(
uint nodeIndex,
uint? parentIndex,
Vector3 position,
Quaternion rotation,
Vector3 scale
) {
var node = gltf.GetSourceNode(nodeIndex);
if (node.mesh >= 0) {
// instantiat this prefab
}
else {
// instantiate other prefab
}
...
}
public virtual void AddPrimitive(
uint nodeIndex,
string meshName,
Mesh mesh,
int[] materialIndices,
uint[] joints = null,
uint? rootJoint = null,
float[] morphTargetWeights = null,
int primitiveNumeration = 0
)
{
// fetch previously generated gameobject and renderer component
var go = nodes[nodeIndex];
var mr = go.GetComponent<Renderer>();
// Assign mesh etc.
...
} |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
At the moment I am adding a custom script to every node after instantiation of a model at runtime. Because the models contain many nodes this takes some time.
I experimented with making the instantiation and initialization faster and noticed that instantiating a prefab with all components and scripts is faster than creating a new gameobject, setting transform/parent, adding components... - it is basically just one call: Instantiate(prefab, position, rotation, parent).
To achieve this I created a custom instantiator which works fine for creating the hierarchy with additional scripts attached. However, because this was significantly faster I also wanted to create meshfilters/renderers/colliders this way. I think at the moment it is only possible to add meshes later in a second iteration. Or is this somehow possible?
Beta Was this translation helpful? Give feedback.
All reactions