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
Azazel
Jun 6, 2001
I bitch slap for a living - you want some?

SlightlyMadman posted:

I'll look into 2DTollkit and SpriteManager 2 though, that's the first I've heard of them. Do they bypass the game objects?

SlightlyMadman posted:

Ah cool, that's strange to me that Unity can handle thousands of textured 3D cube objects, but not thousands of image sprites, but I guess that's the nature of the engine so it makes sense.

I exclusively use SM2, and a buddy uses 2DTK. Both are fantastic libraries for doing 2d in Unity.

I'm no sure what all the talk about exclusively doing stuff to GameObjects or not having them is about. As other experienced members have pointed it, Unity is just a component system, and GameObjects are at the core if you want transformable/renderable objects. Use what you need, remove the rest.

I've made a game that Instantiates a couple hundred GameObjects on demand and recycles them from a spawn pool after, which ran great on mid-line smartphones. Most of the bottlenecks I ran into were not having the spawn pool, not so oddly enough instantiating too many SFX at a time (which lead to a sound specific spawn pool), and poorly optimized Update loops (not caching repeated lookups, etc.). If you are talking about PC dev then most of this is nearly inconsequential.

If you are doing smartphone dev, the two biggest things you should care about are a) draw calls, and b) texture memory. The prior mentioned libraries do a great job of building sprite sheets, drawing them to an optimized mesh, and lowering your draw calls to the bare minimum number of textures loaded into memory. If all of your tiles can fit into a single sprite sheet, you will have exactly one draw call for your whole scene, even with a hundred instantiated tile objects. Having a hundred GameObject tiles in your scene at once might not be technically efficient from a nitpicky programmer point of view, but unless you are trying to run your game on an iPhone 3g or iPad 1, most of the above mentioned optimizations are probably just a waste of time.

Build the easiest case first and focus on building your game, worry about optimizing later.

Adbot
ADBOT LOVES YOU

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!

SlightlyMadman posted:

There shouldn't be any empty squares in a terrain grid, or they'd be bottomless pits. I'll probably start with water, grass, and road, although I'll need to add multiple road puzzle pieces to join them together. I'll store the buildings in a separate array, so I don't have to iterate through terrain when I want to check buildings.
In a 3D grid there would be empty squares. If you're just doing a 2D grid and drawing it in 3D then you're right, but don't model it on my code snippet!

SlightlyMadman
Jan 14, 2005

roomforthetuna posted:

In a 3D grid there would be empty squares. If you're just doing a 2D grid and drawing it in 3D then you're right, but don't model it on my code snippet!

Yep, the idea is basically a 2D game but with a 3D camera you can move and pan around things.

Shalinor
Jun 10, 2002

Can I buy you a rootbeer?

SlightlyMadman posted:

Yep, the idea is basically a 2D game but with a 3D camera you can move and pan around things.
Even if you do need empty grids, just make a prefab that is an Empty Grid Prefab. It can just be a parent object with nothing actually in it, and then there you go, a hole in the grid that doesn't evaluate to NULL.

EDIT: VV Personally, I do this kind of thing in the editor, and I either make a custom editor interface to do key/value pairs or I make two arrays - one for the Prefab GameObject, one for the string name that'll act as a key. Throw them into hash map, index via key, bing boom bam, done and user friendly.

Shalinor fucked around with this message at 03:31 on Apr 3, 2013

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:

Even if you do need empty grids, just make a prefab that is an Empty Grid Prefab. It can just be a parent object with nothing actually in it, and then there you go, a hole in the grid that doesn't evaluate to NULL.
Though I personally wouldn't instantiate an empty object to avoid nulls, it does remind me of a thing that's non-obvious that can be pretty useful - you can do
public GameObject[] Prefabs;
and then modify that array in the editor, which can be pretty useful when you're generating a tilemap from an array of numbers.

