|
I'd like to have a prototype object, which I clone at runtime (possibly many times) and then change the texture on each one independently. My early experiments were in JavaScript, but now I'm moving to C# for easier multidimensional arrays. In JavaScript, this works fine:
I can call this multiple times with different row and col values, and each one gets a unique look. But when I try to do the same thing in C#:
...the result appears to be panels that are linked together. Both the original and the clone always have the same look, and even if I change the texture offset in the editor for one, it changes it for the other. I would speculate that this is because Instantiate did not do a deep copy, but instead gave me a clone that's sharing the same material object as the original. If there's only one material object, then of course all objects using it will look the same. But I thought that JavaScript and C# were calling through to the same stuff under the hood. So why is the behavior different? And, how would I go about cloning an object and giving it a unique look in C#?
(comments are locked)
|
|
Just had a similar problem. You are correct in assuming that this happens because a deep copy was not performed. You can force the deep copy yourself:
note that you may in turn need to copy the texture for the Material as well: Thanks, that's a neat trick and sounds like it'll solve the problem. I still find it disturbing that the same function behaves differently in JavaScript vs. C#, though!
Feb 09 '11 at 03:13 PM
JoeStrout
(comments are locked)
|
