r/Unity2D

Image 1 — Movement Issues(Visual Scripting)
Image 2 — Movement Issues(Visual Scripting)
Image 3 — Movement Issues(Visual Scripting)

Movement Issues(Visual Scripting)

(Thank you to everyone who helped me with my last issue!) So, I have got the jump working, however when I move horizontally I am unable to jump, and when I jump THEN move horizontally gravity hardly affects it and I end up gliding down to the ground. I know this is caused by x movement constantly overwriting my falling but I have no clue on how to fix this. Any help would be appreciated!

(Sorry for the bad image quality again, my computer refuses to take screenshots)

u/Thenextlevel247 — 21 hours ago
▲ 9 r/Unity2D+1 crossposts

Just announced SubDuctis, my upcoming space folding puzzle game!

SubDuctis is a Sokoban-style puzzle game that explores space folding. In this game, the player must utilize special 2x2 pushable blocks called "splicers". When activated, a splicer and its pair will fold away all tiles that lie between them. This can be used to pass over obstacles, connect distant objects, and more.

The full game will feature over 100 puzzles, nonlinear progression, and secret areas.

Please consider adding SubDuctis to your Steam wishlist to support the game!
SubDuctis on Steam

u/quintin-steiner — 1 day ago

How to get an instance of an object to reference an instance of a different object?

In my game I make instances of 2 seperate objects and when the player spawns one, the other one also spawns. The player can spawn multiple instances of the same object so I need to track and link the 2 seperate objects and only the objects that spawn together. I've given both of the objects unique ids when they spawn in but I don't know where to go from here. I want to be able to reference variables and sprite renderers and things like that.

Object One's script:

using System;
using UnityEngine;

public class FishTab_MB : MonoBehaviour
{

    public Guid UniqueId { get; }

    public FishTab_MB()
    {
        UniqueId = Guid.NewGuid();
    }
    private void Start()
    {
        print("FishTab_MB UniqueId: " + UniqueId);
    }
}

Object two's script:

using System;
using System.Collections;
using Unity.VisualScripting;
using UnityEngine;

public class FishAI_MB : MonoBehaviour
{

    SpriteRenderer fishSr;

    public Guid UniqueId { get; }

    void Start()
    {
        print("FishAI_MB UniqueId: " + UniqueId);
    }

    public FishAI_MB()
    {
        UniqueId = Guid.NewGuid();
    }
}
reddit.com
▲ 40 r/Unity2D+7 crossposts

We’re a small team of friends who make trailers & video content for indie games, and we just launched our new website!

Hey everyone! 👋

I’m Brad, founder and creative director of ByCherryMedia.

We’re a small creative team specialising in trailers, gameplay editing, devlogs, social content and other video/creative work for games. We’ve just finished rebuilding our website, so I wanted to share it here and introduce ourselves properly.

We’re a small group of friends who have known each other for a long time. We originally met online playing Call of Duty: Ghosts back in 2014. Over the years we all went in different directions, built different careers and picked up different skills. But gaming was something that always kept us connected. Eventually we thought, why not put our skills together and build something around gaming? And that’s basically how ByCherryMedia happened.

Today we’re a small team covering video editing, game capture, motion graphics, music, sound, and localisation. I’m personally responsible for most of the creative/video side of things, with the rest of the team helping across the different areas.

We’ve had the opportunity to work and build relationships with some really amazing game developers from all over the world this last year:

VaultBreakers Map Overview (now unlisted)
VaultBreakers Playtest Showcase (we’ve helped amass over 1 million views for VaultBreakers on YouTube!)
Slumber Realm Trailer
Swimpossible! Launch Trailer
Relooted Demo Trailer

And our new website is finally LIVE - bycherrymedia.com

We’ve tried to make the process as transparent as possible, particularly around pricing. One of the things we’ve added is a pricing estimator, where you can select the type of work you’re looking for and build up an estimate based on the scope and requirements of your project. So rather than having to contact us just to ask how much a trailer or social edit would be, you can get an estimate yourself before even reaching out!

We’re currently taking on a limited number of projects over the next month or so. We’re deliberately keeping the number limited because we’re still a small team, and we’d rather work with a handful of developers and give their projects the attention they deserve than take on everything that comes our way.

If you’re working on an indie game and need a trailer, gameplay video, devlog, social content, motion graphics or something more custom, please check us out!

