- Home /
creating an instance of a texture at runtime
So currently i have a system that reads in a texture as an armour value for a unit to determine whether something gets hurt or not, what i want to do with it though is alter the texture whenever it takes a hit to have a lower armour value at the impact point. however i can't predict the number of units used and therefore can't have a static number of separate textures to use and alter therefore i was wondering if there was any way to duplicate an existing texture at run time so that each unit has its own values and then remove the duplicate texture on the units destruction.
Why are you using textures to deter$$anonymous$$e what a string or a numeric value should?
i use the texture so i can assign different values to different area of the mesh, so a turret might have a value of one while the back of a vehicle might only be 0.2 etc
Answer by hexagonius · Sep 25, 2017 at 04:05 PM
I'd you must use textures, just use Instantiate with an existing one.
Right, every instance of a class that is derived from UnityEngine.Object can be duplicated / instantiated with "Instantiate()".
the way you worded hexagonius it sounds like you are saying that when i instantiate my model that i should just reference the original texture? that doesn't work because any change made to one unit would affect all of them at the same time. although maybe i'm just misinterpreting the answer?
Your answer
![](https://koobas.hobune.stream/wayback/20220612135607im_/https://answers.unity.com/themes/thub/images/avi.jpg)