Is this a situation where you delete any of those four declarations and shit hits the fan because of some arbitrary race condition and the easiest fix is to add a small delay in the function by repeating the same operation four times?
This looks like unity, in that case, all of this happens in a single gameplay tick - so no race conditions unless they're doing something insane, and the "player can move" assignment is beyond redundant.
Is there no chance that functions for different game objects could be run in parallel during a single tick? Maybe there’s some other object that might try to move the player
This is what I was thinking, like when you make a call to it, in the setter there is some sort of iterator that changes with each time you set it. That being said, it's not clear from the code and leads to maintainability issues if you don't have that legacy knowledge, so still bad code.
In this case Transform.position is a custom setter that calls out to native C++ code, so not only will it not be compiled out but it's pretty slow to do!
I once saw a codebase where all the code was in property setters. So then setting some shit multiple times had side effects. I really think the guy who did it was a maniac.
What kind of a BS metric is that? I will probably make less than minimum wage if I was evaluated/paid like that because I write very less code. Most of my time is spent maintaining the service and writing docs.
I wonder if character.transform.position is a float4 (vec4), and the X, Y, Z, W variables in the array were originally copied one by one. Then someone cleaned that up later, but left all 4 assignments. .playerCanMove seems to be acting as a crappy attempt at a mutex so that nobody accesses the position variable while it is being written.
Also the naming conventions are wrong. It access properties outside the function, those are typically named _name or Name depending on the property type and access level. At least in .net
class Transform
{
Position _position;
public Position position
{
get { return _position; }
set
{
if (new Random().Next(4) == 0) { _position = value; }
}
}
}
I mean, what even is this? Never mind the duplicated code.
All this does is snap the character to the object with this MonoBehaviour component (transform.position = component owner's position) – that is performed instantly (merely 3× more than necessary), and sets character.characterManager.playerCanMove to true even if it was previously false. I hope this function is unused or still in progress of being written…
Also, from the name, I'd expect the signature to be something like ChangeCharacterPositon(Character character, Vector3 position).
109
u/distractedNightOwl Aug 29 '21
Haha, I think, these copy+paste- or merge-errors can be found in every code base. Hopefully, this was not written intentionally.
231
u/trBlueJ Aug 29 '21
Is this a situation where you delete any of those four declarations and shit hits the fan because of some arbitrary race condition and the easiest fix is to add a small delay in the function by repeating the same operation four times?
97
u/Aggravating-Ad-2310 Aug 29 '21
I smell unity
32
u/[deleted] Aug 29 '21
That’s what happens when you pay consultancies per line of code!
9
u/rgrannell1 Aug 29 '21
I really hope those are redundant lines of code and not necessary due to to some strange setter...
6
u/RelentlessWolf27 Aug 29 '21
How would you improve this ?
5
u/Jaegermeiste Aug 29 '21
I wonder if character.transform.position is a float4 (vec4), and the X, Y, Z, W variables in the array were originally copied one by one. Then someone cleaned that up later, but left all 4 assignments. .playerCanMove seems to be acting as a crappy attempt at a mutex so that nobody accesses the position variable while it is being written.
3
u/deftware Aug 29 '21
Racking up the old quantity code eh?!
2
u/[deleted] Aug 29 '21
I'll sometimes ctrl-v/ctrl-z while I'm thinking. This guy maybe just forgot the ctrl-z 50 times
1
u/[deleted] Aug 29 '21
I gave up after the first statement.
1
u/EquivalentOne9996 Aug 29 '21
Also the naming conventions are wrong. It access properties outside the function, those are typically named _name or Name depending on the property type and access level. At least in .net
1
u/JuHu13 Aug 29 '21
How big do these position Variables have to be, that he has to disable the player movement for the operation?
1
u/stevie-o-read-it Aug 30 '21
1
u/nickpofig Sep 06 '21
playerCanMove can be a property.
1
u/_Ralix_ Aug 29 '21
I mean, what even is this? Never mind the duplicated code.
All this does is snap the
characterto the object with this MonoBehaviour component (transform.position= component owner's position) – that is performed instantly (merely 3× more than necessary), and setscharacter.characterManager.playerCanMoveto true even if it was previously false. I hope this function is unused or still in progress of being written…Also, from the name, I'd expect the signature to be something like
ChangeCharacterPositon(Character character, Vector3 position).-7
u/Knuffya Aug 29 '21
Poor chap C# is being javascripted by all the unity kiddos.
-4
u/om_plusplus Aug 29 '21
Does c# have (sass-like) mixins? Seems like unity is quite annoying when it comes to repetitive method calls