benArcen

Unity Questions Thread

Recommended Posts

I thought you might be dealing with a significantly large list of scenes if you wanted it to be completely dynamic. If it's only a handful then you should be fine. Some people create a scene for each level, which isn't really necessary, and you can easily map prefab levels in a more static way.

I think it's probably best just to use a few constants in this case. It'll smell less than retyping the scene name in multiple places.

Share this post


Link to post
Share on other sites

Yeah that'll only work in the Editor, but you can take the results and build a manifest you can reference later. But these kinds of solutions smell worse than a few hard coded strings.

Share this post


Link to post
Share on other sites

It blows my mind that Unity's a mature platform using OO principles and scene loading's still done with strings.

 

For this prototype it'll be fine, but the intention is eventually to have a lot more levels so I'm going to have to look into prefabs one of these days.

Share this post


Link to post
Share on other sites

If you are using them like levels then I personally think you should use a single scene for your gameplay and put the dynamic content into prefabs representing each level.  It'll mean that you don't repeat core components across all your scenes.

Share this post


Link to post
Share on other sites

If you are using them like levels then I personally think you should use a single scene for your gameplay and put the dynamic content into prefabs representing each level.  It'll mean that you don't repeat core components across all your scenes.

 

Hmm, this raises further (and much less frustrated) questions!

 

From my understanding, prefabs allow you to package up a collection of objects into one, and future objects can derive from the prefab. I'm using prefabs for my player character and enemies, and I'll probably use them for the controller and UI objects and any modelled objects I create. Most of my levels are terrain data, with box colliders for checkpoints, with defined start and end points where players go back out to a world map. Are you saying that, for stuff that's being used once and one at a time, prefabs are still better?

Share this post


Link to post
Share on other sites

Yeah prefabs are great for single use objects. In this case they're better because you can map them explicitly to a field in a component so you won't have to use strings to load your levels.

Share this post


Link to post
Share on other sites

Does anyone have experience building Unity games for Windows Store and know of good guides/resources for doing so? I wanted to experiment a bit with touch controls, and I'm finding this process pretty aggravating and lacking in docs. I ended up downloading both the Windows 8.0 and 8.1 SDKs, then two separate versions of Visual Studio 2013 and eventually got it to work but it wasn't a pleasant experience. I get the feeling some of my frustration might be that I'm doing this from a Surface Pro, but it runs Windows 8 so I don't know why it would matter.

 

I think the physics simulation is a little bit different now too, forces seem to be just a little stronger than they were. So if anyone knows of a place that talks a bit about these quirks (and what ever other potential issues I might hit) that'd be really useful. I was initially reading these http://docs.unity3d.com/Manual/windowsstore-gettingstarted.html but they're sort of vague in places, and didn't mention the version of VS I ended up needing.

Share this post


Link to post
Share on other sites

Does anyone have experience building Unity games for Windows Store and know of good guides/resources for doing so? I wanted to experiment a bit with touch controls, and I'm finding this process pretty aggravating and lacking in docs. I ended up downloading both the Windows 8.0 and 8.1 SDKs, then two separate versions of Visual Studio 2013 and eventually got it to work but it wasn't a pleasant experience. I get the feeling some of my frustration might be that I'm doing this from a Surface Pro, but it runs Windows 8 so I don't know why it would matter.

 

I haven't worked much with the Windows store Unity development, but I would imagine their touch functions would work just like they do for Android/iOS.  You can find more info in the Unity script reference which has been greatly improved in the last couple of months.  Personally I still use Visual Studio 2010 for Unity projects, although I am still using Windows 7 so I can't comment on the compatibility with Windows 8.

If you are looking for information on how to use Unity specifically related to Windows store development, I'd suggest checking out Microsoft's Channel 9.  They have a number of general how to tutorials, some related to Unity, that go over what types of gestures exist and how to use them as well as general programming concepts.

Share this post


Link to post
Share on other sites

