Ten minute game jam!

If the prefab needs to find something in the scene, I can’t see the scene objects from prefab mode. If I click the little circle icon next to the prefab field I want to link, nothing appears. I can only link by dragging the prefab back into the scene, which is a pain.

I would love to hear if there’s a better way!

Ah, I get what you’re saying now.

To be honest, I didn’t even consider that a prefab would retain references to objects in a scene. I assumed they acted more like scriptable objects in that regard.

I wonder what happens if you instantiate a prefab in scene ‘A’ with references to objects in scene ‘B’. Do those just become null references?

Given my misunderstanding, I’ve always added scene references to my prefabs at the time of instantiation. So whatever code is doing the instantiation would be responsible for setting those values (typically through scene references assigned to it via the inspector since it wouldn’t be a prefab itself).

It’s an interesting point you’ve raised!

Out of interest, what scene reference are you wanting to add to what sort of prefab (in the context of your particular game)?

Hmm. I think I’m doing what you suggest – maybe I’m just not doing it comprehensively enough. For starter, I populate data fields at instantiation – in this project, typically I inject a Scriptable Object’s values into a prefab. But in addition, I do sometimes add references to the prefab in the instantiating script, which is attached to a game object in the scene. E.g., I have an “outer space” object that instantiates a ship that is then parented to space. “Outer space” has a reference to the game’s audiomanager, and I give the ship a reference to outer space’s Audio Manager variable. That all works.

But sometimes I think what I do is create an object, attach its script, drag references to it, then drag the object (with those references) into the prefab area down below. Maybe I should be creating all such references in code, rather than dragging objects onto the soon-to-be-created prefab?

In any case, I often find I want to add a reference to a prefab, like my ship. I have always thought I had only two choices: I can make a reference in code, using GameObjectFind or GameObjectFindWith Tag; or I can drag the prefab back into the scene, and then drag the scene object into the prefab, then drag it back down below. But now I’m realizing I of course have a third choice: just edit my instantiation script to add a reference. So give my ‘space’ object a reference to the new thing I want to reference (using the Inspector), and then just copy that reference to the prefab at instantiation time.

I hope I didn’t confuse you or other readers! I’m entirely self-taught, so I’m sure I’m making mistakes left and right. Though I’m happy to say that I seem to be getting a lot faster and more efficient, and my code seems to work. :)

Yep, that makes sense and sounds like good practice.

So that creates a prefab, but I’m fairly certain (based on some googling I’ve just done) that those references won’t persist when the prefab is later instantiated ie they’ll be null references. Again, similar to how you can’t have scene references in a scriptable object.

As far as I’m aware, if you’re instantiating a prefab and it needs particular scene references, you’ll need to do so at the time of initialisation. I typically do that by having the instantiating code (eg an EnemyManager) injecting the references, but you could also have the prefab do it within Awake/Start using one of the various Find methods or, alternatively, a singleton reference.

So essentially the first and third options you’ve mentioned. I don’t think option two is viable (though I could be wrong!).

Honestly, it seems you’re doing really well if this is your first crack at things. :)

The UI certainly seems to imply it’s not. When I do it this way, the prefab does not show the reference I’ve tried to create. But it does seem to work. But since the other two methods we’ve discussed are rock solid, I’ll just make sure I use those two instead going forward.

Thanks! This is not my first effort at a Unity game, but it’s the first one that’s progressed to the point that it’s a playable prototype. I tried to do a 4X last year in Unity and that was way too ambitious, to say the least. I’m still interested in making something like that, but I’ll try a simple wargame first.

I did complete some simpler games using GameMaker – a tetris clone, checkers, and a chess engine that I’m kinda proud of (until it falls apart in the endgame). I messed around with Godot a bit but I didn’t produce anything. Godot is interesting, but it’s so hard to get questions answered, whereas Unity has a huge volume of learning material.

I also did some systems programming decades ago for my dad’s software company, during college summers, but that was in COBOL (gasp). I was a comp-sci major for one semester in college (using APL, Pascal), but I did not do well and switched to the humanities. Since then making a game has always been on my bucket list, and now I’m living the dream!

So I’ve arrived at the fun stuff – making an explosion! I’ve been playing with the particle system, but all my efforts look like fireworks. I think maybe I don’t have the right material? The manual says: “The particles in the standard assets include a material called ParticleFireball which is very suitable for explosions (menu: Assets > Import Package > ParticleSystems ).” When I click that menu option, I get only the option to import a custom package.

Also, can I put a 3D explosion in worldspace in my 2D game? In Unity everything is really 3D, right? Should I consider making my own explosion in a 3D modeling program or something?

Finally: my particle bounds are HUGE – 10x the size of my scene. Almost as big as the canvas! I can’t seem to change them. I’ve tried checking different scale settings, or setting the scale values, but nothing alters these bounds. My explosion fills the whole screen and then some; I want it to fill 1/15th of the screen.

Bit lost here, but it’s fun. :)

Quick update: OK, I got my particles looking better, with some help from the official forums. I had to change the lifetime of the particles and other values in the “main” part of the inspector display for the particle system. I’ve now got lasers shooting at ships, with explosions happening on contact, and sound effects! None of it’s gonna win any graphics awards, but it’s a good start. I wanted some sort of visual feedback to for the player (and me), especially when watching the AI play.

