❔ static class
Hey. I'm trying to define a static class. My static class's methods are almost entirely all functions of variables not in my class. However, I do want to initialize a reference to one thing, to an instance of a singleton, so I don't need to call GetInstance() (and all the baggage associated with calling it) every time I run a function from my static class.
Q: Is there a way to store a reference to an instance as a variable in a static class at runtime?
10 Replies
A static class can have static field as well
You can use a static constructor, ig?
Just like a regular class can have regular fields
But if you rely on static classes this much, something might be fucky-wucky with your architecture as a whole
maybe I could show you my code to see if this makes sense
assume that little error is a real singleton.
Would the code that I just wrote actually be like a real constructor for my static class? which lets me just make a bunch of functions that use that static variable without concern?
A static constructor runs once, IIRC when the static class is first accessed
And, yeah, it should save that instance in your
tileDirectory
sweet. I'll give it a whirl. ty.
it worked great. ty so much
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.