ELI5: How do video games handle things off-screen?

r/

I’m not very tech savvy, so forgive me if this is dumb, but I’ve been wondering about this. If I’m playing an RTS game, say Starcraft or something, does everything not in front of me on my screen still “exist?” is every unit and building still being processed by my computer just the same? Or in an FPS game is everything in the level, every part of the map, every enemy always there?

Comments

  1. IAM_Carbon_Based Avatar

    Yes, everything is there, in the game memory, and it renders once you move to that area. Just like real life, it’s all there you just can’t see it untill you look.

  2. CanadaNinja Avatar

    Pretty much all of it exists, as in the game engine keeps track of the OBJECT of everything (see object-oriented programming to understand the specifics of that), which is each “thing” in the game. This means the calculations for that object are still happening.

    However, the engine is probably not rendering the object, as in it’s not “drawing” the image at all until you turn the camera to look at it.

    Sometimes engines do more complex things to be more efficient and have certain, unimportant objects cease to exist at all when not looking (like cyberpunks NPCs) but most of the time they still exist

  3. --Ty-- Avatar

    At an eli5 level, the answer is yes and no, it depends on the game.

    For an RTS, yes, everything, including enemies hidden in the fog of war, are still loaded into memory. They need to be in order for the game to run calculations on them, to know what they’re doing and where they are, so that they can emerge from that fog of war and do stuff to you, or to other ai players. However, other elements, like the graphical appearance of a tile, will NOT be loaded and rendered. What I mean by this is that the game is rendering a fog texture INSTEAD of the appearance of the tile beneath it, it’s not rendering the tile and then also rendering the fog on top. Instead, the tile is left un-rendered visually, and only comes into being when the fog is dispelled. 

    For an FPS, if it’s a single-player, narrative or action game, the game typically only renders what’s in your immediate vicinity, or in the immediate “level space”, such as the courtyard you are fighting in. 

    With really big, very detailed games, the game world sometimes stops rendering everywhere except for where you’re actually looking, to save on GPU processing. Enemies behind you and the like can still be loaded into memory, and can still fire at you and such, but the graphics won’t be rendered until you turn your camera to look at them. 

    With online games, such as a multiplayer fps, the entire map is loaded at all times. 

  4. GoatRocketeer Avatar

    depends.

    If there’s a reasonable chance you’ll run into something pretty soon, or if it wouldn’t make sense to freeze the entity in time or reset its behavior, then it’ll exist even offscreen.

    But maybe there’s some small enemy or item which you wouldn’t generally notice if it froze or reset behavior, in which case the game might do one or the other.

    For example, in minecraft there’s a certain range beyond which mobs stop moving. There’s a secondary range even further out where hostile mobs will automatically despawn (unless “saved” by putting them in a boat or putting a nametag on them).

  5. matchuhuki Avatar

    This is something called culling. Where certain things are purposely not rendered. So if something is outside of your field of view, or it’s too close to the camera that it would block your view, or it’s facing away from you, it won’t be rendered. Now that doesn’t mean it’s not there. That just reduces it to a simple number indicating its position essentially. Once the camera changes, or the object moves into view. The calculations happen again to determine the colour, reflection, shadows etc. All the heavy stuff that needs to happen to show it on screen.

    There’s also LODs which is like a middle step. Stands for level of detail. When something is far away from the camera. It doesn’t need to be as detailed. We can leave out some edges, leave out some colour and shadows. To save processing power but still having it visible on the screen if it’s relevant to the player.

  6. yourdiabeticwalrus Avatar

    For single player games, the only things that “exist” , are the things you can see on the screen, if by “exist” you mean “computer is drawing (rendering) the thing”. Think of it as a big cone coming out of your character’s eyes that encompasses everything you can see. Everything in that cone is rendered, everything outside that cone doesn’t get rendered. Things outside the cone do “exist” in a literal sense, they’re just waiting on the cone to pass over them in order for the computer to render them.

  7. jepperepper Avatar

    it exists as a model in memory but is not rendered on screen (in graphics memory) to allow for high frames per second.

  8. nutcrackr Avatar

    Mostly yes, but some engines don’t load stuff that isn’t on screen. Levels in an FPS game can be comprised of multiple separate parts. If you’re not in that part of the level, it effectively doesn’t exist and is waiting for you to get to a hallway so it can load. One thing most engines do, even if the levels are not split into parts, is using LOD transitions. If something is far away from the camera, it will render a much lower polygon version and will probably do a simpler physics calculation.

  9. floopsyDoodle Avatar

    data is far less intensive for hte computer to track, it’s visuals that really slow things down. Sow hen it’s out of sight (there are many ways to track that, your view, distance, etc), it’s no longer being rendered but the data behind it is still there, like:

    zergling_34: health: 123, position: 12,322,42 (x, y, z cordinates), actions: waiting

    and it’s updating constantly, but just never being rendered to the screen till necessary to save on processing power.

  10. stephanepare Avatar

    You’re approaching things backwards. First, the game needs to calculate an object’s boundaries and actions.Then, the game decides which of them it’s going to draw. You don’t need to draw something for it to exist, because it had to be loaded in the game’s memory before it starts drawing it on screen.

    As to whether everything in a whole map or level is loaded, each game makes decisions on what’s essential to keep track of accurately, and what can be off-loaded until absolutely needed.

  11. davidgrayPhotography Avatar

    Yep, stuff is “always there”, but not in the way you’d think.

    Drawing lots of stuff to the screen can be very taxing on your computer, so programmers take liberties with what they draw onto the screen.

    If the player can actually see something, it’ll get drawn. This means that if you’re looking at the front of a building, the back of the building won’t be drawn (there’s no point because you can’t see it, right?) so likewise, everything that’s behind you doesn’t get drawn until you turn around to look at it because doing all the maths and such to draw something you can’t see is just a waste of time. This applies to everything, even a sheet of paper

    So when you’re playing an RTS and your units aren’t on the screen, the computer remembers where they were, but just doesn’t draw them until you scroll over and look at them.

    A very simple way of visualizing this is by thinking that the game has two functions, drawToScreen() which does things like check where on the map you’re looking, check if there’s units there, grab the images needed to draw everything that can be seen, then draw it, and an updateUnits() function which doesn’t care where you’re looking, but will find every unit on the map, run their AI logic to determine where they should move, then update their position so they’re there.

    And sometimes that “move units” thing is instant. If it would take a unit 10 seconds to move from X to Y, you don’t need to “move” them step-by-step if they’re not on screen. You can just wait 10 seconds then teleport them

    It’s WAY more complex than that and every game does this differently, but hopefully this helps.

  12. Vadered Avatar

    It very much depends on the game. For many modern games, especially ones on relatively small maps like Starcraft, the answer is yes, everything is on the map from the beginning and aside from graphical fidelity is treated the same whether on screen or not. But not all of them.

    Minecraft, for instance, doesn’t generate or update chunks of the world until a player is within a certain distance of them. This way the game only needs to run calculations when the player moves from area to area, rather than needing to track everything happening on the map in real time, at all times. The effect is mostly the same as if you tracked everything all at once, but not quite.

    But in some older games, the answer is a flat out no. In some older NES games, enemies are spawned when the part of the level they are on is scrolled on screen, and despawn once they are far enough off screen – even if you then immediately move in the direction they were going. This is a clunky way of doing things and modern games tend to avoid doing stuff like this because it’s REALLY obvious and feels too video gamey rather than immersing you in a world, but it certainly is a way of handling things off screen.

  13. idiotcube Avatar

    Everything in a game is just the computer doing math. To make the game run better, the programmers try to make sure that it’s not doing any math that isn’t useful. The math that tells the computer how to handle graphics only needs to be done for things that the player is looking at, so programmers try to keep track of which objects are in your field of view, and only do the graphics-math for those.

    But not all the game’s math can be ignored just because the player isn’t watching. If a unit in Starcraft was told to move to the other side of the map, but stopped moving when your camera wasn’t pointed at it, you’d think the game was broken! So the math for things like NPC behavior, physics, and other basic information about the game world keeps getting done no matter where the player is looking.

  14. QuietCormorant Avatar

    No spoilers but if anyone has played the Outer Wilds expansion, this concept is used in a cool way. Shout out to my favourite game of all time.

  15. GrndControlTV Avatar

    To add to everyone else’s answer, this is how cheats are made, because all of it is still happening and when you read the memory you can see the data that’s usually hidden by fog of war or walls and things in the way.

  16. wutzebaer Avatar

    The game is split in two parts. One part runs the logic updates positions of objects and updates the camera position when you move the mous3 etc but just raw coordinates and data. The other part fetches the camera position und objects near the camera position and draws your view with it.

  17. Vineee2000 Avatar

    So there’s a lot of mostly correct answers in the thread at this point, but they’re all quite technical, I wanna try for more of an eli5

    Basically, everything that’s not directly in front of you is still remembered and tracked by the game, but it’s not drawn. Essentially, the game remembers a bunch of numbers about every single object, – be that a unit, a building, a character, etc., – as well as a bunch of technical info, and it usually keeps updating those numbers and technical info so that it knows what the object is doing. But it’s all just numbers and functions, no picture – because pictures are really expensive, so only stuff on your screen is actually drawn

    For example, if you look away from a building in Starcraft, the game will still keep track of its coordinates on the map, its production state, queue, hp, etc. It will even remember what animation the building is playing (e.g. glowing windows to indicate it’s building stuff), and which step of that animation it was, and it will keep ticking those states – but it won’t actually draw that animation to be shown to the void – it will just keep refreshing the numbers on it so that the exact frame you look back, the game is ready to draw everything perfectly consistently as if you never left

  18. sessamekesh Avatar

    The game is keeping a pretty detailed list of everything in the game all the time.

    The part you see is a picture that one sub-system in the game engine (the renderer) paints to illustrate what’s going on in that world.

    Some things sorta disappear, but only sorta. There’s a really cool GIF of this happening in Horizon Zero Dawn, where you see grass, trees, and mountains disappearing when the player looks away. The game still knows they’re there, but doesn’t bother with all the details like which exact way they’re swaying in the wind (which only matters for drawing, and not for gameplay).

  19. Weeznaz Avatar

    Let’s give an example, Call of Duty. In the campaign the entire mission does not exist at the same time. What needs to exist is what the character can see without aiming, and kind of see what is far away. The objects closest to you are given higher quality textures then objects farther away. Depending on where you are standing then certain assets can dissappear or reappear. If a building explodes and rubble is everywhere that is not that building being destroyed, that is one building that was created to be upright being replaced with a separate model of a building which is destroyed. The developers try to hide the instantaneous switch of models by adding smoke effects, or shaking the player camera. Not all enemies spawn at the same time. Depending on where your player character is standing, different enemies might appear. If you walk forward past an arbitrary line, then a tank will spawn from seemingly out of nowhere, but this is hidden due to the tank spawning behind a building.

    Multiplayer games… I’m not as familiar with how everyone manages to see the same world at the same time.

  20. tinmetal Avatar

    At a high level the game only keeps track of exactly what it needs to keep track of. This can change from game to game depending on what the creators want. If you want your game to appear big or more detailed you have to be clever in how you “trick” your players into thinking it is. A game developer will usually only show or keep track of what is necessary to maintain the illusion.

  21. LBPPlayer7 Avatar

    it very much depends on how the game optimizes things and what it deems to be important

    some things just don’t spawn out of view, some things stop existing out of view, but if they’re deemed to be important, they persist for as long as it’s reasonable to, and even then, some games simplify the logic of those things if they’re far away as you likely wouldn’t notice anyway

  22. ryujin_io Avatar

    They still exist – as game data. Even when you don’t see things on screen, a game’s engine will still apply various processes and routines to them as needed by the game’s design (AI, movement, physics etc.). Modern game engines are optimised to understand not to apply irrelevant routines such as rendering (e.g., drawing them on the screen) if it knows you won’t see it anyway.

    And it’s not just games that so this. Even an every day mobile app applies these techniques. Sayo you’re browsing a list of products on a scrolling list of search results. Your screen can maybe just show 5 or 6 rows at a time but the app keeps a much longer list in memory and updates the contents of the visible rows really fast to keep the scrolling experience smooth.