C
Join ServerC#
help
need help with properties and their setters
TTheSnowOwl11/15/2022
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
any advice would be quite lovely. The setter method is not yet finished, but i got stuck with this.
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.

EEro11/15/2022
the set block is executed when you set the transform
EEro11/15/2022
the transform's setter doesn't care about what you do inside the transform
EEro11/15/2022
i'm not sure this is even how you're meant to do it
EEro11/15/2022
i would imagine there's a built-in thing in unity that moves all children of a transform along with their parent
PPobiega11/15/2022
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.TTvde111/15/2022
it's really dangerous to put odd logic in setters, people won't expect it
TTvde111/15/2022
if you could, I would recommend to make transform get only, and create a method to update the transform with information
EEro11/15/2022
nobody needs to expect it
EEro11/15/2022
it's a unity game
EEro11/15/2022
no one else is using this code
TTvde111/15/2022
I wouldn't see that as a good reason to write code I think is "bad code"
TTvde111/15/2022
just because it's likely no other human will see it
TTheSnowOwl11/15/2022
hmm, strange, as if I try to set a value within a get only property it says that I can ot assign values...
TTheSnowOwl11/15/2022
it's not unity :) it's something I'm making for myself tho, so indeed no one else will use this
TTheSnowOwl11/15/2022
anyway... if there is no build in way of doing this I'll find another way to do this. thanks a bunch everyone!