And if you’re not looking for anything right now that’s completely fine too, we’re always happy to meet other developers and see what people are working on!

Thanks for reading if you’ve gotten this far :)

- Brad

bycherrymedia.com
u/BradCherryEU — 1 day ago
▲ 115 r/Unity2D+1 crossposts

pixel designer Looking for work

Looking for work (pixel designer)

Hi everyone, I'm 17 and from Norway, I speak Russian. I dropped out of school to pursue my project, but I'm also looking to take on small paid commissions. I'm good at drawing tilesets and environment details, and I also have experience with indoor and UI. Below are my works.

u/Dazzling_Ant_7347 — 2 days ago
▲ 12 r/Unity2D

Welcome _Guns to the Mod Team

Please join us in welcoming u/_Guns to the r/Unity2D moderation team!

They’ll be helping us keep an eye on the mod queue, deal with spam and other unwanted content, and generally help keep the subreddit running smoothly.

As the community continues to grow, having another active pair of hands will help us respond to reports more consistently and keep things organized behind the scenes.

Welcome aboard, _Guns!

reddit.com
u/GuideZ — 1 day ago
▲ 4 r/Unity2D+4 crossposts

Lessons from building a deal-aggregator app: expiring content is a harder cache problem than I expected

Native Android, Kotlin. The app aggregates time-limited free-game offers from a bunch of storefronts. Sounds like a simple list screen. The expiry semantics are what made it interesting.

A few things I got wrong first time:

Stale data is worse than no data here. A normal feed can be five minutes behind and nobody dies. In this app, a five-minute-stale card means someone taps through to an offer that just closed and concludes the app is broken. I ended up [describe your approach — server-side refresh cadence, TTL, invalidation on open].

Countdowns and lifecycle. Every card renders a live countdown. Naively that's one ticker per visible row and the list stutters. I moved to [single ticker driving state / whatever you did] and made sure it stops on onStop so it isn't burning cycles in the background.

Device clock lies. People's clocks are wrong, sometimes by hours, and timezones make "2 days left" ambiguous. Everything is stored as UTC instants and I [compute offsets against a server timestamp / etc.] rather than trusting local time.

Sorting by expiry means the list reorders under the user's thumb. Genuinely annoying if you don't handle it. I [describe: stable keys, no resort while scrolling, etc.].

Offline. The list has to render from cache the moment it opens, then reconcile. Room + [your setup].

Happy to go deeper on any of it. The app is GamesBolt if you want to see the result: https://play.google.com/store/apps/details?id=com.auragames.gamesbolt

If anyone's solved the "list that reorders itself while you're reading it" problem more elegantly, I'd like to hear it.

u/Arslanchaudhry — 2 days ago
▲ 11 r/Unity2D+1 crossposts

How to start learning how to animate as a programmer

I am a programmer first. Been learning myself how to draw and I can help myself out in that regard. I am a solo dev working on a card game but I want to start introducing card animation for for instance opening cards from a pack etc.

This seems daunting to approach as I don't even know where to begin. Any tips?

reddit.com
u/TikiNL — 2 days ago
▲ 30 r/Unity2D+1 crossposts

Are you accessing and changing variables too much from outside a class? The dangers of getters/setters

Note: This is aimed more at beginners. Experienced programmers will likely know this stuff. But even the veterans among us might find something useful here.

The nature of Unity's component-based design can make it very easy for objects/classes to modify each other's variables (fields). For example, say we're making a dungeon crawler, and we're using some good design principles like having our Health in one component, our Equipment in another component, and our BattleStats in a third component.

This kind of code is very common:

private void AttackEnemy(Fighter target)
{
    int baseDamage = CalculateMyDamage();
    baseDamage -= target.CalculateMyDefense();
    target.myHealth.current -= baseDamage;
    if (target.myHealth.current < 0)
    {
      target.PlayOnDeathAnimation();
      int xp = target.CalculateEarnedExperience();
      myXPComponent.xp += xp;
    }
}

It's not terrible. We are intelligently using functions like CalculateMyDamage, CalculateMyDefense, and CalculateEarnedExperience rather than writing that stuff in our AttackEnemy function.

However, we're still tightly coupling the attacker and defender. The attacker shouldn't be responsible for checking to see if the defender is dead or not. It shouldn't be responsible for 'knowing' when to play the death animation. In fact, it shouldn't even be responsible for changing the defender's HP at all.