Microsoft actually hosted a few porting events for Unity developers.  Unfortunately I didn't go, but if you're still interested I could reach out to the guy that ran them and see if he has any online resources.

Share this post


Link to post
Share on other sites

I actually attended one of these Microsoft events, and it was very informative ( i also won a free phone so that was cool).  Basically the windows phone/metro builds of unity are radically different than any other platform.  As it stands now, Unity uses .net 2.5 (I may be wrong on the exact version), on every deploy target except windows phone/metro.  On those builds Unity compiles out to use the latest version of .net (4.5 i believe at the moment), so that the code can run natively on these devices.  So theoretically, you should be getting better performance on these devices ( key word there being theoretical ).  Microsoft has been working directly with Unity to make this change happen, but as you can imagine there are quite a few bugs/quirks in this version, as they are having to re-write a ton of stuff to update to the latest version of .net. The Unity forums for windows development (http://forum.unity3d.com/forums/windows-development.50/) is a great place to see a bunch of these issues brought to light and discussed.  Unfortunately there aren't a ton of fixes for most of the issues at the moment.

 

As far as getting the dev environment setup, I had to use windows 8.1 with the 8.1 sdk (don't mess with the 8 sdk as it is out of date) installed into the latest version of VS 2013.  The process is not well documented and a huge pain to get working correctly.  On top of getting the dev environment setup, you will have to worry about 3rd party plugins from the asset store. Because of the changes I listed above, a lot of the plugins from the asset store will just break.  Basically anything that is trying to do file i/o is going to be busted, unless of course the developer of the plugin specifically states that it is tested on wp8/metro builds.  I spent most of my time "porting" my game to wp8 installing the the correct sdk and then stripping my game of most of my 3rd party assets/plugins.

 

As far as touch input goes I only have experience with the wp8 builds, but in that case the input functionality works identical to the iphone/android builds.  I would assume the same would hold true for windows store (metro) builds.  I hope this helps, but to be honest this is an undocumented learning experience for us all

Share this post


Link to post
Share on other sites

I hope this helps, but to be honest this is an undocumented learning experience for us all

 

That actually is very helpful, thanks! Also just good to know that I'm not alone in finding this bizarrely difficult. It felt like I was missing some really obvious source of documentation, but nope, it just doesn't exist.

Share this post


Link to post
Share on other sites

The game I'm working on requires that I hold down multiple keys while also using other keys for repeatative input. So for instance, I want to be able to hold down 'r' and 't' while also using pressing down 'left' and 'right' arrow keys in an alternating fashion. Sometimes I run into keys that just don't seem to work in combination. In this case, it's 't'. I can't get 'right' input on the horizontal axis if I'm holding down 't' and any of these other keys at the same time: r,e,w,q. But the 'right ' input on the horizontal axis will work if I hold down 't' with 'y' at the same time or just 't' alone. I looked through the axis in the input-section of the inspector in "project settings" but 't' doesn't seem to be bound with anything that would create this conflict. Anyone one know what is going on or a good search-term for this type of thing?

Share this post


Link to post
Share on other sites

I can't get 'right' input on the horizontal axis if I'm holding down 't' and any of these other keys at the same time: r,e,w,q. [...] Anyone one know what is going on or a good search-term for this type of thing?

 

I don't know if this is your problem, but I've had some keyboard hardware issues with this in the past. Some keyboards are designed to handle a maximum number of keypresses at once, and some I think can only handle a certain number of keypresses from specific regions of the keyboard? No idea if Unity has any limitations that might also be causing issues, but I know it can be a physical keyboard construction problem too. This post kinda explains some of it:

http://www.microsoft.com/appliedsciences/antighostingexplained.mspx

Share this post


Link to post
Share on other sites

I don't know if this is your problem, but I've had some keyboard hardware issues with this in the past. Some keyboards are designed to handle a maximum number of keypresses at once, and some I think can only handle a certain number of keypresses from specific regions of the keyboard? No idea if Unity has any limitations that might also be causing issues, but I know it can be a physical keyboard construction problem too. This post kinda explains some of it:

http://www.microsoft.com/appliedsciences/antighostingexplained.mspx

 

Thank you. I used the applet at the top of the page you linked and it demonstrated that this is the problem.

Share this post


Link to post
Share on other sites

I actually didn't know what that was called until I looked it up today. The title of that article is hilarious though, "Anti Ghosting Explained" sounds like the subtitle of Ghostbusting for Dummies.

Share this post


Link to post
Share on other sites

pixelimperfection.png

 

I'm finally working on a thing again. It's just a simple platformer, yo. Which is great, I love platformers.

 

Anyway, I have no idea why these blocks aren't aligned. The big stuff is zoomed in version of the little stuff to make it easier to see.

 

They're in the exact same position, vertically speaking, and they're of the same dimensions, in terms of width and height, and yet they're misalligned. As I move the player around (and thus the camera, which follows the player), the lava block (yeah, that's lava, shut up D: ) jitters around both vertically and horizontally, so that it's sometimes aligned correctly, but mostly not.

 

ANY IDEAS?

Share this post


Link to post
Share on other sites

They are, but that's not the problem*. It persists if they're not animated. I actually fixed the jittering - forgot to make my camera size the correct size. So now the sprite doesn't shake around as the camera moves. But it is still misalligned. Now just permanently one pixel up and to the left.

 

pixelimperfection2.png

 

There's also this problem where the dude there, that animation frame seems to be grabbing one pixel to the left (and, since I bet it's related to this lava issue, up!) from the sprite sheet. The blue crystals similarly suffer, but not at this particular frame apparently.

 

