|
Re: Global state, there are only 3 ways to get an instance of something: Pull it from a member var, pass through a function parameter, or use a global. There are a lot of scenarios where adding a member var is bad (i.e. small, high-frequency structure, or worse, POD), or won't work (i.e. the instance you want changes). Passing through a function parameter can run into problems if you're using virtuals and wind up having to update an interface and a shitload of overrides. Globals are much easier than either of those, so they definitely do have use cases. Some of the use cases are completely non-controversial, like a service that controls access to a resource (i.e. asset streamer, threaded job dispatch, rendering backend), or something that would conflict with other instances of itself (i.e. almost anything that writes to a fixed location on disk, like a shader cache). The catch is this: You'd better be drat sure that you really only ever need one of that thing, that nothing is holding a reference to it, and that everything that wants to access to it can be cleaned up before you shut it down.
|
# ? Jul 20, 2016 17:01 |
|
|
# ? Apr 17, 2024 19:44 |
|
OneEightHundred posted:The catch is this: You'd better be drat sure that you really only ever need one of that thing, that nothing is holding a reference to it, and that everything that wants to access to it can be cleaned up before you shut it down.
|
# ? Jul 20, 2016 17:28 |
|
Is it possible to use C# 6.0 with Unity?
|
# ? Jul 20, 2016 17:44 |
|
Zero The Hero posted:Is it possible to use C# 6.0 with Unity? That isn't the correct question. There are two things you need to be worried about. 1) What version of the CLR is supported by Unity. 2) What version of the C# language can Unity compile. The CLR version and the C# version aren't tied together and are two separate things. However, some C# language features are only enabled on certain CLR versions. In order to find out if Unity can handle C# 6 code you would have to go feature by feature of the changes in 6 and see if Unity can compile and/or read the assembly properly. Some features can be supported. For example, Unity uses CLR 2.0. It is known to support C# language features up to C# 3.5. But right away I'll tell you that things like async are impossible. And a bunch of other stuff that was added in .NET 4, 4.5, etc.
|
# ? Jul 20, 2016 17:54 |
|
xgalaxy posted:That isn't the correct question. There are two things you need to be worried about. Has there been any word from Unity devs on if/when they'll update the CLR?
|
# ? Jul 20, 2016 18:24 |
|
Zero The Hero posted:Has there been any word from Unity devs on if/when they'll update the CLR? From what I know, the plan is to update to a newer CLR and C# versions once all platforms they support work under IL2CPP. My guess is this is still at least a year out from being a reality.
|
# ? Jul 20, 2016 18:50 |
|
I like using singletons or globals as managers or storage and not much else. It's very handy to store, for example, sprites in some box that you can say "I'd like this sprite, please" to. Central storage of resources used in a bunch of places can be very handy. But managers shouldn't be doing much to what they manage. Mostly they should say "hey thing do this" or "hello other thing this is the thing you wanted." ENCAPSULATE EVERYTHING.
|
# ? Jul 20, 2016 19:23 |
|
Suspicious Dish posted:the goon-built renderdoc? https://github.com/baldurk/renderdoc Sex Bumbo posted:Turn on the debug spew and get really good at figuring out why things are going wrong by making educated guesses. welp Renderdoc is good enough to aid me in guessing gl errors so it's better than nothing, I guess.
|
# ? Jul 20, 2016 20:01 |
|
Since we are on the topic of global state, I shall share my favorite. I wrote a temperature controller application for lab stuff at work, and somebody's module was having the damndest time with it. They thought they were being clever using "temp" for assigning temperature. That was fine since it all fit on one page--kinda. It turned out their code was in a larger Python repository of other people's crap, and people really loved their global temp variable. So that thing would get set to all kinds of crap. It turns out your thermal controller doesn't like to be set to random strings and the like. Now for something completely different: Should I stick with Unity even if I'm just dabbling on a pseudo-3d turn-based board game interface for cell phones?
|
# ? Jul 20, 2016 20:37 |
|
Rocko Bonaparte posted:Now for something completely different: Should I stick with Unity even if I'm just dabbling on a pseudo-3d turn-based board game interface for cell phones? You gaze upon the gates of hell, and wonder of the adventure within.
|
# ? Jul 20, 2016 20:50 |
|
While we're talking Unity and global state - anyone have a (clean) pattern for a self-instantiating Singleton that uses a prefab? Maybe the right direction really is the "write all the stuff to do it without a prefab" direction, but the easy runtime tweaking et al is really nice. Also handy for all those asset reference types that are obnoxious to load via code but easy to drag into a slot in the Inspector. Sort of related - has anyone ever run into a case where having your objects this.gameObject.GetComponent() everything they need on awake was a noticeable perf hit? I've been manually assigning public variables to keep it efficient, but - boy would it be nice to not do that. Shalinor fucked around with this message at 21:02 on Jul 20, 2016 |
# ? Jul 20, 2016 20:59 |
|
Zero The Hero posted:Is it possible to use C# 6.0 with Unity? Unity C# 5.0 and 6.0 Integration
|
# ? Jul 20, 2016 21:16 |
|
Shalinor posted:Sort of related - has anyone ever run into a case where having your objects this.gameObject.GetComponent() everything they need on awake was a noticeable perf hit? I've been manually assigning public variables to keep it efficient, but - boy would it be nice to not do that. This will blow your mind, I found this out recently but cant find the tweet. If you add a function "void Reset() { ... }" you can assign variables in there and it gets called when you click "Reset" on the property window or instantiate the object in the inspector So you just put GetComponent's in there to autofill inspector variables; and I'm pretty sure it doesn't run in-game. Jewel fucked around with this message at 22:36 on Jul 20, 2016 |
# ? Jul 20, 2016 21:27 |
|
HaB posted:Aside: what's the good, rebindable-at-runtime Input asset thingy everyone was talking about for Unity? I believe we were mostly talking about Rewired: https://www.assetstore.unity3d.com/en/#!/content/21676 There are others (cInput Pro for example) but this seems to be the best/most used one. I don't have experience but Shalindor talked about using it with uFPS recently.
|
# ? Jul 20, 2016 21:33 |
|
leper khan posted:Shortly after that mess ended I worked with someone way worse than Hellfucker. Glad I got let go when I did though; about two months after that Tony stopped paying taxes. But yeah; I shouldn't have to ever tell anyone this, but don't just literally pull huge chunks of code from stack overflow verbatim. It's CC-by-SA licensed and I assure you, you do not want that poo poo anywhere near your commercial project. Don't steal code. Haha. Ha. Ha. Christ what a mess.
|
# ? Jul 20, 2016 22:04 |
|
Shalinor posted:While we're talking Unity and global state - anyone have a (clean) pattern for a self-instantiating Singleton that uses a prefab? Maybe the right direction really is the "write all the stuff to do it without a prefab" direction, but the easy runtime tweaking et al is really nice. Also handy for all those asset reference types that are obnoxious to load via code but easy to drag into a slot in the Inspector. Sure, just create your highlander class like you normally would. Then OnStart do a GameObject.FindObjectsOfType on your type. Name the first one ConnorMacLeod and Destroy any that aren't ConnorMacLeod because there can be only one. This works because new instantiations will always come after ConnorMacLeod in the scene graph, so ConnorMacLeod will always be the one true highlander. Probably still best to try not to have MacLeod take the other highlanders power too often, but he'll decapitate any other highlanders that you accidentally invoke to challenge him. Haven't ever noticed a real perf hit, but I don't usually work with tons of objects or extremely wide trees. I also normally just drag my assignments manually as well..
|
# ? Jul 20, 2016 22:23 |
|
I created a Game Development Discord server. I tried to get hold of Digital Spaghetti but I wasn't able due that he doesn't allow PM's. The link to the server is: https://discord.gg/JFwAarN it's brand spanking new but if you guys want to join it and participate its up and running. thx.
|
# ? Jul 20, 2016 22:31 |
|
Singletons are dumb because they're usually a pointless layer over global state that somehow manages to make it worse. They handle visibility, instances, and hide initialization order, and usually you just want to handle visibility. You either care about the order in which things are initialized or you don't -- if you do care, you should make it explicit because otherwise you need to wrap your head around some implicit system rather than just reading it. Dogmatically opposing global data is meant to solve data coupling and sharing, but both problems can trivially exist even without global data. Also, you can prevent data dependencies and sharing in other ways too.
|
# ? Jul 21, 2016 01:25 |
|
Jewel posted:This will blow your mind, I found this out recently but cant find the tweet. If you add a function "void Reset() { ... }" you can assign variables in there and it gets called when you click "Reset" on the property window or instantiate the object in the inspector
|
# ? Jul 21, 2016 02:50 |
|
Shalinor posted:HOLY loving poo poo THIS IS AMAZING I LOVE YOU
|
# ? Jul 21, 2016 03:13 |
|
Jewel posted:This will blow your mind, I found this out recently but cant find the tweet. If you add a function "void Reset() { ... }" you can assign variables in there and it gets called when you click "Reset" on the property window or instantiate the object in the inspector There's a reset button?
|
# ? Jul 21, 2016 03:25 |
|
leper khan posted:There's a reset button? Yeah, this one
|
# ? Jul 21, 2016 10:58 |
|
i enjoy how im oscillating between feeling hopelessly buried under stuff i don't understand yet, and moments of seeming invincibility because i wrote a delegate i am perfect On that subject, since I've been trying my best to understand the whole singleton debate and stuff, am I correct in that the alternative is to both place the "global" fields in more relevant objects, and to use static classes/fields/methods for when they need to be singular in nature? Not an exciting question but I'm trying to avoid forming bad habits since I won't have anyone else really to look over my shoulder and point out when I'm doing something batty; my initial instinct, for instance, was to go with "coordinator" type classes that serve as the locus point for getting classes to initialize/do things together without turning into a codependent tangled web, but then that's something I see a lot of anger directed at without much of an alternative put forth other than USE OBJECTS/INTERFACES DUMMY style of things. e: gee willikers i use a lot of profanity in my test stuff Tiler Kiwi fucked around with this message at 12:43 on Jul 21, 2016 |
# ? Jul 21, 2016 12:37 |
|
K. I freely admit I am awful at math. I think that may be at the heart of my current problem. In my RTS game, with a unit selected, right-clicking on the ground sends a Move order to that unit, with the point clicked as the target. That "works" in that if I select a unit and right-click the ground, the unit does in fact move there. "Move" is inaccurate. It TELEPORTS there. So I'm sure my per Update delta calculation is WAY off. I am currently doing this: (pseudocode, for brevity) code:
|
# ? Jul 21, 2016 13:58 |
|
HaB posted:K. I freely admit I am awful at math. I think that may be at the heart of my current problem. How far away is the target? And what does MoveTowardsTarget do?
|
# ? Jul 21, 2016 14:01 |
|
LordSaturn posted:How far away is the target? And what does MoveTowardsTarget do? code:
|
# ? Jul 21, 2016 14:13 |
|
HaB posted:
from: https://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html quote:The value returned by this function is a point maxDistanceDelta units closer to a target/ point along a line between current and target. If the target is closer than maxDistanceDelta/ then the returned value will be equal to target (ie, the movement will not overshoot the target). Negative values of maxDistanceDelta can be used to push the point away from the target. Are you sure that the result of speed * Time.deltaTime is not greater than the distance between both positions? Because this could be the cause of the problem. So try lower values for speed. That should be a bit of Trial and error. Or check ti via debug wether or not the distance is smaller than the step. Because in that case you'd reach the endpoint in a single frame.
|
# ? Jul 21, 2016 14:28 |
|
Tank Boy Ken posted:from: https://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html Yeah I am starting to wonder if Vector3.MoveTowards is the right function. I tried setting the speed to like 0.0001 and it still teleports there. The step debug outputs are like: (speed = 1.0 here) code:
|
# ? Jul 21, 2016 14:38 |
|
Just noticed you call MoveTowardsTarget(step); but the function you posted is void MoveTowardsTarget(). Do you have another function which takes one parameter? Also passing along "step" negates the need to calculate it in the called function.
|
# ? Jul 21, 2016 14:44 |
|
Tank Boy Ken posted:Just noticed you call MoveTowardsTarget(step); but the function you posted is void MoveTowardsTarget(). Do you have another function which takes one parameter? Also passing along "step" negates the need to calculate it in the called function. Yeah I was pseudocoding from memory and forgot that I am doing the step calculation inside MoveTowardsTarget. I have figured out the problem. In Start I am assigning the moveTarget to the same as the unit's transform. That is apparently being done byRef not byVal, so of course when I set my new target, it's just setting the unit's transform immediately to that value. I discovered this by printing out distance(target, unit.position) and noticing it was always 0. Herp derp derp. Fixing. Edit: well now my speeds are normal, but I have another problem. Here's what the relevant functions are: code:
HaB fucked around with this message at 15:34 on Jul 21, 2016 |
# ? Jul 21, 2016 15:27 |
|
Do I overlook something or could you just use a Vector 3 instead of the complete transform for moveTarget. If you do want to move the unit without changing the rotation, all you need to deal with is the position. So you need to get a reference via the selected objects. And then assign the new position to the transform.position. So more like gameObject.transform.position = target; (I guess MoveToPoint is attached to the gameObject that's supposed to move).
|
# ? Jul 21, 2016 15:57 |
|
Tank Boy Ken posted:Do I overlook something or could you just use a Vector 3 instead of the complete transform for moveTarget. If you do want to move the unit without changing the rotation, all you need to deal with is the position. So you need to get a reference via the selected objects. And then assign the new position to the transform.position. Actually that's a good point. I won't be worrying about rotation until I have actual models anyway, and most of that will just be equivalent to .LookAt( target ); Thanks.
|
# ? Jul 21, 2016 16:00 |
|
Tiler Kiwi posted:i enjoy how im oscillating between feeling hopelessly buried under stuff i don't understand yet, and moments of seeming invincibility because i wrote a delegate i am perfect With an emphasis on need. You definitely want to set up some sort of object hierarchy where some things conceptually own others. Part of the problem with global state is that nothing owns it so it can change in non-obvious ways at non-obvious times. Part of the problem with singletons is that they can be used to solve a problem that's better resolved with something else. If you want to serialize access to some hardware or something they can make a great deal of sense. If you want general access everywhere to your game screen, you could make a singleton out of it to expose it as global state, but doing so will make it very annoying to run split screen or whatever in the future. Regardless, the game screen should be managing all the fiddly bits for the game screen either way. Singletons are good because ordinary static fields don't solve the problem of oneness, they just provide a mechanism to hold state. If a class is a singleton, multiple instantiations of it will return the same single allocated object. Just having a static field I could allocate 100 objects assign them to the static instance and leak 99 of them. The singleton would only ever allocate 1 object. I'd really recommend picking up a book on design patterns.
|
# ? Jul 21, 2016 16:14 |
|
Sex Bumbo posted:Singletons are dumb because they're usually a pointless layer over global state that somehow manages to make it worse. They handle visibility, instances, and hide initialization order, and usually you just want to handle visibility. You either care about the order in which things are initialized or you don't -- if you do care, you should make it explicit because otherwise you need to wrap your head around some implicit system rather than just reading it. I utterly loathe lazy initialization. It's an open invitation to have random totally unexpected side-effects because oops you removed an access and now initialization happens somewhere else, especially in C++ where now you have destructors running in an unpredictable order and annoying crash-on-exit bugs to chase forever. I'm OK with global objects that are explicitly set up and torn down. leper khan posted:Singletons are good because ordinary static fields don't solve the problem of oneness, they just provide a mechanism to hold state. The only good case I can think of for lazy initialization is if you have code with a large number of entry points and having a uniform startup process would be prohibitive, like web services. Games are nearly always single entry point, so there's no point. OneEightHundred fucked around with this message at 17:33 on Jul 21, 2016 |
# ? Jul 21, 2016 17:25 |
|
If the static accessor is also a setter, you retain that control over initialization. It just means you need the discipline to write to it only during init and tests.
|
# ? Jul 21, 2016 17:29 |
|
Shouldn't be too difficult to write a setter that only allows you to set once.
|
# ? Jul 21, 2016 17:36 |
|
leper khan posted:With an emphasis on need. You definitely want to set up some sort of object hierarchy where some things conceptually own others. Part of the problem with global state is that nothing owns it so it can change in non-obvious ways at non-obvious times. http://gameprogrammingpatterns.com/contents.html There's another one I seem to remember with rabbit pictures in it, too. I can't seem to find it, but this book is pretty good too.
|
# ? Jul 21, 2016 17:57 |
|
HappyHippo posted:Shouldn't be too difficult to write a setter that only allows you to set once. Object Foo = null; Public void setObject (Object bar) { If (Foo == null) Foo = bar; } Yeah, real easy.
|
# ? Jul 21, 2016 18:34 |
|
It has implications on testability but if your mock implementation can be reset then that is no problem either because there'd be no need to call the setter a second time in tests either.
|
# ? Jul 21, 2016 18:37 |
|
|
# ? Apr 17, 2024 19:44 |
|
leper khan posted:I'd really recommend picking up a book on design patterns. yeah I grabbed Martin's book on C++ APIs you had recommended in your other post. Thanks for your advice.
|
# ? Jul 21, 2016 18:44 |