Instantiating with GameObject.instantiate or GameObject.instantiateSynced works in situation’s where its full of all sorts of objects until a canvas with canvas type components such as text or images are in it.
Hi! It looks like you’re encountering issues with GameObject.instantiate or GameObject.instantiateSynced when instantiating a canvas containing text or images in Needle Engine. Based on the information you provided and the documentation, here’s a brief breakdown of potential causes and solutions:
Issues and Potential Solutions
Error Context: The errors you’re receiving when the canvas contains text or images may be related to rendering or instantiation specifics in the engine. Check for properties or mandatory components not being set correctly when instantiating UI elements inside a canvas.
Instancing Limitations: If you’re trying to instantiate objects with complex components (like UI elements with child components) without proper configuration, the instantiation may fail. Ensure that all required properties for UI elements are correctly defined in the instantiated prefabs.
Render Settings: Make sure that the Canvas component has valid render settings. Properties such as renderOnTop, depthWrite, doubleSided, castShadows, and receiveShadows should be set according to your requirements (see the documentation).
Suggested Code
You might want to adjust your spawnitemToInstantiate method to include debug logging that captures significant errors or outputs during the instantiation process. Here’s a revised version of that method:
@marwie1
I managed to bypass the bug by instantiating all the objects under the Canvas.
So jam packed all objects under it.
Is this just a standard practice and not a bug?
Could you send a bugreport if you haven’t already? I’m not sure if I understand the setup correctly. The canvas that you instantiate contains 3D objects (non canvas objects) too?
Should be fixed in the next update. I think this issue never occured before because in most cases UI is loaded from a prefab or separate scene and was (so far) never cloned at runtime when it was already in the scene. Thanks for reporting! That’s a good issue to fix