benArcen

Unity Questions Thread

Recommended Posts

What is this for?  If you are interested in scene serialization as a way of creating save games, there is actually a package on the asset store that will serialize the entire scene in a line or two of code.  So long as your saving mechanism writes all the properties you want for the Difingo class, those properties can be recalled.

 

Just a heads up about that project.  While super useful and easy, it doesn't work across all platforms (namely Windows store/Windows Phone) and the author seems to have dropped off the face of the earth in regards to updating the project or responding to emails.  I was using this project until I decided to port a WIP game to WP8 and it just completely blew up.  I found this project  that works pretty well: https://www.assetstore.unity3d.com/en/#!/content/768

 

That project does require a bit more setup and knowhow, but it is also a lot less "black box" in how it stores everything.  basically you are in full control of the saving scheme.  I have been using it in my very complex game with no issues for quite some time now.  If anybody needs help with it pleas pm me.

Share this post


Link to post
Share on other sites

Right now my characters have all of their weapons already in their hierarchy when they spawn. I'm trying to switch over to a system where their weapons are instantiated from a generic prefab so that they can inherit changes from the prefabs rather than having to be changed individually, can be easily swapped, and so on.

However, the position and rotation of the weapons need to be set to specific values so they fit into the character's hand properly, and there seems to be some kind of difference between the way Instantiate() works vs simply dropping an object into a scene. I have a sword prefab that, if dropped onto the relevant transform in the editor shows up in the proper position, but if instantiated in script with the exact same values for position rotation, and parent, ends up floating off to the character's side.

Does anybody know what's going on here or what I can do about it?

Edit: Figured it out. I needed to be setting the local position and rotation, not the world ones. The editor doesn't really specify which one you're changing, but in scripts you need to be specific.

Share this post


Link to post
Share on other sites

Right now my characters have all of their weapons already in their hierarchy when they spawn. I'm trying to switch over to a system where their weapons are instantiated from a generic prefab so that they can inherit changes from the prefabs rather than having to be changed individually, can be easily swapped, and so on.

However, the position and rotation of the weapons need to be set to specific values so they fit into the character's hand properly, and there seems to be some kind of difference between the way Instantiate() works vs simply dropping an object into a scene. I have a sword prefab that, if dropped onto the relevant transform in the editor shows up in the proper position, but if instantiated in script with the exact same values for position rotation, and parent, ends up floating off to the character's side.

Does anybody know what's going on here or what I can do about it?

Edit: Figured it out. I needed to be setting the local position and rotation, not the world ones. The editor doesn't really specify which one you're changing, but in scripts you need to be specific.

 

I did something similar with my weapon mounting, but rather than saving specific sets of local transform values somewhere for every weapon and use that as the instantiate parameters, I positioned each weapon correctly parented to the weapon hand, then created a new empty gameobject at that same position/rotation, parented the weapon to it, and then saved that empty gameobject (with child weapon object) as my weapon prefab. That way, each weapon prefab's root is an empty gameobject with the weapon object parented to it with the correct offset, so I could just instantiate them right on the hand with no position/rotation fiddling.

Share this post


Link to post
Share on other sites

I did something similar with my weapon mounting, but rather than saving specific sets of local transform values somewhere for every weapon and use that as the instantiate parameters, I positioned each weapon correctly parented to the weapon hand, then created a new empty gameobject at that same position/rotation, parented the weapon to it, and then saved that empty gameobject (with child weapon object) as my weapon prefab. That way, each weapon prefab's root is an empty gameobject with the weapon object parented to it with the correct offset, so I could just instantiate them right on the hand with no position/rotation fiddling.

 

 

