Hey guys, I want to use “System.Environment.UserName” to get the player name to spook the player a bit
but I was also thinking of making a check to compare it to a few hundered(maybe thousands) of names to see if its real if not then we skip the spook, and is this going to be bad for performance or space? it could maybe do this every time you open the game or once depending on results
While you could do this… who cares if it’s real or not?
While it’s a fun little twist, I don’t really see you needing to check against a list. But, try it and see how it runs. If it’s a list, you could even use something like .Contains to easily check if the list has the name.
Also, if it’s really a huge deal, you can easily reduce the load by grabbing the first letter and using that to only load a list of names that begin with that letter. But, you really just need to implement your list and see how the performance is before you worry about performance.
A few thousand strings? Run a single time? Don’t even worry about it unless your user is running a 6502 made in the year 1976.
thanks, I sadly know how to make stuff…but not the optimization lol
It mostly comes with experience. A lot of it is from picking up tricks from others or simply having an issue and then having to deep dive into it to solve the issue. Like Brathnann said, it’s usually best to do it in the simplest way you can think of until you know there is a problem. You kinda just need to accept that your first guess won’t always be right but obviously you have to start with something before you can know better.
wise words lol, thanks I’ll keep that in mind
Don’t sweat it. You should throw yourself fulltime at trying all the stuff your brain can come up with, simply to see how it goes and to learn from it and have fun. Modern hardware is very fast and Unity is a BEAST of a game engine.
When you do have a slowdown, here’s my standard blurb:
DO NOT OPTIMIZE “JUST BECAUSE…” If you don’t have a problem, DO NOT OPTIMIZE!
If you DO have a problem, there is only ONE way to find out. Always start by using the profiler:
Window → Analysis → Profiler
Failure to use the profiler first means you’re just guessing, making a mess of your code for no good reason.
Not only that but performance on platform A will likely be completely different than platform B. Test on the platform(s) that you care about, and test to the extent that it is worth your effort, and no more.
https://discussions.unity.com/t/841163/2
Remember that optimized code is ALWAYS harder to work with and more brittle, making subsequent feature development difficult or impossible, or incurring massive technical debt on future development.
Notes on optimizing UnityEngine.UI setups:
https://discussions.unity.com/t/846847/2
At a minimum you want to clearly understand what performance issues you are having:
- running too slowly?
- loading too slowly?
- using too much runtime memory?
- final bundle too large?
- too much network traffic?
- something else?
If you are unable to engage the profiler, then your next solution is gross guessing changes, such as “reimport all textures as 32x32 tiny textures” or “replace some complex 3D objects with cubes/capsules” to try and figure out what is bogging you down.
Each experiment you do may give you intel about what is causing the performance issue that you identified. More importantly let you eliminate candidates for optimization. For instance if you swap out your biggest textures with 32x32 stamps and you STILL have a problem, you may be able to eliminate textures as an issue and move onto something else.
This sort of speculative optimization assumes you’re properly using source control so it takes one click to revert to the way your project was before if there is no improvement, while carefully making notes about what you have tried and more importantly what results it has had.
While I do not disagree with the general tenet that premature optimization is foolish that doesn’t mean that common sense optimizations should not be implemented from the start.
What sort of list are you checking against and what type of comparison are you planning?
If you implement any persistence mechanism as you have mentioned, you could bypass checking on every start up once you have determined the name. That is sensible and it means any hit only occurs when you don’t know the answer already.
There is generally no need to profile such an improvement. The goal isn’t to know whether 5ms or 10ms was saved and you aren’t going to run a profiler every time you edit your code. I routinely implement solutions that could theoretically take a millisecond longer but the code is so understandable that I prefer it to any objectively faster alternative.
I can’t think of any reason why you would bother with this step. A list of names that large would still only cover the more commonly used names, and if it’s a common name people are just going to assume that the developer went with that name during development rather than pulled it from the user’s profile.
Another problem with this idea is that System.Environment.UserName
returns the name that they use to log into the device not the name of the person who owns it and many people will use a nickname or email address for that.
But even if it worked perfectly and the user did understand that it was their name being displayed on purpose I’d be worried about the reaction they might have to that. It’s very possible they could view that in a negative way.
yeah its meant to be scary and at this point i think most people know about this trick so it might not be too wild
thanks I’ll keep that in mind and I just want to say thanks for helping out in the fourms I keep on seeing you in many threads helping out