benArcen

Unity Questions Thread

Recommended Posts

I'm actually doing both of those things. The buttons are using this shader for a slight subsurface scattering effect and I'm adjusting the button material color with SetPropertyBlock. Each button has it's own point light which gets assigned the appropriate color when pressed. If I muck around in the quality settings (Edit -> Project Settings -> Quality), boosting the pixel light count provides a better effect, especially with the lights bouncing off the surface of the metal console.

DbNsC9S.png

 

 

Scene with Pixel Light count set to 1 (only the middle green "works")

HDTZR7l.png

 

Scene with Pixel Light Count set to 12

L8uglSO.png

 

 

Again, I might be prematurely optimizing, but I was wondering if anyone else has dealt with a similar problem.

Share this post


Link to post
Share on other sites

Oh I see it's a quality issue.  I know one solution for this is to create a kind of glow mesh that gets illuminated so you can get away with less lights.    Have you tried switching to deferred lighting?  You'll need a pro license to activate it, but you should be able to write a shader that fakes the above effect over multiple objects.  I've never personally worked with a lot of lights in Unity before so I'd be interested to know how you end up solving this one.

Share this post


Link to post
Share on other sites

So I have returned again.

 

I'm trying to make a grid based game where each square of the grid is an element of a 2D array. But when trying to determine if a square is a viable place to put an enemy I'm getting some erratic behaviour. I go into detail and have my code in a Unity Questions page here if anyone thinks they could shed some light on it.

(to be clear, the code functions and even catches some instances where there shouldn't be an enemy, but not all of them. And I am not sure why that is since i can't see a pattern to it)

Share this post


Link to post
Share on other sites

Hm I don't see anything that is obviously the cause but I think it's strange the calculateChaserChance tests go down from i to 1 and j to 1. Are all cells guaranteed to be set to 0 before genereating the level? If not, you could prematurely break the testing loops by testing the cells[i,j] value which is the cell you're currently computing (and could be set to 1 for some reason). Also the test will ignore everything with i = 0 and j = 0 but maybe these tiles are guaranteed to be walls? Anyway I would change the loops to for (curr = i - 1; curr >= 0; curr--) (the same for j obviously).

 

Also I would try to modify the code so calculateChaserChance outputs some huge chance instead of 0.2 so the enemies would always be placed as soon as possible. If that eliminates the problem it means something is wrong with the randomness/chance values.

Share this post


Link to post
Share on other sites

The way values are being set is by looping through every cell and then setting the value. There's a series of else if commands, so first it decides on whether or not to place a wall and only if that doesn't happen it sets an enemy. So I never need to test the current cell for being a wall, only testing to see if it's empty or if other cells are walls. But that does mean you're right about adjusting the loop! I'm wasting a cycle checking the cell itself, twice in fact. I have it set as > rather than >= because the 0 cells are always just set as walls, to make the level enclosed.

 

 

 

...so I just rewrote it and now it works fine for reasons unknown. For posterity here's the rewritten functioning loop:

 

	for (curr = i - 1; curr > 0; curr--){
		if (cells[curr,j] == 1){
			break;
		} 
		if (cells[curr,j] > 1){
			return -5;
		}
	}

