Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Workaday Wizard
Oct 23, 2009

by Pragmatica

ApproachingInfinity posted:

This is pretty much what Unity's built-in text system does (or well, they probably use FreeType or similar but same deal). Doing this is fast enough that you can, if you want to, render to that texture on-demand and just display the letters at the size/style you want without much issue. Even better, if you need the same glyph again, you just pull the one you already rendered out of the texture. You can also pre-render all the glyphs you think you'll need beforehand for even more speed. The problem with this method is that you're pre-rendering text at fixed sizes; glyphs rendered at 16 pt just aren't going to look good at 80 pt size.

One solution to this, which TextMeshPro uses, is to instead render the glyphs out and then generate signed distance field textures from them. With these you do just a bit of extra math to determine your final alpha, and you can get very smooth-looking fonts rendered at very disparate sizes out of a single glyph texture, and the texture doesn't even have to be that big. There's also certain kinds of effects (glow, soft drop shadow, among others) that become really easy and cheap to render with SDF fonts.

The issues with this method:
- Generating the signed distance field texture is, relatively, very slow. Because of how slow it is, you pretty much _have_ to pre-render all your glyphs. This means you can't easily ask for new ones on-demand. If you're localizing for East-Asian languages this can quickly become a big problem, because now you have to either pre-render a crapload of SDF textures, or try to pick which ones you think will or won't get used and add some limitations.
- At very small sizes (IMO) SDF-rendered fonts are much harder to read than with the traditional method, or at least with TMP they are. You could probably mitigate that by smoothing in the shader or anti-aliasing, but with the traditional method you'll get properly rendered fonts at exactly the size you want, every time.

Some links:

https://en.wikipedia.org/wiki/Signed_distance_function - Wikipedia's articles about these kinds of things are generally very unhelpful for me (I am a math dummy), but it's probably technically super-precise or something
https://www.youtube.com/watch?v=CGZRHJvJYIg - A video showing pretty well what the results are of SDF fonts visually

Thanks for the detailed answer :)

e: it's a new page might as well quote the whole thing

Adbot
ADBOT LOVES YOU

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

leper khan posted:

.... you just put the attributes on things. I don’t understand what the issue is.
Heh okay. The issue is that I have some rules that rely on particular GameObjects and logic with them. They don't necessarily rely on one particular MonoBehaviour. Because of that, I wasn't so sure where I'd put required attributes to replace the rules I've written.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

OneEightHundred posted:

If the text is being rendered at a single size with no rotation, scaling, or other subpixel motion (like in typical web scenarios), the best thing to do is render it at the size it's being displayed to take advantage of font hinting features that improve the legibility of the text. When that's done, there's not really much point in keeping polys around because the rasterized result is always the same.
I was thinking the rasterized font is typically larger, storage-wise, than the source truetype font data *or* the vector data, and marginally more of a pain to use than the vector data (you have to write to a vertex buffer *and* prepare and select a texture, and involve transparency, vs. just the vertex buffer if you're rendering as triangles), but the hinting and smoothing are good solid reasons to use pre-rendering, thanks.

I wasn't convinced by the n^3 algorithm argument (or others about the triangle-ing being a pain), because n is pretty small and it's a "run once at startup" thing so meh to time/complexity, and while yes conceptually triangling around holes sucks, I'm pretty sure it reduces to a "use a library" problem these days (and even if it didn't, it's an interesting problem). So outcome-based reasons are much more compelling than difficulty-based reasons.

On a related note, is there a decent library or method for inexpensively rendering text in WebGL? (Here, the most concerning expense is effort, with hardly any poo poo given about rendering time and only a small poo poo about bandwidth.)

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

roomforthetuna posted:

I wasn't convinced by the n^3 algorithm argument (or others about the triangle-ing being a pain), because n is pretty small and it's a "run once at startup" thing so meh to time/complexity, and while yes conceptually triangling around holes sucks, I'm pretty sure it reduces to a "use a library" problem these days (and even if it didn't, it's an interesting problem). So outcome-based reasons are much more compelling than difficulty-based reasons.

Yeah, it's "run once per font size, and possibly for all three subpixel positions if you want to do subpixel layout". Grid fitting, stem darkening, hinting are all complex algorithms that are very sensitive to the final pixel size of the font, and greatly distort the shape of the font.

It's a very interesting problem. Pathfinder 2 is attempting to use Lorenzetto triangulation on the CPU. Slug uses efficient bezier math on the GPU but that still kills your early-Z and has to do the bezier roots per fragment which is inefficient.

For WebGL, just render text to a separate 2D canvas using drawText, or just build a PNG/SVG text sprite sheet and supply that as your font atlas during texImage2D.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Suspicious Dish posted:

For WebGL, just render text to a separate 2D canvas using drawText, or just build a PNG/SVG text sprite sheet and supply that as your font atlas during texImage2D.
Ah! I had been thinking rendering a small bit of text to a canvas and then using it as a texture for each floating caption, or trying to overlay moving canvases in the html layout, which seems like a horrific idea, but now that someone else suggests the same premise I realize I can just overlay a single second canvas the same size as the main one, and position and size the text there, rendering whenever the GL canvas renders. Duh. Thanks.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
leper khan I have DOTWeen questions. Actually this is just Rotation Hell; I don't think anybody's going to be left out. I think I figured this out but it makes me feel gross.

I am trying to convert this tire fire that is my ring menu rotation management code into a tween, but I'm trading one problem for another. I have to rotate clockwise or counter-clockwise by the theta angle representing the angle between my ring menu elements whenever the player presses the appropriate key. I haven't even gotten into what happens if they hit one of the keys while an existing tween is running. The rotation is just fussy.

Setting it up superficially is not that hard:
code:
centerRectTransform.DORotate(new Vector3(0.0f, 0.0f, selectedItemIdx * theta), ReachNextElementTimeSec, RotateMode.LOL)
   .SetUpdate(true);
RotateMode is currently set to a fictitious LOL because all the modes have been... interesting. Let's say I have two elements because that makes brings up the dilemma. When I want it to rotate clockwise, it will do it the first time, but it will rotate in reverse to go back if I want to select the original element instead.

I tried the LocalAxisAdd and WorldAxisAdd, and these seem to try to do the right thing, but there's a compounding error factor that causes the elements to veer out of alignment at their stationary positions.

Now I just grab the rotation by the balls when it finishes and force it into the right spot at the end:
code:
                centerRectTransform.DORotate(new Vector3(0.0f, 0.0f, theta), ReachNextElementTimeSec, RotateMode.WorldAxisAdd)
                    .SetUpdate(true)
                    .OnComplete(()=> { centerRectTransform.rotation = Quaternion.Euler(new Vector3(0.0f, 0.0f, selectedItemIdx * theta)); });
This seems to work. It's kind of gross that I have to give a relative angle as an argument to DORotate while OnComplete gets the absolute angle.

Does this look at all right?

The next part of the problem is being able to handle changing this tween as it runs. I haven't looked into what I can do for that, but it has to be easier than this crap I have for the rotation logic right now:
code:
        if (moving)
        {

            // Can't use Time.deltaTime since we might be paused... then it doesn't move (why?!)
            float deltaTime = (float) (currentTime - lastWallTime).TotalSeconds;

            // theta / (time to reach next item / time last frame took) = theta * time last frame took / time to reach next item.
            float nextRotate = moveDirectionFactor * theta * deltaTime / ReachNextElementTimeSec;
            float currentAngle = centerRectTransform.rotation.eulerAngles.z;
            float nextAngle = currentAngle + nextRotate;

            // We're being fussy over hitting the cursor angle because we might change where this angle is. For a centered ring menu,
            // we would default to the cursor being straight up. However, we could put the rig menu in the corner with only a portion showing,
            // and that would put the cursor in the middle of the revealed portion.
            // It gets real ugly when we roll around zero degrees.
            float cursorAngle = 0.0f;
            float targetAngle = selectedItemIdx * theta + cursorAngle;
            //Debug.Log(nextAngle + "\t" + cursorAngle + "\t" + currentAngle);
            if((moveDirectionFactor == MovingCW &&
                (nextAngle > targetAngle && currentAngle < targetAngle) ||
                (nextAngle > targetAngle + 360.0f && currentAngle < targetAngle + 360.0f))
                ||
                moveDirectionFactor == MovingCCW &&
                (nextAngle < targetAngle && currentAngle > targetAngle))
            {
                moving = false;
                nextRotate = targetAngle - currentAngle % 360.0f;
            }
            centerRectTransform.Rotate(0.0f, 0.0f, nextRotate);
            for (int stack_i = 0; stack_i < stackImages.Count; ++stack_i)
            {
                stackImages[stack_i].rectTransform.rotation = Quaternion.identity;
            }
        }

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
I feel like I should market Godot again.
I went to add sound effects the other day, having done absolutely nothing with sound before, and it took me only 45 minutes to record, edit, learn how to do sound in Godot, load my five sounds into the editor, add them to my scripts, and then realize that I could even *not* put it in the scripts and instead attach the playing of sound into animations, and do that instead.

Which is to say, the sound stuff is super intuitive and easy, and the animation stuff is amazingly flexible.

Ranzear
Jul 25, 2013

I was waiting for 3.0 release before I tear into it, but you think it's okay to dive in a little early?

BirdOfPlay
Feb 19, 2012

THUNDERDOME LOSER

leper khan posted:

More cool, in my opinion, are all of the attributes. You can tag fields as supposed to be filled with a scene object or prefab and then it tells you if the contract is broken. There are a lot of new attributes, and many are neat/useful. Others I just haven’t bothered to get to yet :shrug:
Scene validation is an incredibly useful tool for larger projects where things can start changing out from under you.

Oh my. I may to need to get that. I've thought about how nice that would be but was never certain how you'd do that given the tools.

I also just love that kinda stuff. I'm, basically, the only one that touches stuff, but every field accessible in the editor gets a tooltip and is either bound by a Range attribute or has some sort of validation check. I've been thinking about adding something to have fixed sized arrays shown in the Inspector, but I'm currently just hacking it that way with a Validate method that forces the array to be of the proper size.

Does... does this make me a tools engineer? :ohdear:

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

BirdOfPlay posted:

Does... does this make me a tools engineer? :ohdear:
Some people would say doing that kind of stuff more than zero times makes you a tools engineer, and those people need to be against the wall.

Kind of like the people that would say you're a test engineer if you wrote a unit test.

TerraGoetia
Feb 21, 2011

A cup of spiders.
Been doing some work on the tiles for my crpg. Here's a demo screenshot:

TerraGoetia
Feb 21, 2011

A cup of spiders.
Worked on some new art for my game. Here is a screenshot of new assets:

Farchanter
Jun 15, 2008
Is there a good way to use the Unity 2D animator to change a sprite if a character goes further than a given distance? Just something like "for every ten pixels of Y movement, switch to the next frame on the spritesheet." It is probably just me, but I am having difficulty finding tutorials for how to do it with the animator, rather than pure C#.

Thanks in advance!

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Farchanter posted:

Is there a good way to use the Unity 2D animator to change a sprite if a character goes further than a given distance? Just something like "for every ten pixels of Y movement, switch to the next frame on the spritesheet." It is probably just me, but I am having difficulty finding tutorials for how to do it with the animator, rather than pure C#.

Thanks in advance!
I don't know if the Unity animator is sufficiently similar to the Godot one, but I did this kind of thing in Godot by calling a function to set the animation 'time' every frame based on the world-position of the character.
AnimationPlayer.set_speed(0);
AnimationPlayer.seek(x*DISTANCE_TO_ANIM_TIME_RATIO);

TerraGoetia
Feb 21, 2011

A cup of spiders.
I downloaded Tiled and was able to pop up a map rather quickly:



The output is a JSON file, so my next step is to read that into the game and parse the contents.

Lork
Oct 15, 2007
Sticks to clorf

Farchanter posted:

Is there a good way to use the Unity 2D animator to change a sprite if a character goes further than a given distance? Just something like "for every ten pixels of Y movement, switch to the next frame on the spritesheet." It is probably just me, but I am having difficulty finding tutorials for how to do it with the animator, rather than pure C#.

Thanks in advance!
You can do this with a blend tree. Set it to 1D, add your frames of animation in as "motions" and set it up to follow a float parameter you've created. Then you can feed in the distance with yourAnimatorReference.SetFloat("yourDistanceFloat", distance); in an update loop somewhere.

Doctor Soup
Nov 4, 2009

I have nothing but confidence in you, and very little of that.
Speaking of 2D animation, after reading about what Unity’s animator actually does every frame I’m looking into alternatives for general canvas-based UI animation. Some light research suggests DOTween is a good pick, but I’m wondering if anyone in the thread has opinions on the matter.

Also, if there is a more performant alternative to layout groups out there I would love to hear about it.

KillHour
Oct 28, 2007


TerraGoetia posted:

I downloaded Tiled and was able to pop up a map rather quickly:



The output is a JSON file, so my next step is to read that into the game and parse the contents.

I wrote something for this. It's a little basic but I'll throw it somewhere and you can modify it.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Doctor Soup posted:

Speaking of 2D animation, after reading about what Unity’s animator actually does every frame I’m looking into alternatives for general canvas-based UI animation. Some light research suggests DOTween is a good pick, but I’m wondering if anyone in the thread has opinions on the matter.

Also, if there is a more performant alternative to layout groups out there I would love to hear about it.

Tweens are ok for simple things, but more complex animations probably want something with a timeline.

What performance issues are you running into with layout groups?

TerraGoetia
Feb 21, 2011

A cup of spiders.
New assets and me wondering if the final boss should be an evil computer:

Doctor Soup
Nov 4, 2009

I have nothing but confidence in you, and very little of that.

leper khan posted:

Tweens are ok for simple things, but more complex animations probably want something with a timeline.

What performance issues are you running into with layout groups?

Basically, we did everything wrong with our last game's UI. We created deep object hierarchies with multiple layout groups, lots of animations, and only a handful of canvases. As you can imagine, basically everything ended up getting dirtied/rebuilt/recalculated each frame, which was not great for performance.

As for layout groups specifically, most of our problems would go away if we didn't use animations so it's not as big of a priority as finding an alternative animation system. That said, now that I think about it I do wish layout elements had a flag we could throw that would prevent them from traversing the object hierarchy looking for layout groups to dirty.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
I've just run into what seems to be a weird omission in the Godot engine - I'm using KinematicBody2D for all my moving parts because I hate physics engines. The move[_to] functions work pretty well for the sort of behavior I want, I can do partial physics and resolve collisions mid-frame in whatever way I feel is appropriate. For example of something I can do that regular physics wouldn't, I can transition from horizontal motion on a horizontal surface to 45 degree descending on a slope without momentarily lifting off at the corner because momentum.

Anyway, the next thing I'm trying to do is add a long aimable weapon to the player-character. My intent was to make the weapon another KinematicBody2D separate from the player character but moving so as to always stay positioned on the player character, with special cases to resolve whatever kinds of collisions might occur. The aiming requires rotation.

Which is the weird thing - there doesn't seem to be any sort of rotation functions for KinematicBody2D. I'm pretty sure if I rotate the thing by just updating its rotation value it will get all out of sync with the physics and be terrible, like it will end up overlapping with objects it shouldn't be able to. Anyone here got an idea for how to resolve this?

Failing a proper solution, the best workaround I can think of is to represent the weapon as a small KinematicBody circle at the tip of the weapon, move that with the linear move functions so as to position it where the rotating tip is trying to be, resolving collisions along the way, and then position and angle a sprite between the player and that point. But I'd really rather not - that way the weapon could potentially get its midpoint passing through a thin protrusion, for example, and it'd also be a significant pain in the rear end to implement in the first place. Or no body at all and just use free-floating collision detecting functions, but that way other things could move into the weapon.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Why is the weapon part of a kinematic body at all?

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I can't tell if I'm making a video game or a ring menu.

KillHour
Oct 28, 2007


Rocko Bonaparte posted:

I can't tell if I'm making a video game or a ring menu.

Make the ring menu standalone and customizable and sell it on the asset store.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Rocko Bonaparte posted:

I can't tell if I'm making a video game or a ring menu.

KillHour posted:

Make the ring menu standalone and customizable and sell it on the asset store.

Secret of Menu: Ring

Thermal Anomaly
Jul 1, 2017

by Cyrano4747

TerraGoetia posted:

I downloaded Tiled and was able to pop up a map rather quickly:



The output is a JSON file, so my next step is to read that into the game and parse the contents.

What language are you using? If it's C# you can use the TiledSharp library to easily read and parse Tiled maps from their native .tmx format

EDIT: Also I think I made something like what you're working on for the game jam contest earlier this month, so let me know if you need any advice or code samples

Thermal Anomaly fucked around with this message at 21:52 on Jan 25, 2018

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

OneEightHundred posted:

Why is the weapon part of a kinematic body at all?
Because it should collide with things, and not intersect with them. And other moving things should collide with it. Is there something better for it to be? I don't want it to be a rigidbody because then it would try to drift away on its own any time something touches it, and would get all the floaty shitness that comes with standard physics engine behavior. I'm pretty much only using the physics engine for collision detection, anything that moves is a KinematicBody2d. I also don't want the weapon to be represented as a series of standalone collision checks because then things could pass through it during their turns at moving.

It's not part of a kinematic body, it is a kinematic body. Though it's linked to the wielder, so inverse kinematics might happen as part of collision resolution.

An example of a collision resolution I want that might explain better; if your weapon is a lance, and you charge it point first into a stone wall, you get knocked off your mount or break the lance. If you ride through a doorway with the lance pointing up, on the other hand, it should just rotate out of the way because leverage. It's not just a "hit monster" thing, it interacts with any objects.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

roomforthetuna posted:

An example of a collision resolution I want that might explain better; if your weapon is a lance, and you charge it point first into a stone wall, you get knocked off your mount or break the lance. If you ride through a doorway with the lance pointing up, on the other hand, it should just rotate out of the way because leverage. It's not just a "hit monster" thing, it interacts with any objects.
I don't think it supports doing that. Kinematic bodies use a different, specialized physics simulation that AFAIK only support movement and not rotation and its kick-out behavior is already pretty limited.

Your best bet is probably going to have to do be doing something like doing rotations separately and using is_colliding to figure out if the rotation caused an overlap, then figure out the nature of the overlap and resolve it iteratively.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

OneEightHundred posted:

I don't think it supports doing that. Kinematic bodies use a different, specialized physics simulation that AFAIK only support movement and not rotation and its kick-out behavior is already pretty limited.
Yeah, I like the kick-out behavior very much (that it's not actually kick-out if you're using it right, but rather reject the movement in the first place, stopped at the point of impact, and then you can go on to resolve the incomplete part of it yourself). But the lack of support for rotation was an unpleasant surprise. :(

quote:

Your best bet is probably going to have to do be doing something like doing rotations separately and using is_colliding to figure out if the rotation caused an overlap, then figure out the nature of the overlap and resolve it iteratively.
Ugh. :(
I know modifying kinematic bodies other than with the move functions sometimes has just horrifying side-effects, from trying to teleport a character by updating its coordinates (it ends up colliding with stuff where it used to be, in the next frame). Maybe that's just problematic if you mix coordinate changes with move functions though.
I'd be okay with the weapon being moved only by direct updates, I could probably even make it a trigger-only kinematic body.
Thanks, that will probably work, though I'm nervous because of that prior side-effects experience.

TerraGoetia
Feb 21, 2011

A cup of spiders.

Thermal Anomaly posted:

What language are you using? If it's C# you can use the TiledSharp library to easily read and parse Tiled maps from their native .tmx format

EDIT: Also I think I made something like what you're working on for the game jam contest earlier this month, so let me know if you need any advice or code samples

I'm working in Java, using LWJGL. When I have some time to work on my map importer I'll take a look at that. Thanks!

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I'm starting to do some strange things in Unity and need to think out loud and compare. I am dabbling in making my player controls events that fire off. Different parts of the system attach and detach as they are active or inactive. First, this is looking like it will be kind of inefficient with directional control. Should I not be too disturbed by that? The alternative is a polling loop checking for directional controls instead of an event firing that off each frame.

The second issue is this attachment process is touchy when starting up. If the subsystem checking controls and firing events isn't set up yet, then I'll get null pointers trying to attach to it. I started to dabble in giving the subsystem a callback queue to check on each Update(). I send the attachment requests to that so I know I'm in a good spot when it finally does the attachment. The alternative is to use coroutines. It wouldn't really be an issue if I needed to give the subsystem to the callback to do some processing, but I'm not taking any arguments, and I'm not returning any values. So I believe a coroutine could do it fine. It's hard to tell though if the coroutine happens at the beginning of the Updates() or at the end; I could theoretically be losing a frame before I even get a chance to run the code. In that case, I guess I should start doing this callback queue thing.

It's not too alien an idea to me to do this. I'm used to having to schedule tasks to run on other threads in other projects, for example.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Rocko Bonaparte posted:

I'm starting to do some strange things in Unity and need to think out loud and compare. I am dabbling in making my player controls events that fire off. Different parts of the system attach and detach as they are active or inactive. First, this is looking like it will be kind of inefficient with directional control. Should I not be too disturbed by that? The alternative is a polling loop checking for directional controls instead of an event firing that off each frame.

The second issue is this attachment process is touchy when starting up. If the subsystem checking controls and firing events isn't set up yet, then I'll get null pointers trying to attach to it. I started to dabble in giving the subsystem a callback queue to check on each Update(). I send the attachment requests to that so I know I'm in a good spot when it finally does the attachment. The alternative is to use coroutines. It wouldn't really be an issue if I needed to give the subsystem to the callback to do some processing, but I'm not taking any arguments, and I'm not returning any values. So I believe a coroutine could do it fine. It's hard to tell though if the coroutine happens at the beginning of the Updates() or at the end; I could theoretically be losing a frame before I even get a chance to run the code. In that case, I guess I should start doing this callback queue thing.

It's not too alien an idea to me to do this. I'm used to having to schedule tasks to run on other threads in other projects, for example.

You can use a ScriptableObject to do what you want. Have your input manager call an InputChanged function or w/e and have things what care about input subscribe to it.

No NRE issues, because the ScriptableObject /will/ exist, and that’s what everything is told about inputs from. Then you can do the Mario hat thing by swapping which input manager (player vs ai) they’re listening to.

see also this Unite talk

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Okay okay time to get into ScriptableObjects.

Edit: Pardon my frustration, but it's frustrating to me that the Unity developers decided, "Hey let's make this really important thing that we think can solve a lot of problems for you, then make a little lovely dilly in the docs about it and put everything else about it into videos. Our users are visual learners that don't read or write code so it's perfect!" I know I'm pissing in the wind about it, but it's particularly stark here with ScriptableObjects.

Rocko Bonaparte fucked around with this message at 18:49 on Jan 29, 2018

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Rocko Bonaparte posted:

Okay okay time to get into ScriptableObjects.

Edit: Pardon my frustration, but it's frustrating to me that the Unity developers decided, "Hey let's make this really important thing that we think can solve a lot of problems for you, then make a little lovely dilly in the docs about it and put everything else about it into videos. Our users are visual learners that don't read or write code so it's perfect!" I know I'm pissing in the wind about it, but it's particularly stark here with ScriptableObjects.

You need to appreciate the purpose of the unity docs. They’re actually really good for some things, but you need to keep a bit of cynicism.

Unity was originally a game engine for hobbyist game developers only usable on OSX. The documentation and “best practices” found therein reflect this, and essentially act as mitigations for customer support tickets.

This is the same reason they recommend serializing fields by making them public and explicitly state that you may never end up using [SerializeField]. Every organization I’ve worked in this is almost the opposite. There is a mechanism to serialize to the editor that does not mess with member visibility; it gets used frequently.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Okay I'll try to go through what I did to start using a ScriptableObject, but it's extremely contextual. I'm also not done, which I'll try to highlight.

I put the events and InControl ControlActions into a ScriptableObject. The OnEnable sets up all the events; each button is wrapped up in a object that is has the actual event and the logic to do the per-frame poll to fire them. The idea is this is the one place I poll on them. Maybe that logic should come out of there and go into the control subsystem now.

At the moment, this ScriptableObject is created and owned by the control subsystem, which is hanging off my global state singleton with all the other subsystems. It's OnEnable() creates the ScriptableObjects. At this point, everything trying to subscribe for events do that in Start() so I don't have to worry about an NPE. However, I'm conceptually not done. I think the next step is to attach the ScriptableObject directly to something. It will probably be the global state GameObject itself. Everything will just retrieve the record from there instead.

I got the impression that they were trying to use ScriptableObject to somewhat avoid having these global states. I don't really see how that works. I could create the thing the first time I need it and then otherwise just have Unity scan for the item, but to me that seems pretty much the same as having some global GameObject anyways.

Ranzear
Jul 25, 2013

Godot 3.0 is out.

Doc Block
Apr 15, 2003
Fun Shoe

:woop:

It took me way too long to figure out they renamed Globals to ProjectSettings

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Is it going to ruin everything if I try to transition my existing project?

Adbot
ADBOT LOVES YOU

Nude
Nov 16, 2014

I have no idea what I'm doing.
It seems like Godot wants to be a serious contender for both 2D and 3D game development. With C# (7!) support does anyone know how it compares to Unity? Right now I see it as something that's growing and to keep an eye out for. Would love to hear anyone else's thoughts.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply