need help with properties and their setters
i have a property for a transform that holds several values, including position. and i have a setter block to handle logic that if the positional values were to be moved, any child object should move accordingly with it. however when i call
myObject.Transform.position = new Vector2(7, 2);
it does not invoke the setter method of the gameobjects transform property.
any advice would be quite lovely. The setter method is not yet finished, but i got stuck with this.6 Replies
the set block is executed when you set the transform
the transform's setter doesn't care about what you do inside the transform
i'm not sure this is even how you're meant to do it
i would imagine there's a built-in thing in unity that moves all children of a transform along with their parent
The transform setter is indeed not invoked when you do
myObject.Transform.position = new Vector2(7, 2);
- the getter is however, and then the position
on that object is changed.it's really dangerous to put odd logic in setters, people won't expect it
if you could, I would recommend to make transform get only, and create a method to update the transform with information
nobody needs to expect it
it's a unity game
no one else is using this code
I wouldn't see that as a good reason to write code I think is "bad code"
just because it's likely no other human will see it
hmm, strange, as if I try to set a value within a get only property it says that I can ot assign values...
it's not unity :) it's something I'm making for myself tho, so indeed no one else will use this
anyway... if there is no build in way of doing this I'll find another way to do this. thanks a bunch everyone!