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
Salynne
Oct 25, 2007

FateFree posted:

No I already use perlin noise to generate the map, so now I have an island with sand and grass and transition tiles in between. I want to layer a large, grass texture block over all the green grass pixels to make them look nicer. And similary layer a large sand texture pattern over all the yellow pixels.

I'm a little bit confused still, how about a screenshot of the pixels or whatever?

I'm not getting why they have to pixels -> texture pattern overtop or whatever but it seems like an easy problem to solve, it just depends on how your stuff is actually structured.

Adbot
ADBOT LOVES YOU

stramit
Dec 9, 2004
Ask me about making games instead of gains.

xgalaxy posted:

So I guess Unity 4 still doesn't quite work correctly with namespaces.
We have this strange issue where it thinks the class isn't named the same as the file when trying to attach it to a game object, and when we remove the namespace it works fine. Yet another script with a namespace works fine...
I just had a look in the bug database and we don't have anything about namespaces not working properly (afaik they should 'just work') if you raise a bug with simple repro project and give the the bug number I'll send it off to one of the scripting team, you might be hitting some weird corner case.

Unormal posted:

I haven't had any issues with namespaces; that said Unity has an infinite number of bizarre bugs, so I wouldn't rule it out. Perhaps you've got a naming conflict somewhere?
ehhhhhhhhhhhhhhhhhhhhhhh

Zizi
Jan 7, 2010

Strumpy posted:

I just had a look in the bug database and we don't have anything about namespaces not working properly (afaik they should 'just work') if you raise a bug with simple repro project and give the the bug number I'll send it off to one of the scripting team, you might be hitting some weird corner case.

ehhhhhhhhhhhhhhhhhhhhhhh

I thought namespaces didn't play nice with Monobehaviors?

EDIT: Oop, right, that was supposed to be fixed with 4. Apparently there are still some caveats, though: http://answers.unity3d.com/questions/361976/are-namespaces-supported-in-unity-4.html

It appears there are still issues with multiple classes in a single file being in namespaces, and some other stuff.

Zizi fucked around with this message at 19:08 on Sep 19, 2013

SlightlyMadman
Jan 14, 2005

I'm working on a space game with a Sims-like ship designer in Unity (c#), and I'm debating how best to store the ship data. It's pretty much a straight 3D grid of cubes, basically voxels. My experience is mostly with roguelikes and I'd have used a two-dimensional array to store the board data in the past, but I'm wondering if there's a better way to do it, particularly in 3D?

Would a hashtable with a Vector3 as the key make sense? I'm leaning towards that since Unity is all Vector3's all over the place anyways, and a hashtable seems preferable to full arrays since a spaceship will have a lot of empty space around it.

edit: Screwed around a bit, and came up with this
code:
public class ShipCube {
	public GameObject GameObject { get; set; }
	
	public ShipCube(GameObject gameObject) {
		this.GameObject = gameObject;
	}
}

public class Ship {
	public Dictionary<Vector3, ShipCube> Cubes;
}
I'll obviously be adding more properties to ShipCube, but that suits my purposes pretty well for the moment. Much more efficient in memory than gigantic three-dimensional arrays, with still very fast coordinate look-up. Great for my render method, since I can just iterate the actual items in the dictionary, instead of having to loop through all possible array coordinates.

SlightlyMadman fucked around with this message at 23:30 on Sep 19, 2013

Zizi
Jan 7, 2010

SlightlyMadman posted:

I'm working on a space game with a Sims-like ship designer in Unity (c#), and I'm debating how best to store the ship data. It's pretty much a straight 3D grid of cubes, basically voxels. My experience is mostly with roguelikes and I'd have used a two-dimensional array to store the board data in the past, but I'm wondering if there's a better way to do it, particularly in 3D?

Would a hashtable with a Vector3 as the key make sense? I'm leaning towards that since Unity is all Vector3's all over the place anyways, and a hashtable seems preferable to full arrays since a spaceship will have a lot of empty space around it.

You can certainly do it that way-- I don't know offhand if there's a downside to it. I have a system much like this in one of my projects, and personally, I just went with a 3D jagged array, since I expect the whole thing to be filled most of the time anyway, and you can still access everything with a Vector3 if you want.

SlightlyMadman
Jan 14, 2005

Zizi posted:

You can certainly do it that way-- I don't know offhand if there's a downside to it. I have a system much like this in one of my projects, and personally, I just went with a 3D jagged array, since I expect the whole thing to be filled most of the time anyway, and you can still access everything with a Vector3 if you want.

Yeah, that's certainly a more straightforward way about it and I've always used it for dungeon environments. The structure really only needs to be a cube containing the ship, not the whole environment of course, but even then, draw a box around a space ship and it's mostly empty space around it.

The only downfall I've thought of so far, is that if I want to scan a "slice" I'd have to either make a bunch of ContainsKey calls with newly created Vector3 objects, or look through every element and check it's key.

Zizi
Jan 7, 2010

SlightlyMadman posted:

Yeah, that's certainly a more straightforward way about it and I've always used it for dungeon environments. The structure really only needs to be a cube containing the ship, not the whole environment of course, but even then, draw a box around a space ship and it's mostly empty space around it.

The only downfall I've thought of so far, is that if I want to scan a "slice" I'd have to either make a bunch of ContainsKey calls with newly created Vector3 objects, or look through every element and check it's key.

That's definitely a downside compared to jagged array, since C# means you don't have to store Array lengths and can just run a foreach on the chunks you want by accessing them directly. On the other hand, I'm dealing with ship internals, not the structure of the ship itself. In my case, each ship design has a set number of internal decks, corridors, and slots that you install lifesupport, storage, sensors, engines, etc into.

On the other hand, with your Dictionary, you could always scan slices using LINQ to Objects, which would look something like

code:
var result = from item in Cubes
	where item.Key.X == xSlice
	select item;

foreach (ShipCube in result)
	// Do stuff
I don't think this is faster than going through the list yourself and filtering, though LINQ does let you do a bunch of neat things like sorting the results if you need to.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
LINQ is very useful for writing compact code, but no, it definitely doesn't have any performance benefits. If anything, it actually incurs a slight penalty.

SlightlyMadman, if access of slices is a common operation (i.e. more common than mutation of the ship itself), you could consider maintaining a parallel data structure which is organized by slice. There's a memory cost, of course, but I doubt it's substantial.

SlightlyMadman
Jan 14, 2005

Orzo posted:

LINQ is very useful for writing compact code, but no, it definitely doesn't have any performance benefits. If anything, it actually incurs a slight penalty.

I personally think it looks like rear end too, and I've seen extremely high-traffic websites brought to their knees by the overhead of seemingly simple linq queries. It can perform as well as native code in many cases, but it's sometimes weirdly suboptimal in seemingly normal circumstances.

Orzo posted:

SlightlyMadman, if access of slices is a common operation (i.e. more common than mutation of the ship itself), you could consider maintaining a parallel data structure which is organized by slice. There's a memory cost, of course, but I doubt it's substantial.

I was actually just debating an array of Vector2 dictionaries, where the array would be the deck number (z-index) and the Vector2 would be the x-y coordinate. It might look a little awkward, but the game will mostly be dealing with one deck at a time (and that would be the only slice normally taken), and accessing "Cubes[z][new Vector2(x, y)]" isn't much worse than "Cubes[new Vector3(x, y, z)]". It still solves the problem of eliminating wasted empty space just as effectively, since there won't be entire empty decks.

There's probably some memory overhead of storing multiple dictionaries, but that shouldn't be a big deal since there won't generally be more than a few decks. I can't really think of any other drawbacks, except that it just feels a bit odd.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
We game jammed again! August's theme was "an Oasis song" so we picked Fuckin' in the Bushes. Give it a shot!



http://ghostcrabgames.com/jams/bang-buster/

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

SlightlyMadman posted:

I personally think it looks like rear end too, and I've seen extremely high-traffic websites brought to their knees by the overhead of seemingly simple linq queries. It can perform as well as native code in many cases, but it's sometimes weirdly suboptimal in seemingly normal circumstances.
First of all, I agree that the SQL-style LINQ methods look like rear end. Don't use them. But the IEnumerable<T> extension libraries--which the SQL-looking poo poo calls anyway, are excellent (i.e. .Where, .Select, .Reverse, etc) and look just fine as long as you don't have an aversion to lambdas (which you shouldn't).

Second, there's actually nothing mysterious about them. At my job, before they even existed, our group had actually implemented most of them in an algorithms helper class which became mostly obsolete when Microsoft released their extension methods. If you have reflector or resharper, the code isn't at all obfuscated, you can just click and see how they're just wrapping basic loops in nice methods. '.Select' is just shorthand for iterating through a list given a Func<T, X> and extracting values out of a list, for example.

SlightlyMadman
Jan 14, 2005

I absolutely agree with you there, I use the lambda orm stuff all the time. It's also much more obvious exactly what you're doing, and there's nothing that you can do in sql style linq that you can't do with it. I mostly use it for simple entity database interactions (anything complex usually gets a stored procedure), and the object relations in particular work great.

CuddlyZombie
Nov 6, 2005

I wuv your brains.

Hey everyone, I have a couple questions I was hoping a Unity expert might be able to help me with, so I don't spend an hour spinning my wheels when I could be Getting Stuff Done. I know barely anything about the Unity interface/libraries, and am most comfortable when working in MonoDevelop with existing C# principles. :shobon:


I have a single-"scene" project that I inherited from another engineer with a mostly empty scene with a few objects holding all of the game's initialization scripts.


I was wondering, is there a clean way for me to:

Make a brand new scene, and have that be the starter/initial scene.

When a user presses one of several start buttons on the new initial scene, the original, complex scene that I inherited is loaded up and made active, only with a parameter that varies depending on what button was pressed.


I don't wanna break any of these existing scripts while experimenting, since not all of them have documentation. While I'm sure it's something I could EVENTUALLY figure out on my own with Google and documentation and such, if anyone could point me in the right direction on a general way to tidily do this, it would be a HUGE help and time saver.

Obsurveyor
Jan 10, 2003

CuddlyZombie posted:

Make a brand new scene, and have that be the starter/initial scene.

Assuming it's just using standard Unity stuff:

  • File -> New Scene
  • Save the Scene
  • File -> Build Settings
  • Click 'Add Current' button

Order them so that your new scene is index 0 and the old scene is index 1

quote:

When a user presses one of several start buttons on the new initial scene, the original, complex scene that I inherited is loaded up and made active, only with a parameter that varies depending on what button was pressed.

Make your GUI(do a tutorial or something to get buttons for this) call:

code:
Application.LoadLevel(1);
when your button is clicked. You can set static values in a game class that manages the parameter that you want to vary. I'm not sure if there's more "Unity" way to do that.

CuddlyZombie
Nov 6, 2005

I wuv your brains.

Ooh, thanks! That all sounds simple enough,


Obsurveyor posted:

You can set static values in a game class that manages the parameter that you want to vary. I'm not sure if there's more "Unity" way to do that.

So to confirm, a static value is static across the entire unity project, and not just in a given scene? If so then perfect, I've been worrying a lot over nothing.

Obsurveyor
Jan 10, 2003

CuddlyZombie posted:

So to confirm, a static value is static across the entire unity project, and not just in a given scene? If so then perfect, I've been worrying a lot over nothing.

If you create a member in a class that is static, it doesn't change across instances of the class.

CuddlyZombie
Nov 6, 2005

I wuv your brains.

Obsurveyor posted:

If you create a member in a class that is static, it doesn't change across instances of the class.

Oh okay, so I can just make a class called StaticVariables or something, then give that a static string called foo in my first scene, set an instance of that class's foo string to "bar" in my first scene, and if I later make another instance of StaticVariable in my second scene and get its foo variable, it'll return "bar"?


Beautiful, thank you so much!

Unormal
Nov 16, 2004

Mod sass? This evening?! But the cakes aren't ready! THE CAKES!
Fun Shoe
Static variables do not change between scene loads.

The one big caveat to that statement is that Unity GameObjects will be invalidated when you load a scene, unless you tag them to not be destroyed on scene-change by calling http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

CuddlyZombie posted:

Oh okay, so I can just make a class called StaticVariables or something, then give that a static string called foo in my first scene, set an instance of that class's foo string to "bar" in my first scene, and if I later make another instance of StaticVariable in my second scene and get its foo variable, it'll return "bar"?


Beautiful, thank you so much!
Better yet, make the class itself static and you won't waste resources instantiating anything. Static classes are a thing; they must have all static methods and member variables.

CuddlyZombie
Nov 6, 2005

I wuv your brains.

Unormal posted:

The one big caveat to that statement is that Unity GameObjects will be invalidated when you load a scene, unless you tag them to not be destroyed on scene-change by calling http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html

I'm not sure I understand why this is necessary, if after my first intro screen I have no reason to return to it. Even if the first class instance gets destroyed, the static foo will still have the same value, right?

Orzo posted:

Better yet, make the class itself static and you won't waste resources instantiating anything. Static classes are a thing; they must have all static methods and member variables.

Is this any different than a singleton?

Obsurveyor
Jan 10, 2003

CuddlyZombie posted:

Is this any different than a singleton?

Not really. Singletons don't use any resources until they're used for the first time. It sounds like you're going to be using it right away, so it probably doesn't matter which you use.

CuddlyZombie
Nov 6, 2005

I wuv your brains.

Obsurveyor posted:

Not really. Singletons don't use any resources until they're used for the first time. It sounds like you're going to be using it right away, so it probably doesn't matter which you use.

Cool, thanks.

Well, it sounds like I have a few different options that'll each get the job done. I appreciate the help guys. :)

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!

Obsurveyor posted:

Not really. Singletons don't use any resources until they're used for the first time. It sounds like you're going to be using it right away, so it probably doesn't matter which you use.
The static class is a little bit less fiddly to work with, in my experience. But that's maybe only true if you're a bit lazy about the OO-ness - accessing the static variables like "StaticClass.thing=1" is something you can do with the static class and is more unwieldy with the singleton. (StaticClass.Instance.thing=1 perhaps?)

Or you can do it with the same syntax as the static class through implementing a bunch of static get/set methods, but you can skip that entirely with the static class.

Shalinor
Jun 10, 2002

Can I buy you a rootbeer?

roomforthetuna posted:

The static class is a little bit less fiddly to work with, in my experience. But that's maybe only true if you're a bit lazy about the OO-ness - accessing the static variables like "StaticClass.thing=1" is something you can do with the static class and is more unwieldy with the singleton. (StaticClass.Instance.thing=1 perhaps?)

Or you can do it with the same syntax as the static class through implementing a bunch of static get/set methods, but you can skip that entirely with the static class.
The singleton method exposes the class to the inspector, since it's on an object. Meaning you can tweak values and assign prefabs and the like.

That's the main reason I use them over statics.

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!

Shalinor posted:

The singleton method exposes the class to the inspector, since it's on an object. Meaning you can tweak values and assign prefabs and the like.

That's the main reason I use them over statics.
Aha, that is a good reason. I generally prefer tweaking values in the code, but being able to assign prefabs is certainly an advantage if that's something you want to do with a global var.

Chunderstorm
May 9, 2010


legs crossed like a buddhist
smokin' buddha
angry tuna

seiken posted:

code:
x = (x + 180) % 360;
x = clamp(x, 150, 210);
x = (x + 180) % 360;

This totally worked! Thank you so much!

superh
Oct 10, 2007

Touching every treasure

roomforthetuna posted:

Aha, that is a good reason. I generally prefer tweaking values in the code, but being able to assign prefabs is certainly an advantage if that's something you want to do with a global var.

I used to be of the same mindset, but there are certain areas that seeing your changes live will save you so, so much time on. Unity makes it so easy, once you can wrap your mind around it you'll really thank yourself for taking advantage of it.

For example, I was working on a unity fighting game - after switching to inspector based hit box timing / positioning I could implement a character in a single day of fiddling instead of two or three days of fine tuning and trial and error.

I've even been taking the time to implement quasi wysiwyg editors into most of my non unity products these days - it's a huge initial investment but you'll end up saving so much time in the end.

xgalaxy
Jan 27, 2004
i write code
So I was watching a demo of the UbiArt tech for Rayman Legends. I wanted to know if anyone here has any thoughts, or possibly links to blogs, articles, or papers on how they do what they call 'smart textures' for the ground as demonstrated here:
https://www.youtube.com/watch?v=W9c8dTRNg20&t=780s

My current naive thinking would be to calculate the angle at the control points and use that as a key into a look up table of the swap-able textures. Stretching could be accomplished by tiling the texture across the length and/or having variations that it blends into / on top of the texture. The end caps would just be 'capped' textures that are blended on top of the base texture.

Does that sound about right?

Shalinor
Jun 10, 2002

Can I buy you a rootbeer?

xgalaxy posted:

My current naive thinking would be to calculate the angle at the control points and use that as a key into a look up table of the swap-able textures. Stretching could be accomplished by tiling the texture across the length and/or having variations that it blends into / on top of the texture. The end caps would just be 'capped' textures that are blended on top of the base texture.

Does that sound about right?
That's how I'd do it, yeah. Though rather than doing a visual lerp between textures per point, I'd probably start by enforcing one "angle" of texture per run, and have a set of transition textures to chunk in between runs of substantially different inclines. Though just a straight up lerp might look fine too, who knows.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
They said in the video that it's a mesh, and the blocks are curved at the control point, so it's probably just a randomized tile mesh with caps at the end.

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!

superh posted:

I used to be of the same mindset, but there are certain areas that seeing your changes live will save you so, so much time on. Unity makes it so easy, once you can wrap your mind around it you'll really thank yourself for taking advantage of it.
Oh, yeah, I was just talking about global variables there. I do use inspector-mounted values on characters and things. But I also tend to make my global variables things that aren't going to be frequently tweaked, too.

SlightlyMadman
Jan 14, 2005

Anybody else use git with unity? I set up a project, and used a default .gitignore for unity, with the following:

code:
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/

# Autogenerated VS/MD solution and project files
*.csproj
*.unityproj
*.sln
When I open up the project on another computer though, the scene is completely empty. My game script and camera and everything like that are gone. I'm guessing that's in a file that's getting ignored somehow, but I'm not seeing where it is to put it back in.

Obsurveyor
Jan 10, 2003

SlightlyMadman posted:

When I open up the project on another computer though, the scene is completely empty. My game script and camera and everything like that are gone. I'm guessing that's in a file that's getting ignored somehow, but I'm not seeing where it is to put it back in.

Did you set Version Control to "Meta Files" under Project Settings->Editor Settings? There's also a new Asset Serialization Mode to force text which would probably help git patches but I haven't tried it yet.

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.

SlightlyMadman posted:

When I open up the project on another computer though, the scene is completely empty. My game script and camera and everything like that are gone. I'm guessing that's in a file that's getting ignored somehow, but I'm not seeing where it is to put it back in.
Did you actually open the scene from the Assets after opening the project? The last-open scene doesn't carry across computers, so if there is none Unity will just open a new project with a blank scene.

Unormal
Nov 16, 2004

Mod sass? This evening?! But the cakes aren't ready! THE CAKES!
Fun Shoe

SupSuper posted:

Did you actually open the scene from the Assets after opening the project? The last-open scene doesn't carry across computers, so if there is none Unity will just open a new project with a blank scene.

I'll second this as almost certainly the problem. Just open up the scene file on the other computer, and you should be good to go. It's just opening with a new default blank machine on the first open on the other computer.

SlightlyMadman
Jan 14, 2005

Ahh yeah that sounds like exactly it. I'll check it out again tonight when I get home, thanks for the tip! I'm still pretty new to unity so I didn't think about that.

DancingPenguin
Nov 27, 2012

I ish kakadu.
Does anyone have any info on when Unity 4.3 drops?
What's the general take here, get 2D-toolkit and work with that or just wait for the update? (For a project that's supposed to be done in a couple of weeks.)

Shalinor
Jun 10, 2002

Can I buy you a rootbeer?

DancingPenguin posted:

Does anyone have any info on when Unity 4.3 drops?
What's the general take here, get 2D-toolkit and work with that or just wait for the update? (For a project that's supposed to be done in a couple of weeks.)
Get 2D Toolkit. Whatever Unity drops will probably be rough, and take a couple of versions to become something you really want to use.

If 2D Toolkit were expensive, hey, wait, but... it really isn't.

FuzzySlippers
Feb 6, 2009

Yeah I wouldn't wait for 4.3 especially for a small project. There are beta versions out there for 4.3 already but its hard to say when it'll hit for everyone else.

The author of Rage Spline is the one they hired to head up the 4.3 2D so I dunno if using that might make it easier to transition to the regular Unity support when its released.

Adbot
ADBOT LOVES YOU

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

DancingPenguin posted:

Does anyone have any info on when Unity 4.3 drops?
What's the general take here, get 2D-toolkit and work with that or just wait for the update? (For a project that's supposed to be done in a couple of weeks.)

Do you have a pro license? If so you'll be able to do a ton of fancy stuff with the new 2D part. If not, just stick with 2dtoolkit. Even once 4.3 goes live, you aren't really gaining much over 2dtoolkit so porting over won't be much of a benefit versus just sticking with 2dtoolkit. I've played a little with 4.3 beta and while it replaces a lot of 2dtoolkit, the really nice stuff like the sprite sheet optimization is all saved for pro license holders unfortunately.

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