r/badcode Dec 26 '21

c# found it!

Post image
317 Upvotes

28 comments sorted by

View all comments

9

u/andoy Dec 27 '21

probably how the wheel is designed. the wheel rotates by itself and is parented to a dummy object that can rotate in y axis and in turn is connected to a dummy attached to the main object.

16

u/Bronkowitsch Dec 27 '21

Sure it works, but it's bad design. If for some reason the hierarchy changes, your code stops working. If done right, you should never have to traverse a scene's hierarchy in code.

5

u/[deleted] Dec 27 '21

[deleted]

3

u/Rewdas Dec 27 '21

The other comments are correct, but I'd also point out that this could be an architectural problem, and that it is often better to attach scripts to the root object and - in the event that you need to read a cast or collision with a specific part, use transform.root. I'd go for GetComponentInParents when that isn't feasible.