# Unity Unity 3D Gotchas?

This topic is 1810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've been programming games for a while, and just now trying out unity.  Once I got over its initial hump, I'm finding it pretty easy and nice to work with, to the point where I'm going to use it for my next game  City Builder first, and then shifting into something more robust.

My question is to any other Unity 3D Devs out there; What kind of Gothca's might I expect?  What limitations or issues have you had a hard time resolving (or not resolving) along the way?

Before I get to far into proofs for my game, I want to start looking at challenges that might be common with it.

where there unreasonable hassles?  The content loading and descriptor engine nature are really nice.

##### Share on other sites

The GUI could really use some sort of editor.  Each frame you have to draw the GUI, and respond to it, all in the same if statement.  Yes...the same function that you call to create and draw something is also the same one that returns the status of that GUI object.  Supposedly they have a new system in the works....

There was a talk at Unite 12 about the upcoming GUI and editor. Looks much better, I wish they'd hurry up and ship it.

http://video.unity3d.com/video/6943180/unite-2012-using-the-new-gui Edited by Daaark

##### Share on other sites

haha, check what I found http://unitygems.com/mistakes1/

##### Share on other sites

I agree with most of what's been said here, but I don't understand this:

Don't put stuff in the Resources folder. Resources.Load might be a tempting function, but the Resources folder is never pruned; that is everything in it goes into your build.

Why would you put something in the Resources folder that you didn't want in your build? And as long as you keep this in mind it surely works ok, right? Seems a bit excessive to never use it because of that. I mean, how would Unity know what to prune when it doesn't know what you'll need until you load it?

I more or less only use my Resources folder in my recent games because with most of my games I don't use the Unity Editor at all. They are all empty scenes and I load and create objects and maps procedurally at runtime. The Resources folder has worked fine for my needs so far. Not sure if there's an alternative to it. I put meshes in there, textures etc. and the load and assemble them at runtime.

Edited by TwiiK

##### Share on other sites

@twiik  Yeah, i see your point. I'm used to artists putting assets into our game, and they tend to do stupid things like place "level collision rev 1" and "level collision rev 2" in there, using the project as a sort of backup system. And i can't seem to get my point of why this is bad across... Ever.... So we just have a policy to not use the Resources folder. But if you know whats going on and are responsible, sure go for it.

@cdrandin, what @Sir Mac Jefferson said. If you must use GameObject.Find to get a reference, cache it once if possible. On a recent project of mine one of the programmers made a static list in a script where each game object of that type was added on awake and removed on destroy. While this gives an easy to traverse list of objects of the type i don't know how i feel about it... Kind of dirty... But that's game development.

One of the other things you want to avoid is nesting game objects too deep. If you modify a parent's transform, all it's childrens transforms are modified as well. For some reason reparenting a child takes longer the deeper it is nested. Deeply nested objects also take longer to move for some reason (I can't think of why, but this does happen). Recently we had a scroll list in one of our games that ran at ~30fps. The scroll list was nested like so GUI > Menu > Submenu > Filter > Scroll List  the scroll list had about 21 List Items, and each List Item had about 5 children, nested at most 3 objects deep. Moving all the List Items out of Scroll List and into the root of the scene (That's all, nothing else) boosted our game to about 45 fps. This is one of those minor things not many people realize makes such a difference.

##### Share on other sites

I know it's been said several times already but the GUI system is atrocious. Awful. Mixes logic with presentation? Yup. Lacks many useful controls? Yes. Stupid bugs, like various styles not working unless you add a dummy texture? Sure. Almost impossible to align things correctly? Of course! Shading and themes based on global variables? Uh-huh! It's an embarrassment that they haven't replaced it yet, but I suspect that Scaleform might have 'incentivized' them to make this less of a priority.

Other things I mentioned on Reddit recently when a similar question came up:

• No low level tweaking possible. 95% of the time this isn't a problem. 4% of the time it's a problem but you can work around it. 1% of the time it's a real irritation. I ran into a bug with the engine just yesterday, and there's no way I can fix it, only work around it.
• 2D support isn't there. Yes, you can use 3D as 2D, just like you can chop legs off a lizard and call it a snake. In practice you pay for the parts you don't use and it simply doesn't compare well to a proper 2D engine.
• The component-based system doesn't suit everybody. It's hard to use well, because hardly anybody really gets how to make the best use of components yet.
• Doesn't always play nicely with source control. It's dangerous to have 2 people working on the same scene, and updating assets while Unity is open will often corrupt the data. (Though the latter point is fixable - once you notice it - by closing Unity, deleting all the data, then updating again).

