Hgawmphdmph Posted April 21, 2021 Share Posted April 21, 2021 I have what may be some kind of instancing issue. I have a model created in Blender and imported to Leadwerks. I opened a new empty map, dragged in the model, attached a lua script, and saved the result as a prefab. I then opened another new empty map, dragged in the model again, attached a different lua script and saved the result as a second prefab. The model has no material. Both of the scripts create their own new material and attach it to their associated entity. Each then make changes to it's material - one uses a buffer to write and draw graphics to its associated material, the other switches the textures of its material to produce animation. If I add one instance of each prefab to any empty level, at runtime the same output appears on both objects. The script attached to the last prefab dragged in, draws to both objects. (To be clear, these are instances of two DIFFERENT prefabs.) If I remove the script whose output is showing from it's associated entity, the script attached to the other object draws to BOTH objects. If I remove the object whose script is showing everywhere, the other one starts showing what would be expected from its own attached script. If I drag in further instances of the model, the current dominant script output is drawn to those also. If I drag new instances of one of the prefabs into the scene, the last one dominates and its associated script affects ALL objects with this model, whether standalone model instances or instances of either prefab. It's as if a model is always instanced and shared, between different prefabs and even between different standalone versions of the model. Is this the case? Can anyone help with what on Earth is going on? Thanks all. Quote Link to comment Share on other sites More sharing options...
Solution Rick Posted April 22, 2021 Solution Share Posted April 22, 2021 Yes, I believe if the same model is dragged into the editor, it in instanced which means they share certain aspects, material being one of them. In code I believe the Copy() method you can specify if you want the material to be shared or not, but as far as I recall in the editor the only way was to make a totally different model (not prefab but model). I did at one point suggest to give us a way to specify when dragging models into the scene if they should be instanced or copied without material sharing. The reason for the way it is would be it's less resources to share that information. Quote Link to comment Share on other sites More sharing options...
Hgawmphdmph Posted April 23, 2021 Author Share Posted April 23, 2021 Thanks Rick. I ran a bunch more tests and I think I understand it now. I tried saving an identical, but differently named asset and that got converted into a new .mdl file, which avoids the instancing issue. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.