*EDIT: Based on my thoughts as I wrote this post, I think the problem is how Unity's grabbing the sprite from the sprite sheet? Well, it might not be a problem WITH Unity, but there's clearly a problem here, and I think it's related to the sprite sheets. Because even when the lava wasn't animated, it was still pulling from the sheet.

 

EDIT EDIT: No, that doesn't make sense. The colored tiles all around are also pulled from a sprite sheet, just a different one.

Share this post


Link to post
Share on other sites

uh i fixed it

 

I forgot I'd changed the resolution to "Free Aspect", which breaks things OF COURSE when you're trying to do pixel-perfect rendering for pixel art with an orthographic camera. Ehehehhehe.

 

What I should do is make a script to automatically change the orthographic camera size based on resolution, but I've been lazy. I guess I'll do that now!

 

There's also this: https://gist.github.com/pixelrevision/2981863

Share this post


Link to post
Share on other sites

This is more of a C# question than a Unity question, and I feel so embarrassed for asking it. I've done a bunch of programming before in various languages, but never much C#. It feels like every solution I come up with in C# for things feels like it could somehow be the wrong solution and end up creating various horrors.

 

Are there any good resources for best practice design patterns for working with Unity? For example, if I have something like character abilities that I want to implement, right now I'm writing an ability base class then creating a class that extends from that base class for each ability in a separate namespace. Is this the right pattern? I know it will work, but I just want to make sure there's not some special feature of the language I'm missing that would be a more natural fit.

 

I know I should just slog through a primer on C#, but actually making a game is more fun.

Share this post


Link to post
Share on other sites

I think a key with Unity is figuring out how to work in such a way that you get the most value out of being able to tweak data in the inspector. So for instance in a project I've set up AI behaviors such that you can add a behavior manager to a prefab, then add each behavior (that derives off a base behavior class), and it will prioritize behaviors based on an order that you specify in the inspector. Each behavior also has its own inspector-tweakable values.

 

But if you're creating (say) player abilities in a single-player game where you control a single character, I don't think there's necessarily much point to keep them in different classes, because you're not going to be mixing and matching the abilities on different characters. But if it helps you logically think about the abilities to have them separated into different classes, I don't think there's anything fundamentally wrong with it.

 