Because imagine if we now introduce damage from terrain. We make a new object called a Hazard, and it deals damage every second. If we keep writing code the same way, we might end up with:

private void CauseHazardDamage(Fighter target)
{
  int baseDamage = CalculateMyHazardDamage();
  baseDamage -= target.CalculateMyDefense();
  target.myHealth.current -= baseDamage;
    if (target.myHealth.current < 0)
    {
      target.PlayOnDeathAnimation();
      int xp = target.CalculateEarnedExperience();
      myXPComponent.xp += xp;
    }
}

You can already see that this is essentially duplicated from AttackEnemy, which is a red flag. For example, what if we want the roll for treasure when an enemy dies? Well, now we have to add code like this to both functions:

if (UnityEngine.Random.Range(0,1f) <= target.GetTreasureChance())
{
  Treasure reward = target.GenerateTreasure();
  // do spawn logic here
}

Then what if we want to add an effect to some Fighters where they have a chance to avoid a fatal blow? We might need to amend the code again for both functions:

  target.myHealth.current -= baseDamage;
  if (target.myHealth.current < 0)
  {
    if (target.HasStatus("avoid_fatal_blow") && UnityEngine.Random.Range(0,1f) <= AVOID_FATAL_BLOW_CHANCE)
    {
      target.myHealth.current = 1;
    }
    else
    {
      // regular 'on death' code
    }
  }

Or what if Fighters can have other status effects or items that react when they take damage? Suddenly, we have code that could look like this:

private void CauseHazardDamage(Fighter target)
{
  int baseDamage = CalculateMyHazardDamage();
  baseDamage -= target.CalculateMyDefense();
  target.myHealth.current -= baseDamage;
  
  if (target.HasStatus("reactive_damage_ability"))
  {
    // do some cool stuff here
  }

  if (target.myHealth.current < 0)
  {
    if (target.HasStatus("avoid_fatal_blow") && UnityEngine.Random.Range(0,1f) <= AVOID_FATAL_BLOW_CHANCE)
    {
      target.myHealth.current = 1;
    }
    else 
    {
      target.PlayOnDeathAnimation();
      int xp = target.CalculateEarnedExperience();
      myXPComponent.xp += xp;
      if (UnityEngine.Random.Range(0,1f) <= target.GetTreasureChance())
      {
        Treasure reward = target.GenerateTreasure();
        // do spawn logic here
      }
    }
  }
}

It just turns into a nightmare. Now there are a lot of ways to architect your code so that you don't mire yourself in scenarios like this. But for the purposes of this post, I want to focus on this idea:

If you find yourself directly getting, modifying, and setting variables that belong to other objects, this should tell you that you may be writing difficult-to-maintain code.

We could have realized this as soon as we wrote this line:

target.myHealth.current -= baseDamage;

Without going into excessive detail, a far more maintainable approach would be something like this.

private void AttackEnemy(Fighter target)
{
  // We can play VFX/SFX here...
  int baseDamage = CalculateMyDamage();

  // But we trust the TARGET to figure out what to do with the damage we calculated
  target.OnAttacked(this, baseDamage);  
}

private void OnAttacked(Fighter attacker, int baseDamage)
{
  int defense = CalculateMyDefense();
  baseDamage -= defense;
  OnDamageReceived(attacker, baseDamage);
}

// This logic is split out from OnAttacked, because we could certainly take damage from things
// OTHER than an 'attack'. For example, if we are poisoned, that might ignore defense completely.
// In that case we would just run OnDamageReceived(poisonDamage).
private void OnDamageReceived(Fighter attacker, int damageAmount)
{
  // This function SHOULD NOT know or care what each StatusEffect we have does.
  // We will trust the StatusEffects themselves to take this and modify it how they see fit.
  foreach(StatusEffect se in myStatusEffects)
  {
    damageAmount = se.OnDamageReceived(damageAmount);
  }

  // Our status effects may have reduced our damage to zero!
  if (damageAmount == 0)
  {
    // Play some kind of 'DEFLECT!' vfx and sfx.
    return;
  }

  myHealth.ReduceHealthFromDamage(attacker, damageAmount)
}
 
 // ---- now we are in the HealthComponent class -----

private void ReduceHealthFromDamage(Fighter attacker, int damageAmount)
{
  current -= damageAmount;
  OnHealthChanged();
  if (current > 0) return;
  OnTookLethalDamage(attacker);
}