I did the same type setup for my game.  In my game you build out a aircraft with numerous parts and pieces.  To keep everything straight and looking correct, for each part available there are two spawnpoints that are nothing more than empty GOs that carry the proper rotation and location.  When instantiating a new item you find the spawnpoint where you want it to go, instantiate it, and then parent the new item to the spawnpoint transform.  As a child, a GO will inherit it's parent's rotation and location upon instantiation, so you can safely assume that the new item will be in the correct position with the correct rotation (if your instantiated item's local rotation and position are zeroed out ).  Now if the new instantiated item has a spawnpoint as well, then you can create very interesting "trees" of items that will just always work.

Share this post


Link to post
Share on other sites

NGUI is on sale today.

This is the same situation I was in with the Playmaker sale. I feel like I should buy it just because it's mentioned as a very popular tool, though I have no idea what I would use it for. Anyone know what this can do that a 3d text child can't?

Edit: I'm leaning towards saving my precious gaming-budget and waiting to see how 4.6's UI system turns out

http://blogs.unity3d.com/2014/05/28/overview-of-the-new-ui-system/

Share this post


Link to post
Share on other sites

NGUI is on sale today.

This is the same situation I was in with the Playmaker sale. I feel like I should buy it just because it's mentioned as a very popular tool, though I have no idea what I would use it for. Anyone know what this can do that a 3d text child can't?

Edit: I'm leaning towards saving my precious gaming-budget and waiting to see how 4.6's UI system turns out

http://blogs.unity3d.com/2014/05/28/overview-of-the-new-ui-system/

 

Honestly, its just the ease of use. Once you understand the setup everything is very nicely WYSIWYG, and integrating fonts and stuff is really easy too, for 1-drawcall GUI's. Scaling for resolution out of the box is nice too, and the library of easy tweens and triggers (for sound fx and stuff).

 

I concepted a spell casting system for my game a few weeks ago, mocked up the GUI, then had it integrated into NGUI within a couple hours, with some nice bells and whistles like animations, shakes, sounds, etc.. You can check it out here if you want:   http://dl.dropboxusercontent.com/u/14673841/Runeweaving/Runeweaving.html

 

Hit 'R' to open the "runeweaving" GUI  B)

 

You could probably make that with billboards, 3d text's and GUITexture's, but it be an awful lot of work, and it wouldn't be atlased for one drawcall.

Share this post


Link to post
Share on other sites

NGUI is on sale today.

This is the same situation I was in with the Playmaker sale. I feel like I should buy it just because it's mentioned as a very popular tool, though I have no idea what I would use it for. Anyone know what this can do that a 3d text child can't?

Edit: I'm leaning towards saving my precious gaming-budget and waiting to see how 4.6's UI system turns out

http://blogs.unity3d.com/2014/05/28/overview-of-the-new-ui-system/

 

Everything PrimeDerektive said is absolutely true, but I would add that the built in 3d text should not be used in most cases for UI b/c it is just way too heavy.  With a sprite based UI, you are dealing with very minimal overhead computationally, while the 3d text can contain gross amounts of vertices that have to be updated on each frame. I have used it the 3d text before and it can be nice for a title screen or something like that, but if you are using it solely for your UI then you are adding a ton of unneeded weight to your scene.

 

As far as wether you should buy NGUI or wait for the new Unity implementation, that is a tough question.  NGUI is very well supported and constantly updated.  I would say that once the new Unity UI is added, NGUI will be updated to take advantage of that system and make it even better.  Considering the guy who wrote NGUI was hired by Unity to help with the new UI it is a safe bet that NGUI is going to be a "better" version of that system.

Share this post


Link to post
Share on other sites

 Considering the guy who wrote NGUI was hired by Unity to help with the new UI it is a safe bet that NGUI is going to be a "better" version of that system.

 

He did however quit, though, in November  :blink:

Share this post


Link to post
Share on other sites

He was leading the team, but there were 4 or 5 other people working on it as well. They all remained on the project after he left. And he seems to have left because the project was nearing completion and unity was putting it through extensive alpha and beta testing.

It was originally being built as a straight NGUI port. So much so that he offered to write a conversion tool for NGUI users. They had access to low leel optimizations that he said were impossible as a plugin author, so I do think it'll be the smart call once 4.6 is released.

Share this post


Link to post
Share on other sites

Can anyone provide some tips on optimal ways to lay out a bunch of tiles in Unity? If you know how to do anything of the following:

 

- Easy way to snap tiles to a grid neatly and quickly

- Lower the total amount of GameObjects needed to tile

- easy way to lay down colliding boxes over these tiles

 

So far this is the mess I've gotten myself into:

 

VPku2Px.png

Share this post


Link to post
Share on other sites

If you're doing 2D stuff, there's no built-in tiling feature yet. There are plugins, but I can't remember the names of any. If you ask on the 2D forums http://forum.unity3d.com/forums/2d.53/ they might be able to point you in the right direction.

Share this post


Link to post
Share on other sites