This is so fun! Next I’ll be adding variety to the source and target of laser effects, then adding other weapons. Then I’ll take another pass at card effects and art, then finally get on with the “building a deck” part of the game – what happens after you win a battle and enter the map.

Happy to hear it’s progressing well.

It still surprises me how much of a difference just a bit of sound and visual effects can make to the overall feel.

As my project gets more complex, I’m thinking about writing up some sort of guide for myself on how my software works. RIght now I have lots of Trello cards, primarily (1) To Do, (2) Doing, (3) Done. My Github uploads always have notes on what I’ve done and what’s next. Plus I comment my code liberally.

Still, I know that if I step away for even a couple weeks, it takes me a while to remember which script does what, where game logic starts and ends, which game object does what, what such-and-such algorithm does, etc. I’m thinking of writing this up in an Office document or something. Is there any general practice on this? Maybe there’s a flowchart template I should be using? A mind map thing? It could also be the beginnings of documentation for the player.

Also, I’m curious whether my 2D setup (with URP) restricts me from putting 3D elements in my game. I’d really like a rocket to fly out of the screen toward the user, for example. I put in a simple 3D model and can’t seem to make it appear closer to the viewer, even if I change its Z position. I don’t necessarily want to go nuts with 3D – I want to finish this thing – but it might be fun to have a couple 3D elements. E.g., maybe 3D cards that the player can toss around, and a couple 3D animations.

Even if I’m stuck with 2D, I’m pleased with the progress I’m making on visuals. A few drop shadows in Photoshop, and liberal use of sorting layers, make sprites stack on one another in a pleasing way. I have missiles flying toward targets and causing little explosions. My lasers and disruptors make pleasant zap noises.

All that said, I’m now finishing my UI/visual pass and moving back to gameplay basics. I’ve really got my basic game loop done. It’s time to let the player build his deck and travel thru the galaxy, facing successively tougher challenges.

I tend to over-comment my code, so if I’m down in the weeds a few months later I can grasp what it’s trying to do. But I am in favour of writing up the high-level design in a doc or txt file as, if the time gap is substantial, it’s particularly useful to have a way of quickly getting up to speed on the overall project architecture ie not diving down into the weeds.

It’s also worth noting why certain decisions were made. Just because you learnt your lesson now, doesn’t mean “you a year from now” will remember, and might re-engineer a seemingly poor bit of design only to end up with the same problem you addressed a year ago.

Your 2D/3D issue may be due to the camera setup (orthographic vs perspective).

Thanks for your comments. I probably will write myself some sort of guide, and I like your advice about including the “why.”

You’re right about the camera: doh! I tried perspective cam, and once I adjusted the field of view to 55, it worked fine. Er, is 55 unusually wide?

More importantly, is there any downside to using a perspective cam rather than the orthographic one? If I don’t use any 3D assets at all, I suppose orthographic might be a bit more performant?

I am tempted to try a little 3D with perspective view, though. I enjoy using ZBrush, and it might be fun to add a little 3D content to my game. E.g., I was thinking of turning my cards into 3D worldspace UI elements, and maybe displaying some effects in 3D – missiles racing off at different angles, for example.

I don’t think performance is really a consideration for perspective vs orthographic. It really just comes down to which one makes sense for your game.

Okay, in due course I’ll mess around with a 3D asset and perspective view.

I just discovered that itch.io has a lot of free game assets available, with the CC0 (public domain) license. Up til now, I’ve been relying on OpenGame Art. Any reason not to use itch.io instead? I seem to be finding more of what I need there.

itch.io is pretty reputable, so if they have assets available that are under an appropriate license then I say fill your boots!

Thanks! As always, I appreciate all your advice.

I have been adding tooltips and chat bubbles, fussing with UI, improving art, adding sounds, etc. So fun! My Trello to-do list says it’s time to get back to gameplay, but I am like a little kid enjoying what I’m enjoying. Whatever keeps us enthused, right?

Your regular updates motivated me to get back into my own hobby project, so please keep posting! :)

Glad to hear it! You’ve probably described your project before and I’ve probably forgotten what you said, but if you have a moment, I’d be interested to hear what you’re working on. In fact I’m curious what everyone in this thread is up to. :-)

I don’t think I’ve mentioned it before.

It’s a single player strategy game that involves dice and abilities (kinda like you’d find on cards in, say, Slay the Spire and the like, but you don’t actually draw them and play them). Inspired by Res Arcana and Star Wars Destiny.

The bit I’m working on that may or may not prove to be the death of the project is that all this stuff is procedurally generated. As in, I don’t have any set dice or abilities (or monsters) - everything is generated algorithmically.

With this approach I don’t expect it to be finely balanced (or even balanced at all). The idea is more around finding wacky abusable combos and riding them to the finish. Whether it’s fun or not, I guess we’ll see.

It’s just a ‘toy’ project ie something I’m interested in pursuing from a theoretical design point of view, rather than seeking a wider audience.

Like yourself, I’m keen to hear what others in this thread have simmering away.

That sounds fun! If it reaches a stage where it’s shareable, please let us know.

So between card battles, I call new scenes, and doing so apparently destroys all the instantiated objects in my card-battle scene. I’m not calling Object.DontDestroyOnLoad on any of my cards, for example. I think this is what I want, right? I use a Persistent class of static variables to keep track of a few things from one scene to the next (player health, money, card list, etc.), but other than that I’m happy to see everything wiped clean.

Is this the right practice?