Also, I usually just keep all of my Unity stuff namespace-less, because I don't think things deriving from MonoBehaviors actually support being in namespaces and working properly? At least that's what I've heard :P

 

This resource may have been linked already, but I've gotten a lot out of it: http://devmag.org.za/2012/07/12/50-tips-for-working-with-unity-best-practices/

Share this post


Link to post
Share on other sites

This is more of a C# question than a Unity question, and I feel so embarrassed for asking it. I've done a bunch of programming before in various languages, but never much C#. It feels like every solution I come up with in C# for things feels like it could somehow be the wrong solution and end up creating various horrors.

 

Are there any good resources for best practice design patterns for working with Unity? For example, if I have something like character abilities that I want to implement, right now I'm writing an ability base class then creating a class that extends from that base class for each ability in a separate namespace. Is this the right pattern? I know it will work, but I just want to make sure there's not some special feature of the language I'm missing that would be a more natural fit.

 

I know I should just slog through a primer on C#, but actually making a game is more fun.

 

In regards to namespaces, you can use them and I believe as of the more recent versions of Unity they are supported, its just that in the past they would cause problems.

 

Generally when working with Unity I try to make classes that are as independent as possible from one another.  For example, to make a RPG style Character class like Jason Mentioned you could do the traditional inheritance based route (Actor > RPGCharacter > Player, etc) and really there is nothing wrong with that.  The one concern it brings up is that you aren't leveraging the design philosophy of Unity, in that entities can be created by attaching arbitrary components to GameObjects.  In the end, this approach will actually make your project more flexible and allow you to reuse those components easily.  For example, in my current project we have separate components for applying damage, Health, inventory, locomotion, pathfinding, behaviour control, etc.  Then when I want to make a complex entity I just slap on a bunch of components.  It also allows you to do some pretty cool things like just attach a health component to an object in the world, and then write an item drop component that listens for the object's death event and spawns items, or create a deadly spike by just attaching a contact damage component to the model.

Rather than drone on about all the intricacies, I'll just say that no way of writing code in Unity is wrong.  In my projects I tend to try and create classes that can have their functionality changed based on a few flags (for example, any type of gun imaginable can be created using a single script as opposed to multiple child classes), but I still use inheritance here and there.  Really the whole point of Unity is to make games however you feel comfortable, but if you're willing to buy into their design philosophy you can end up doing a lot more with a lot less.  One thing to watch out for is, because of the open-ended nature of Unity, project management and organization can get out of control quickly.

 

Personally I learned on XNA (C# was my first language) and some of the flexibility of C# can seem a bit weird.  I still run into situations where I find some feature of C# that I never knew existed, but for the most part this is just shorthand or syntactic sugar (For example get/set properties vs methods).  Again, there is no wrong answer, just whatever you are comfortable with.

Share this post


Link to post
Share on other sites

Thanks for the advice guys. I've made a few things in Unity prior to my current project, and I think the way I'm doing it now is the best fit for me. Thanks for the sanity check.

 

I find the inspector really tedious to work with, and so I mostly just use it to debug and prototype. I really don't like building content in it because managing a ton of prefabs seems like a real pain. I'm much more comfortable working with code directly. I think I ran into not being able to put GameObjects in namespaces, but that didn't really bother me too much because of how I have structured my project.

 

I'm doing a kind of MVC pattern where my Controller and View are being handled by Unity while my Model is built with classes that do not inherit from any Unity classes in order to make implementing my game systems more straight-forward. The smaller projects I developed before got out of hand pretty quickly when I tried to use Unity stuff for everything. Development on my current project has gone a lot more smoothly because I can leverage Unity's nested object system for stuff like graphics/camera/animation/sound while not having to wrestle with it to implement the core of my game.

 

So instead of having to make a bunch of different prefabs I'm making generic prefabs for each class of objects that are instantiated as the View and configure/update themselves in reference to the model that's running independently behind the scenes.

Share this post


Link to post
Share on other sites

Does anyone know of a good set of (preferably non video) tutorials on using Unity's shaders?

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