private void OnTookLethalDamage(Fighter whoKilledMe)
{  
  // Like with OnDamageReceived, perhaps we have status effects that do crazy stuff IF we were to take lethal damage
  // We might run through them and exit if any of them bring us >0 again.
  foreach(StatusEffect se in myStatusEffects)
  {
    current = se.OnHealthReducedToZero();
    if (current > 0)
    {
      // Hooray, we survived somehow!
      OnHealthChanged();
      return;
    }
  } 

  OnDeath(whoKilledMe);
}

private void OnDeath(Fighter whoKilledMe)
{
  // ... give whoKilledMe rewards or something!
}

This isn't perfect, and there are many things we could do to improve it further, but nonetheless it separates our 'concerns' far better.

* If we want to add some kind of new block/parry mechanic, we just have to do it in one place: OnAttacked
* If we make new StatusEffects, we don't have to write any new code whatsoever in these functions
* If we want to change what happens on Fighter death, there's just one function that handles it
* If we add new sources of damage - traps, hazards, poison, cursed gear, etc - our existing functions handle it all seamlessly

... and so forth and so on! I hope you find this helpful. My goal isn't to prescribe a specific solution to code architecture as every game is different, but just to recognize overuse of getting/setting variables from outside the object or class as a potentially bad 'code smell'.

reddit.com
u/zirconst — 2 days ago
▲ 94 r/Unity2D+1 crossposts

Procedural PNG, WIP

42 parts with 8 knobs. Using 2D Renderer, doesn't create any PNGs. Layers, pixels all created in code. Able to add/remove Skin layer. Fat simulation (See Image 3). Defomities (Image 4). Every creation is from a seed. A seed can be called and will return the exact creation.

What's not in the photo: I've since added more modifiers like Accuracy, based on Eye placement, Body Symmetry and other deformities. Stability is low center mass, wide stance, etc.

There are other Mutations, Tails, Horns but are rough drafts. Tails are fairly uncanny with skin. Would likely change this if I end up using it. Horns are the most believable looking out of the mutations.

EDIT: appologies, title is a little misleading this isn't a "Procedural PNG" its just using the renderer. However I can export any seeded creation to a PNG!
EDIT#2: Link to next post: https://www.reddit.com/r/Unity2D/comments/1vtpyzn/pixel_hitboxes/

u/MojoBubu — 3 days ago
▲ 49 r/Unity2D+3 crossposts

Roguelite Deckbuilder Tower Defense

Hi! I'm building a Tower Defense game with RTS elements.

You can move your units around, give them orders, and reposition them during combat.

During each run, you receive upgrade cards that can add effects such as Electric, Poison, Ice, etc. These upgrades are stackable, so you can combine effects like Electric + Poison on the same unit.

After each run, you can improve your units, purchase upgrades, and create builds.

There's also a Combinator system where you can create your own items. You can select or remove individual properties and keep only the effects you care about, allowing you to build items specifically around your strategy.

The game has roguelite progression, with new enemies gradually introduced as you survive more days.

The main gameplay loop is:

Defend → Buy upgrades/items/units → Customize your build → Defend

You can play actively and control your units like an RTS, or play it more like an idle game. Later progression also unlocks a dedicated AFK mode designed for idle play.

I've just released a demo, so feel free to give it a try:

https://store.steampowered.com/app/3760000/Shrine_Protectors_Demo

Thanks for checking it out!

https://i.redd.it/vbjmjoabj8kh1.gif

u/Straight_Age8562 — 3 days ago
▲ 2 r/Unity2D+2 crossposts

I added a mini card game, how do you like it?

The boss flips the cards and tries to get closer to 21, then the turn of the move passes to you, you try to get closer, if you pass, you lose, whoever is close to 21 or 21 wins. Actually, it's almost blackjack.

If you want to check out the Steam page and add it to your wishlist:

https://store.steampowered.com/app/4990070/Deckforce/

u/Own_Revenue6357 — 2 days ago

Weird rendering problem causing semaphore.waitforsignal

The screens shows the stats/profiler in the MAIN MENU of the game. Then there is a lobby and finally, the game scene where you play.

I have more screens, also with the profiler on a develop build. THE PROBLEM DISSAPEARS in a build.