(Oh, and one more tiny thing that annoys me is that you can't just change one part of a GameObject's position, because you can't modify a Vector3, only replace it. This is only rarely an irritation, but it's an irritation nonetheless. More of a language thing than a Unity thing, but I wish they'd made that a bit cleaner.)

##### Share on other sites

(Oh, and one more tiny thing that annoys me is that you can't just change one part of a GameObject's position, because you can't modify a Vector3, only replace it. This is only rarely an irritation, but it's an irritation nonetheless. More of a language thing than a Unity thing, but I wish they'd made that a bit cleaner.)

Yeah, that is kind of annoying at times.

Just wanted to note that UnityScript (aka JavaScript) doesn't have this "disadvantage", though C# does.  Not sure about Boo, though (I've never used it).

##### Share on other sites

(Oh, and one more tiny thing that annoys me is that you can't just change one part of a GameObject's position, because you can't modify a Vector3, only replace it. This is only rarely an irritation, but it's an irritation nonetheless. More of a language thing than a Unity thing, but I wish they'd made that a bit cleaner.)

Yeah, that is kind of annoying at times.

Just wanted to note that UnityScript (aka JavaScript) doesn't have this "disadvantage", though C# does.  Not sure about Boo, though (I've never used it).

If you mean something like

thisVector as Vector3 = Vector3(1,2,3)
print(thisVector) // Vector3(1,2,3)
thisVector.y = 5
print(thisVector) // Vector3(1,5,3)



If this is what you mean then Boo can do this with ease.

##### Share on other sites

Time to add one of my own to this list:

DLL HELL!

I've found using DLL's to be a big pain

It has been said already, but vaguely.  The specific issue I had was the Visual studio can use the DLL's, Mono can use the DLL's, but unity runs into errors with them some times.  Normally, when unity finds a script/code error, its easy to go to the source of it.  I.e. double clicking it takes you to the line of code in Mono for instance.  But if it is a DLL, it doesn't express this very well, and double clicking it does nothing.  It would be nice if it actually expanded the references, or highlighted the DLL in your assets folder.

Another issue is that Unity doesn't support any cross domain issues out of the box.  For instance, I'm using a JSON database with Cloudant.com to manage user accounts (not for live interactive data, but stored data only).  The problem is that I connect through HTTPS/SSL.  SSL always fails no matter who what website you try.  it has no trusted validators for the SSL.  I had to write my own security handler for accepting it.  Not too tough, but I really don't like the security implications of taking SSL into my own hands.  It now leaves my game open to proxy redirects.  Not to big of a deal, but I'll want to fix it prior to release.

Myths:

- Unity has no 2D support is entirely false, from a programmers perspective.  It makes sense that in a 3D editor that 2D aspects are not included.  I don't expect any 2D object/images/buttons to be persistent   (similar to a prior rendering of a 3D model) - I've never really enjoyed WYSIWYG editors for game design, and proffer procedurally constructed environments.  I will definitely concede that from a Designer's point of view, that Unity has no 2D support, but if your building a game, and have more skills that what it takes to use game maker, I think you'll be fine with GUI.Draw, and managing you own 2D engine.

- After a discussion with Kylotan, he brought up some significant deficiencies I hadn't thought of.  It worked for a game concept I was thinking about at the time, but not much more.

The component-based system doesn't suit everybody. It's hard to use well, because hardly anybody really gets how to make the best use of components yet.

I'll agree that the component based system doesn't suit everyone.  Then I realized its just a basic Decorator Pattern
, which I use all the time in my 2D games for fast development and simple management.  Once I saw that, I typically start everything from the component and head away from it where I need to.  I found it nice, but I've used it before.  I would imagine that having it forced on you as a standard for the tool without training could very well be a pain.

Kylotan, on 24 Jan 2013 - 17:00, said:
(Oh, and one more tiny thing that annoys me is that you can't just change one part of a GameObject's position, because you can't modify a Vector3, only replace it. This is only rarely an irritation, but it's an irritation nonetheless. More of a language thing than a Unity thing, but I wish they'd made that a bit cleaner.)
Yeah, that is kind of annoying at times.
Just wanted to note that UnityScript (aka JavaScript) doesn't have this "disadvantage", though C# does.  Not sure about Boo, though (I've never used it)

I have to disagree here.  I'm not seeing an issue with this.  Though I'm used to using a transform instead of position when dealing with 3D.  I view the position in use of circular/spherical collision detection.  (I rely on C# instead of Java, came from an XNA world, then VB.BitBlitting, then QB.pixel/line direct, and of course text, I have java, but not as comfortably)

The issue with the input system isn't the system itself, which in general works fine.  It is the fact that you don't have access to the set configuration at run-time.  You can make the player use an external "pre-run" dialog that allows them to set the keys/inputs(and also the screen rez and detail settings), but you can't do this at run-time.  This also makes in game tutorials difficult because you don't have access to the keys the player has chosen.  But even more important than that is that you can't make your own GUI system/options menus to change the control configuration.  There exists a thing in the Unity Asset Store that costs \$20 I think, that replaces Unity's input system with similar function calls, but allows you to either use a default GUI to set keys, or use your own, all at run-time, and you also get access to which key the player has chosen, which is good for tutorials.

I don't see an issue with this either.  I find their current named system for buttons to have been refreshing to see, but it really is just a named collection.  Named collections are ok, but it adds a list search every time a button is pressed to see if it is in the named button calls, and a list search for the name/key reference every time the name is used.  I tend to expect to lock in keys, or set a static variable somewhere for each key.  It can change by config, but that is still faster than the the named list by a factor of [2+ (0.5*Named Command List Count)]

I suppose a lot of the complications everyone has mentioned also stem from backgrounds, particularly Coder vs Designer. With any thing I found not to have an issue with (yet) it seems it is usually a designer/coder/perspective issue.  Overall, these have been very helpful for me.

Edited by hpdvs2

##### Share on other sites

Unity has no 2D support is entirely false, from a programmers
perspective.

It has less 2D support than almost every other game development library or framework available. It's an engine that literally features drag-and-drop 3D support, in that you can get a 3D model rendering and animating on screen without a single line of code, but has nothing resembling similar support for 2D.

if your building a game, and have more skills
that what it takes to use game maker, I think you'll be fine with
GUI.Draw, and managing you own 2D engine.

I think you mean GUI.DrawTexture, which needs to be in the OnGUI function (which is inefficient if you don't know the tricks for it, eg. skipping rendering when the current event is a keypress etc), and most importantly, only works if your image meets a set of quite specific criteria. Only want to render part of the texture? Have to calculate the UVs yourself and use GUI.DrawTextureWithTexCoords. Want to use a non-power of two texture? Probably won't work at all.

It's adding insult to injury really that Unity features an automatic atlasing and mesh generating tool for fonts, but can't do something trivially similar for sprites.

Basically, if 2D is your most important aspect, it's hard to argue that Unity saves you much time over just writing DirectX or OpenGL code yourself. Pretty much any other system, eg. Flixel, XNA, SDL, Cocos2D, pyglet, SFML, etc etc., gives you better 2D support.

I'll agree that the component based system doesn't suit everyone. Then I realized its just a basic Decorator Pattern

I think you have misunderstood the decorator pattern, which is specifically about making a certain function or method call do different things by wrapping the call in another call.

##### Share on other sites

I have to concede on the image issues.  I'll append this to my original statement.  for my usage of it, it seems to handle all the basic features I want.  But you make a good point about it not working well with sprites, as you have to reprocess the UVs

which is inefficient if you don't know the tricks for it, eg. skipping rendering when the current event is a keypress etc

That is particularly interesting.  I can't imagine why that would help.  Do you have a link to anything that explains the issue?

Basically, if 2D is your most important aspect, it's hard to argue that Unity saves you much time over just writing DirectX or OpenGL code yourself. Pretty much any other system, eg. Flixel, XNA, SDL, Cocos2D, pyglet, SFML, etc etc., gives you better 2D support.

After the rest of your post, this makes sense in general, but I will argue one point.  Unity is will placed to execute on a lot of environments.  that gives it more clout than DirectX, XNA or a lot of others.  But the Multi-OS issue is probably about the only thing, and if its just 2D, Java would probably be the most flexible.

I think you have misunderstood the decorator pattern, which is specifically about making a certain function or method call do different things by wrapping the call in another call.

In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class. - Wikipedia

It adds a behavior to a class.  There is no limitation as to whether that is as an object or a method.  I typically use it as a series of interfaces, like IModify, IPaint, IDelete, etc...  Then I would create objects like FrictionModifier : IModify, and then add copies to lists on the gameObjects of choice so they have friction, or gravity, or EnemyMissileCollision, etc...

If you perceive the decorator pattern as object based, instead of method based, then its the same principal.  You tie an object that inherits the BehaviorModifier to the gameObject of your choice, and their properties apply without affecting the rest of the game objects of the same type.  I can see the benefit of method based Decorators, but with objects, I found it easier to apply custom alterations per gameObject.

But back to the core concept of my quote, no 2D support is entirely false, I agree that it is partially false.  Depending on your needs for a 2D game, their stuff would be really annoying.  For a 2D space shooter with individual images, and not a lot, it seems like it would work just as well as most other basic 2D engines.  Sprites and a UI Designer, not so much.

• 11
• 11
• 9
• 12
• 10
• ### Similar Content

• So I am building a turn based rogue-like (think CDDA). The game is going to have a very large map (up to 1000's x 1000's) however to alleviate most of that I obviously can't render everything so there will just be render a certain radius around the player and just load in and out data as the player moves.
The next major system I am prototyping is making interactive tiles destructible and pretty much everything will be destructible besides basic landscape (cars, doors, windows, structures, etc. will be destructible)
While I am only rendering a certain amount of tiles around the player, I want to keep the amount of colliders active at one time to be as small as possible for performance and currently the tilemap tool I use automatically merges colliders together.
So instead of creating a separate colliders for each of these tiles and having the destructible behavior tied to that object (which my tilemap tool would allow me to do) I was thinking that I would store an array of all the X and Y locations for the interactive tilemap layer and let the tilemap manage the colliders.
Then when I hit a collider on the interactive tilemap layer, instead of of getting the behavior for how to deal with the destruction for that tile from that game object, I would pull it from the array I mentioned earlier based on the tile I attempt to interact with which I already have.
Does this sound like a good approach? Any other recommendations would be welcomed.

• Hey guys,
I have a really weird problem. I'm trying to get some data from a REST service. I'm using the following code:

private void GetTheScores() { UnityWebRequest GetCommand = UnityWebRequest.Get(url); UnityWebRequestAsyncOperation operation = GetCommand.SendWebRequest(); if (!operation.webRequest.isNetworkError) { ResultsContainer rez = JsonUtility.FromJson<ResultsContainer>(operation.webRequest.downloadHandler.text); Debug.Log("Text: " + operation.webRequest.downloadHandler.text); } } The problem is that when I'm in Unity's editor, the request doesn't return anything (operation.webRequest.downloadHandler.text is empty, the Debug.Log command just prints "Text: "), but when I enter the debug mode and insert a breakpoint on that line, then it returns the text properly. Does anyone have an idea why is this happening?
The real problem I'm trying to solve is that when I receive the text, I can't get the data from the JSON. The markup is really simple:
[{"id":1,"name":"Player1"},{"id":2,"name":"Player2"}] and I have an object that should accept that data:
[System.Serializable] public class ResultScript { public int id; public string name; } There is also a class that should accept the array of these objects (which the JSON is returning):
[System.Serializable] public class ResultsContainer { public ResultScript[] results; } But when I run the code (in the debug mode, to get any result) I get an error: ArgumentException: JSON must represent an object type. I've googled it but none of the proposed solutions work for me.
Also (regardless if I'm in the debug mode or not) when I try to do some string operations like removing or adding characters to the GET result, the functions return an empty string as a result
Can you help me with any of these problems?
Thank you
• By nihitori
The Emotional Music Vol. I pack focuses on beautiful and esoteric orchestral music, capable of creating truly emotive and intimate moods. It features detailed chamber strings, cello and piano as the main instruments, resulting in a subtle and elegant sound never before heard in video game royalty-free music assets.

The pack includes 5 original tracks, as well as a total of 47 loops based on these tracks (long loops for simple use and short loops for custom / complex music layering).

A 15 seconds preview of each main track is available on Soundcloud:

• Another one of our new UI for #screenshotsaturday. This is the inventory screen for showing what animal fossils you have collected so far. #gamedev #indiedev #sama

• We're looking for programmers for our project.
Our project is being made in Unity
Requirements:
-Skills in Unity
-C#
-Javascript
-Node.js
We're looking for programmers who can perform a variety of functions on our project.
Project is a top-down hack-and-slash pvp dungeon-crawler like game. Game is entirely multiplayer based, using randomized dungeons, and a unique combat system with emphasis on gameplay.
We have a GDD to work off of, and a Lead Programmer you would work under.
Assignments may include:
-Creating new scripts of varying degrees specific to the project (mostly server-side, but sometimes client-side)
-Assembling already created monsters/characters with existing or non-existing code.
-Creating VFX
This project is unpaid, but with royalties.

---