(Though in some respects it can be better to fill the array in code because then you can copy-paste it around or match the indices to const values or the like, which you can't do as easily in the editor.)

SlightlyMadman
Jan 14, 2005

Ok, that turned out to be way easier than I thought!

code:
using UnityEngine;
using System.Collections;

public class MapBehaviourScript: MonoBehaviour {
	
	const int BOARD_HIGH = 100;
	const int BOARD_WIDE = 100;
	
	const float NOISE_SCALE = 1.0f;
	
	public GameObject grassBlockPrefab;
	public GameObject sandBlockPrefab;
	public GameObject waterBlockPrefab;
	
	private Object[,] blocks = new Object[BOARD_HIGH, BOARD_WIDE];

	// Use this for initialization
	void Start () {
		float rand_x = 10f;
		float rand_y = 10f;
		int z = 0; // skip height implementation for now and leave it a plane
    	for (int y = 0; y < BOARD_HIGH; y++) {
      		for (int x = 0; x < BOARD_WIDE; x++) {
				float noise_x = rand_x + (float)x / (float)BOARD_WIDE * NOISE_SCALE;
				float noise_y = rand_y + (float)y / (float)BOARD_HIGH * NOISE_SCALE;
				float sample = Mathf.PerlinNoise(noise_x, noise_y);
				int terrainType = (int)Mathf.Floor(sample * 6f);
				switch (terrainType) {
				case 0:
				case 1:
          			blocks[y, x] = Instantiate(waterBlockPrefab, new Vector3(x, y, z), Quaternion.identity);
					break;
				case 2:
          			blocks[y, x] = Instantiate(sandBlockPrefab, new Vector3(x, y, z), Quaternion.identity);
					break;
				default:
          			blocks[y, x] = Instantiate(grassBlockPrefab, new Vector3(x, y, z), Quaternion.identity);
					break;
				}
      		}
    	}
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
I think I'm getting the hang of this, not bad:


Thanks for all your help, everyone!

Stiggs
Apr 25, 2008


Miles and miles of friends!
I'm making a little 2d platformer in Unity using 2dToolkit and I'm running across some (probably dumb) problems. I've got my little guy running around and swapping between levels and such, but each level is a different scene so when he switches between them, all of the player variables get set back to default.

For example, I've got a jump height upgrade in the first level which increases 'jumpHeight' from 300 to 380 or whatever, but when I move onto the next level it resets to 300. I'm assuming this is because in each scene in the editor, I've manually placed the Player object, so when you load each scene, it just loads a new version of the player with all the default variables?

The same problem is affecting my save/load function too, I'm using PlayerPrefs to save the level that you are on along with your position in that level, but if you saved in level 1 and then hit the Load button from level 2, it loads up level 1 but the player gets set to the default spawn location for that scene.

I'm not all that experienced with Unity so I'm getting a little stuck! Any help would be appreciated. :)

overeager overeater
Oct 16, 2011

"The cosmonauts were transfixed with wonderment as the sun set - over the Earth - there lucklessly, untethered Comrade Todd on fire."



DontDestroyOnLoad will solve the problem of stuff disappearing between scenes. You'll need to handle the case of duplicate player objects, though - I can write up the necessary code later if you'd like to.

Stiggs
Apr 25, 2008


Miles and miles of friends!

Vlad the Retailer posted:

DontDestroyOnLoad will solve the problem of stuff disappearing between scenes. You'll need to handle the case of duplicate player objects, though - I can write up the necessary code later if you'd like to.

Thanks, I'd appreciate that a lot. Or even just writing a few words on how I'd go about it myself. That's the main problem I'm running into, I can't think of a way to spawn the player into a new scene without manually placing him there in the editor. I guess I'm just unfamiliar with Unity (and component based stuff in general really), so it's taking a little while to wrap my head around it.

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!

Stiggs posted:

Thanks, I'd appreciate that a lot. Or even just writing a few words on how I'd go about it myself. That's the main problem I'm running into, I can't think of a way to spawn the player into a new scene without manually placing him there in the editor. I guess I'm just unfamiliar with Unity (and component based stuff in general really), so it's taking a little while to wrap my head around it.
You can also do it without using DontDestroyOnLoad, using static variables or PlayerPrefs. For doing it without DontDestroyOnLoad, you'd just put something in the 'Start' function of the player object that moves it to the position you're loading (make sure you don't move it when you want the player to stay where you put it in the scene!). And much the same for the jumpheight attribute, either retrieve it from save data when the scene starts, or keep it in a static variable, where it won't be changed when the scene starts (in which case, remember you need to reset it at or before the start of level 1!)

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
I'm a bit confused about the version of MonoDevelop that comes with Unity. It says it's version 2.8.2 but if you go to the MonoDevelop website it says there that there's 3.0 available but then if you click on the download link it says the latest stable version is 4.0.1? So is the version that comes with Unity just super out of date?

e: oh Monodevelop is now something called Xamarin Studio? weird

e: you know what, gently caress it I should just use Visual Studio. i like the quickness of MonoDevelop and Xamarin seems like a nice, newer version of that but both of them don't seem to support the whole "page up and down to see what variables this function takes in" that Visual Studios does. like, it pops up the window with overload options and shows you the up and down arrows to browse through them but only Visual Studio allows you to actually click on them and see what they are. for some reason MonoDevelop and Xamarin show you the arrows but nothing happens when you try to interact with them. i don't get it

Yodzilla fucked around with this message at 17:16 on Apr 3, 2013

Stiggs
Apr 25, 2008


Miles and miles of friends!
Thanks for the help guys, managed to sort out my problems.

All of you dudes that are helping people in this thread are awesome. :)

FuzzySlippers
Feb 6, 2009

Yodzilla posted:

I'm a bit confused about the version of MonoDevelop that comes with Unity. It says it's version 2.8.2 but if you go to the MonoDevelop website it says there that there's 3.0 available but then if you click on the download link it says the latest stable version is 4.0.1? So is the version that comes with Unity just super out of date?

Unity intentionally uses an old version of MonoDevelop. You can also use Unity with Sublime Text if you are looking for another lightweight alternative to VS. Its detailed here but I've only set up the proper Unity C# highlighting and haven't done the rest of the integration. MonoDevelop gets on my nerves sometimes but never so much I put in the effort to switch away completely. I end up with tiny annoyances with MonoDevelop I can't solve but they aren't big enough to switch me away. Example: MonoDevelop loves to collapse the solution explorer every time I add a new file to the project. Annoying if you are bouncing between a bunch of different files in a deep subdirectory.

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!

FuzzySlippers posted:

Unity intentionally uses an old version of MonoDevelop. You can also use Unity with Sublime Text if you are looking for another lightweight alternative to VS. Its detailed here but I've only set up the proper Unity C# highlighting and haven't done the rest of the integration. MonoDevelop gets on my nerves sometimes but never so much I put in the effort to switch away completely. I end up with tiny annoyances with MonoDevelop I can't solve but they aren't big enough to switch me away. Example: MonoDevelop loves to collapse the solution explorer every time I add a new file to the project. Annoying if you are bouncing between a bunch of different files in a deep subdirectory.
I hate that MonoDevelop does skinning to some extent, but you can't skin the drat file-browser frame which I find generally convenient to keep on screen. So I can be working in my preferred pale-grey-on-black but there's a glaring big white block at the edge of my vision, ruining the no-eye-strain goal.

FuzzySlippers
Feb 6, 2009

I actually hadn't really tried to use VS with Unity but I've been playing with it today after that post and I grabbed the trial of UnityVS. It does seem to offer some decent advantages over MonoDevelop especially now that the code in my current project has gotten large and tangled enough. Does everyone else just use MonoDevelop?

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
Why do they intentionally use an old version of the application? Especially one that seems to be rather buggy.

HolaMundo
Apr 22, 2004
uragay

sponge would own me in soccer :(

FuzzySlippers posted:

MonoDevelop gets on my nerves sometimes but never so much I put in the effort to switch away completely.

This is a great way to describe my relationship with MonoDevelop.
Almost downloaded the free version of VS for C# just to use it with Unity but the hate towards MonoDevelop never gets so far.

The Gripper
Sep 14, 2004
i am winner
On the topic of MonoDevelop+Unity, I switched to UnityVS and it's really pretty great. I preferred using Visual Studio anyway so it's a lot easier to get things done, plus resharper seems to work fine with it too!

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.

FuzzySlippers posted:

I actually hadn't really tried to use VS with Unity but I've been playing with it today after that post and I grabbed the trial of UnityVS. It does seem to offer some decent advantages over MonoDevelop especially now that the code in my current project has gotten large and tangled enough. Does everyone else just use MonoDevelop?
I got rid of MonoDevelop ASAP (specially since Unity refuses to use anything else while it exists), but then I've been using VS for years so the choice was natural, haven't tried the UnityVS Addin though. The only downside is not supporting shader files but then you usually wanna do your shader editing outside of Unity (oh you have a bug in your shader? let me just crash for you why not :v:).

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch

SupSuper posted:

I got rid of MonoDevelop ASAP (specially since Unity refuses to use anything else while it exists)

:confused: There's an option in Unity that lets you select whatever editor you want it to use. When I had Monodevelop and Visual Studio 2010 both of them were in the dropdown and then when I installed Xamarin all I had to do was navigate to the .exe and it added itself to the list.

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.

Yodzilla posted:

:confused: There's an option in Unity that lets you select whatever editor you want it to use. When I had Monodevelop and Visual Studio 2010 both of them were in the dropdown and then when I installed Xamarin all I had to do was navigate to the .exe and it added itself to the list.
Yeah I changed the preference to Visual Studio, but for some reason everytime I opened a file it'd still open MonoDevelop and only later (or never) also open Visual Studio. Maybe some file association conflict? In any case, uninstalling MonoDevelop fixed that problem for me.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
That's kinda weird. Although due to weirdness like that I've just started opening the code's .sln file instead of launching anything from the Unity project hierarchy. That way I can actually make changes to the project as a whole and it'll save properly instead of on a file by file basis.

The Gripper
Sep 14, 2004
i am winner

Yodzilla posted:

:confused: There's an option in Unity that lets you select whatever editor you want it to use. When I had Monodevelop and Visual Studio 2010 both of them were in the dropdown and then when I installed Xamarin all I had to do was navigate to the .exe and it added itself to the list.
It's a bit finicky, quite a few people have issues with it not launching VS and instead falling back onto MonoDevelop for no great reason, especially with VS2012. For a while I had to rename MonoDevelop.exe to something else just so it would absolutely give VS a chance to load before it gave up.

devilmouse
Mar 26, 2004

It's just like real life.
Speaking of VS and Unity - can you use any old version of VS 2012 or does it only work with the higher end ones?

Shalinor
Jun 10, 2002

Can I buy you a rootbeer?

devilmouse posted:

Speaking of VS and Unity - can you use any old version of VS 2012 or does it only work with the higher end ones?
Also, does it integrate the debugger (in the same attach-to-process way)?

The Gripper
Sep 14, 2004
i am winner

devilmouse posted:

Speaking of VS and Unity - can you use any old version of VS 2012 or does it only work with the higher end ones?
Any version of VS, a lot of people just use the express version. For the UnityVS add-on you need Professional, which you can get free through WebsiteSpark and Dreakspark and BizSpark from Microsoft.


Shalinor posted:

Also, does it integrate the debugger (in the same attach-to-process way)?
If you mean just setting VS as the editor in Unity, no. By default it's purely used as an editor when double-clicking files or navigating to line numbers when errors occur. UnityVS can do it really well though.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
It works just fine with 2012 Express but haven't tried using the debugger in any way.


e: woop beaten

xgalaxy
Jan 27, 2004
i write code
UnityVS works with express or pro versions of Visual Studio but some features only work with Pro.

The Gripper
Sep 14, 2004
i am winner

xgalaxy posted:

UnityVS works with express or pro versions of Visual Studio but some features only work with Pro.
The FAQ lists the Professional SKU as the minimum, and since Express can't load plugins I'm not sure what features it would support. Are you sure Express is supported?

xgalaxy
Jan 27, 2004
i write code

The Gripper posted:

The FAQ lists the Professional SKU as the minimum, and since Express can't load plugins I'm not sure what features it would support. Are you sure Express is supported?

I guess I misinterpreted what the doc said here?
http://docs.unity3d.com/Documentation/Manual/VisualStudioIntegration.html

Edit: yea, I misread. :p

The Gripper
Sep 14, 2004
i am winner

xgalaxy posted:

I guess I misinterpreted what the doc said here?
http://docs.unity3d.com/Documentation/Manual/VisualStudioIntegration.html

Edit: yea, I misread. :p
Oh yeah UnityVS is a separate third-party thing to Unity, which is probably confusing because the name doesn't really make it sound like it is.

One Eye Open
Sep 19, 2006
Am I awake?
Another useful thing with using Visual Studio is to install NShader and then set it up for Unity shader files.

As for getting it to work with the editor, I find it works fine with 32-bit Windows, but *in my experience* on 64-bit Windows it tends to not work correctly (msdev.exe is open in the task manager, but the window doesn't open, so it opens monodevelop). As I use VS2008, I just create a new solution by copy and pasting the one generated by MonoDevelop, then editing the first line from:
code:
Microsoft Visual Studio Solution File, Format Version 11.00
which is a VS2010 solution used by MonoDevelop, to
code:
Microsoft Visual Studio Solution File, Format Version 10.00
which is the 2008 header. Everything else works fine, but you have to open the solution separately and it won't open files directly from the Unity editor.

I have sent bugs to Unity, but they say "It'll be fixed in the next version" each time, which it seems to be, for about a week/first changing projects after install. I'm quite used to it now :D

Shalinor
Jun 10, 2002

Can I buy you a rootbeer?
All of these goofy workarounds, and that I shift between Mac and PC pretty often, are why I keep using MonoDevelop. Even though it does suck out loud.

devilmouse
Mar 26, 2004

It's just like real life.
I'm spending some quality time over the next few days trying to set up Win 8 in VMWare to run VS (building DLLs with MonoDevelop ughghghhg) with UnityVS and .NET Reflector / ILSpy. Maybe if I'm lucky, it'll be fast enough to not feel crappy. Right now, I'm just using emacs and ignoring all the IDE niceties on my Mac and just cursing when I have to build DLLs in MD.

There's gotta be a better way!

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
I may not be able to deploy anywhere with ease, but I love working with VS 2010/2012 with ReSharper and pure C#. I can't imagine a more efficient development environment.

xzzy
Mar 5, 2009

vim. :colbert:

Shalinor
Jun 10, 2002

Can I buy you a rootbeer?
At least you didn't say emacs.

devilmouse
Mar 26, 2004

It's just like real life.

Shalinor posted:

At least you didn't say emacs.

Do not open that box!!

At some point, I'll have to do a writeup on our silly Haxe->C#/Unity and Haxe -> Javascript Frankenstein'd monstrosity.

No Safe Word
Feb 26, 2005


VsVim, best of all worlds, plus it keeps grubby coworker hands off your code during code reviews :owned:

Adbot
ADBOT LOVES YOU

SlightlyMadman
Jan 14, 2005

No Safe Word posted:

VsVim, best of all worlds, plus it keeps grubby coworker hands off your code during code reviews :owned:

Wait, are you serious, does this exist, and is it any good?

edit- Follow-up unity question:

I decided planes will probably be better than cubes for the ground terrain, and I can do cool things like angle them to create hills. I made a new prefab for it, and associated it all of the exact same ways, but when I Instantiate it, nothing shows up.

Is there something about planes that I'm missing, different from cubes?

SlightlyMadman fucked around with this message at 00:49 on Apr 5, 2013

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