The problem is that 2 days ago, i had 100fps on menu (not good, but was fine compared having 30fps) and also 90-100 fps during GAME, not another 25-30fps after this issues started happening.. It "came from nowhere".

Also, in the lobby of the game (not main menu, not the match) it went from 450fps (there is just an image and 3 buttons) to 120fps....

If i turn OFF the main camera it all goes back to normal.

also, if i make a build.

but i have no CLUE on what is going on, other than this is arendering issue.

FINALLY: on the highlights (top of the screenshots shuing CPU and GPU use) my game normally only has red spots, CPU "bound", not GPU. The biggest scene has 1 millions tris and 1000 batches, about 80 set pass calls, nothing crazy.. it all was working well (despite needing some optimization).

u/doom_alien23 — 2 days ago
▲ 6 r/Unity2D+1 crossposts

Sprite visuals problem

I need I'm trying to understand an issue with 2D sprites in Unity and I would really appreciate some advice from experienced Unity developers

I've tested the same sprite at different resolutions — for example 64×64, 1024×1024, and even 4096×4096 — but when they are displayed at the same size in the Game view, they look almost exactly the same

I've tried different Pixels Per Unit (PPU), camera Orthographic Sizes, Filter Modes, disabling mipmaps, increasing texture Max Size, and using Pixel Perfect Camera, but I still don't see the visual improvement I would expect from the higher-resolution textures

What confuses me is that games like geometry dash can have relatively small sprites on screen that still look very detailed and clean

I understand that a sprite can't display more pixels than its actual screen size, but I'm trying to understand how professional 2D games achieve this kind of detailed appearance when their sprites are small on screen

Is there something fundamental about Unity's 2D rendering, texture import settings, camera setup, or downsampling that I'm misunderstanding?

I'd really appreciate an explanation of what I'm doing wrong and what workflow I should be using to achieve high-quality 2D graphics at small screen sizes

I've been trying to solve this for a long time and I'm honestly starting to think I'm approaching 2D development the wrong way

u/Anonmax797 — 3 days ago

How do I make a 2D first-person dungeon crawler?

Hi everyone, I'm new to Unity and wanted to ask how I can program and implement movement in a 2D first-person game! My goal is to make a horror game with turn-based movement (you move from one room to another, and the monster moves from room to room looking for you and chasing you)! My main question, actually, is whether this is really possible to do in Unity 2D? And if you guys have any tips to share with me!

reddit.com
u/Mooneeris — 3 days ago
▲ 6 r/Unity2D+3 crossposts

I published my first mobile game and would love honest feedback

Hi everyone,

I recently published my first mobile game, Stack Raise 3D, on Google Play. It is a simple one-tap 3D stacking arcade game where you drop blocks, build a tower, try to beat your best score, complete missions, unlock skins, earn rewards, and compete on the leaderboard.

This is my first released game as an indie developer, and I am still learning. I would really appreciate honest feedback from players and fellow developers. Please let me know what feels fun, what feels confusing, what should be improved, and what kind of updates you would like to see next.

More updates are coming soon.

Google Play link:

https://play.google.com/store/apps/details?id=com.smodegames.stackraise3d

Thank you for any support or feedback.

u/S-ModeGames — 3 days ago

Getting References for Tiles

In my game, I am drawing tiles onto a tilemap during runtime using SetTile(), which takes a reference to a TileBase Object. I have hundreds of unique textures. Is there a way to get a reference to each TileBase other than dragging and dropping every individual Tile into the references in my script?

reddit.com
u/Parborway — 3 days ago
▲ 8 r/Unity2D+3 crossposts

Just launched my second game ever

Senet Royale - i worked 4 months to it, it's inspired from ancient egyptian game senet, but i tried to adapt it for modern times. You can find it in google play, what do you think?

u/Sufficient-Move6890 — 4 days ago

How do I use AutoTile to set tile/paint through script?

Hello, I have a tilemap and a tile palette which consists of 2 autotiles. I want to fill an area of the tilemap with one of the autotiles. I know the SetTile is supposed to paint the tile but since I'm using autotile, the SetTile doesn't seem to take that in the script. I'm using Autotile because it would just make it easier when I add in other tiles in areas of the tilemap since it would auto adjust. Does anyone know how I can use the AutoTile in SetTile to paint the tilemap?

Update: I'm stupid, I was passing the ints instead of making them a vector3

reddit.com
u/KoniGTA — 3 days ago