I was just planning to tidy it on your suggestion iax, then went back to basics (ignored walls and didn't allow more than one in any row or column) and that was working, so I added what is practically the same code but apparently different enough to fix it. Yay!

Share this post


Link to post
Share on other sites

Sure, I know you're setting the cells in the Start function but the cells do have some values already before executing the function and you tested for these values before setting the new ones. Your posted code doesn't include the part where you create the cells array so I didn't know it's guaranteed to be zero (i.e. empty space). It seems some of the cells were in fact set to 1 before running Start() if the change you posted fixed the problem (or maybe you ran the Start function multiple times? In that case the previous results were present in the cells array and were influencing the algorithm).

Share this post


Link to post
Share on other sites

That's weird, cause I definitely didn't d... oh god. You're right, I had an old line of code still lingering.

 

I first just had a basic way of setting each value to 0 or 1, when I was just making sure that I could set up the system to iterate through the array and assign values, but I never got rid of it. My new system does overwrite every cell anyway, so when the whole array was iterated it worked fine and I didn't get invisible walls, buuut when it was determining where the walls were, those ghost walls were still in the array.

 

This is exactly why I should examine the parts of the code that aren't the bit I'm working on, too often it's because of something else rather than what I'm focused on(even if it's not as dumb as old code lying around). Thanks for the help!

Share this post


Link to post
Share on other sites

We recently completed our Unity game, and I'd like to pass on what knowledge I gained from this while the experience is still fresh in my mind.  I've written most of a post I'll put up in the coming days on the Unity forum, but I just wanted to put a feeler out to see if there is anything regarding making a game in Unity people would like to know.  So far the post covers some editor best practices, integration tips, initialization structure, some method usage, and a few other odds and ends.  Also I should mention the post will be aimed at programmers, or at least anyone writing their game in Unity.  I can't speak with any authority from an artistic perspective, but if you have any questions in that area the artist I worked for would probably have some insight on the matter.

Share this post


Link to post
Share on other sites

I still don't understand the JSON thing and how or if it relates to making a text document and a parser that populates dialogue arrays at runtime (I still haven't written a text-parser and it seems like a completely different thing much like programming shaders does). I looked it up a few different times months ago, bit kept getting stuck. Now I've written a system in one MonoDevelop script that populates a array of "page" class that is then advanced during the game (think visual novel).

I doubt I'll go back and redo it now that I have something working, but I'm still interested in how writing branching dialogue can be handled more efficiently, but still in a Ren'py-esque workflow. If you have anything to say about that, then I would certainly read it.

Share this post


Link to post
Share on other sites

Nice write up^.

 

This isn't really a question I just though id say some things.

Im a complete beginner and I'm just tinkering around trying to figure out how to make a rudimentary 2d builder game(of prison architect ilk).

So far i'v got three scripts, one which generates a tile grid and displays a texture on it, another which stores data for each tile and that tiles location and another which collects mouse information. 

 

I was wondering how would you folk go about putting this kind of thing together?

Share this post


Link to post
Share on other sites

I'm going to describe what I imagine you are trying to do and then describe how I would do it. I'm assuming little knowledge about c# because I don't know how much experience you have and you say you are a beginner.

So there will be tiles on a grid and those tiles are assigned particular textures based on mouse-clicks. I imagine that some NPC or player character will eventually be roaming around on the tiles. I would want to make the code flexible so that I could eventually do things like have tiles change their orientation or change color or make sounds or other stuff. I also imagine that the NPC or player character will need information from the tile they are trying to move onto.

What I would do is create a tile class.

The tile class would include all my tile needs.

-I want a variable that keeps track of the texture on the tile.

-I want a variable that keeps track of the tiles orientation/rotation (I'm think of 4-sided tiles and just having 4 possible orientations).

-I want a bool that keeps track of whether or not an NPC can move onto the tile.

-Then I want a series of methods (also called function) that can assign and change all of these variables listed.

-I also want a series of methods that can pass the information on to the NPC about what the values of the variables are.

So for instance, I'll want to be able to click on a tile to change whether or not it is a wall or navigable space. Then I want the NPC to check to see if it is navigable space before moving onto it.

Am I on the right track?

Share this post


Link to post
Share on other sites

Sorry for the fumbling attempt to say things haha. 

 

But yeah thats great thanks, that helps me set a direction to head in :). Ill set up a tile class and go from there. 

Share this post


Link to post
Share on other sites

You are probably trying to hurry along for the game-jam, and I don't know what your level of programming is, but...

Even though this tutorial series is about how to make a database for your fantasy book collection, my game-programming skills went from beginner to beginner-intermediate when I followed along with these:

Conceptualizing classes and functions is something people with experience take for granted and it wasn't until I saw this gentle fellow ASMR at me about modularity that I really was able to internalize it. Every one responds to different things though.

I'm still more than willing to attempt to answer any questions. I'm pretty limited in skill (for instance, I have to look at the tutorial for constructors every time I write one) but I know enough to enjoy trying to figure it out.

Share this post


Link to post
Share on other sites

Oh cool, ill check that out. Nah im just messing around so I have all the time in the world. Thanks.
 

Share this post


Link to post
Share on other sites

This isn't actually a question but we don't have a general Unity thread sooo

 

Unite 2015 tickets are on sale and it's in Boston this year!

 

http://unity3d.com/unite/boston?unity3dmarketo&unity3d_homepagesweepstakes_emails&theme_sale_04_15Unite_Boston_2015

 

Early bird tix are ~$360, I got mine yesterday which I sorta regret 'cause boy I sure don't have 400 bucks to spare, but they're normally $500 and its so close, I had to jump on it. If anyone else is coming, let me know and lets drink beers in September!!

Share this post


Link to post
Share on other sites

All right here's an actual question...does anyone know of any good resources (tuts, talks, anything) for optimizing unity 2d for mobile? I've been looking into it a bit, but so far all I've done is start using the sprite packer and clean up some scripts, and I'm looking at implementing object pooling soon.

Share this post


Link to post
Share on other sites

Object pooling is a good start. This guide is a little outdated but has some good tips. Do you know what parts are hanging you up specifically?

Share this post


Link to post
Share on other sites

It's getting slow in the later parts of the game, so my guess is that it's either that there are too many colliders or that I'm instantiating too many objects. It starts getting slow when there are ~7+ enemies on screen firing between 1-4 projectiles each.

 

It could also be an issue with UI? I'm generating quite a bit of floaty text (health pickups, damage notifications, etc) and I read somewhere recently that moving UI elements is really expensive.

Share this post


Link to post
Share on other sites

I don't know much about the new UI. Object pooling should help a lot, instantiation is expensive. Are you using lots of particle systems? Those can be pooled too. How many colliders are we talking about? The collider primitives should be pretty efficient.

Share this post


Link to post
Share on other sites

Fairly late in the game I'm seeing 70 static colliders and 20 active. That seems reasonable? I've been taking a closer look at my profiler output and it definitely seems like Canvas/UI is the biggest offender...it's a pain in the ass finding info on it though, since that UI only went in during the fall last year.

 

It seems like each individual Text component has to be its own batch? Maybe I can make sprites of the most common text so they can be reused.

 

Batch is a weird word.

 

batch

Share this post


Link to post
Share on other sites

If those text objects are on the same material they should be all drawn together? Are you doing any kind of tinting/color mods to them? If so you may be generating hundreds of materials that need to be cleaned up manually

Share this post


Link to post
Share on other sites

I'm using the default font material and setting its color from a script, but I don't think it's creating new materials. And I think I misread something in a Unity forum post that made me think the text was using multiple draw calls? I think the problem is actually that I was just creating a lot of Text objects and not doing a great job of cleaning them up. They were fading kinda slowly before and taking a while to completely disappear (which is when they get destroyed), so there were just a lot of them in the scene at a time. I'm being more aggressive about it now and the framerate is much better. I am still looking for other hot optimization tips though.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now