There are actually a few tricks for getting objects to line up nicely.  First is to turn on The Grid Snap Feature, but one I use a lot is the vertex snap feature.  Just hold down the V key, Click on the vertex of an object, then drag it over to another object.  You'll see it start popping around the scene trying to snap to various vertices.  Once you have the position you want, just release the mouse button.  There are a few more tricks you can check out here.

Share this post


Link to post
Share on other sites

Go to the snap settings and configure them to the tile size. Then hold ctrl or command while dragging your pieces around and they'll snap.

It's worth noting that the snap size is relative to an objects current position rather than an absolute grid snap on global positions.

Also you can use vertex snapping by using the V key. But it's a bit more fidgety.

Share this post


Link to post
Share on other sites

Just saw mosses reply after typing all that out on my phone.

Share this post


Link to post
Share on other sites

Oh I misread the question! Yeah there's some grid snapping features. I thought you were asking about actually tiling a sprite so that it'll repeat based on the size of the object you're trying to create, rather than just stretch!

Share this post


Link to post
Share on other sites

I have been using these tools for the past year or so and cannot imagine using Unity without them: http://www.protoolsforunity3d.com/

I know that they may be expensive, but trust me, they are worth every penny.  

 

There is a "pro grids" tool that should be exactly what you are needing.  It has lots of options and makes using Unity soooo much better.

Share this post


Link to post
Share on other sites

How would I use PlayOneShot() to play a clip 440 times a second?

Share this post


Link to post
Share on other sites

Do you mean at equal intervals? If so it's challenging to get anything done at that rate given the games frame rate will be nowhere near. 440/s

Maybe I'm unclear with exactly what you want? Is it just a lot of sounds at once, or a music like procedural track?

Share this post


Link to post
Share on other sites

I'm basically trying to make a music-tracker in Unity so that I can have procedural synth sounds. I made a 1kb .wav in Open MPT and I've imported it, but adjusting the pitch seems to adjust its dominant frequencies rather than its actual frequency/pitch while looping. I was firing it off in Update() and it was giving me a 60hrtz signal (predictably).

Share this post


Link to post
Share on other sites

So after what I think is a reasonable amount of digging, I still can't work how to avoid using magic strings in my code to refer to my scenes. I'm making a very simple game that has several levels, and I want to pass scores between the levels and a map scene. However, I can't work out how to actually tie my scene objects to any code - it doesn't look like I can assign scenes to variables, I can't work out how to grab their names, and it doesn't look like I'm even supposed to be using the strings I gave them as a name in favour of having hardcoded scene names in strings somewhere!

Share this post


Link to post
Share on other sites

If you're really bugged by the strings being repeated, you can create const string values, or use an enum and convert its name using ToString().

There are other options like script able objects, but if you're planning on creating truly dynamic scene loading you'll be blocked by build settings which require each scene to be included manually.

Another option is to question whether they truely need to be distinct scenes or if prefabs would work.

We created a static class called SceneManager that handles all scene transitions as well as can store a map of data we want to pass between scenes. It holds our enum of scene names and by centralizing scene switching it's allowed us to do things like native hooks and state saving between scene loads.

Share this post


Link to post
Share on other sites

I don't need dynamic scene loading, I just want to use the names I've already given the scenes instead of defining two names, one in the editor, and one in the code. (I was going to also have an object in each scene with some details about the level, but now I'm thinking that Unity would prefer me to associate that information with a LevelInfo object that contains all the levels.)

 

Another option is to question whether they truely need to be distinct scenes or if prefabs would work.

 

Could you give me more information about this? I don't think I understand prefabs enough to judge whether this is a better solution. (Is this implying that having more than a few scenes in your game is a bad idea?)

 

You could attach a script to an empty GameObject with all the data you want to pass between scenes, and call DontDestroyOnLoad to keep it in your scene hierarchy when changing levels.
 
I'm not having a problem with communicating between scenes (and it's like the first question people ask, Google sorted that out easily). My problem is, when I fire up a new scene with Application.LoadLevel(levelName), I don't know how to derive the levelName from the name of a scene in my game.
 
I can work around it easily, but I don't want to, because it's got the wrong code smell. (I would be just as satisfied if I could rename the scenes from strings in my code - just so long as there's one place where my code and the Unity engine both get the scene name from.)

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