• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

GAF Learns - Unity [Game Engine]

Persona7

Banned
I wish I could easily be able to program...I forget almost everything I learned years ago.

Maybe I should start with twine for the time being.
 

Makai

Member
I'm ingrained in OO design and I just can't wrap my head around MonoBehaviours. I need my objects to have constructors. I just have one Empty GameObject with a MonoBehaviour script that contains all of my game logic and instantiate everything in script.
 

xBuTcHeRx

Member
This is awsum!
I would love to learn UNITY but I don't have a lot of time that I use to. I did learn a bit of Unreal. This engine is much easier and more broken down to develop with.
 
I'm ingrained in OO design and I just can't wrap my head around MonoBehaviours. I need my objects to have constructors. I just have one Empty GameObject with a MonoBehaviour script that contains all of my game logic and instantiate everything in script.

Programmer OCD :D.

I had similar issues when starting Unity. Trust me you are losing a lot of the benefits of the Editor doing everything in code.
 

Dusk Golem

A 21st Century Rockefeller
This may be a perfect opportunity to reteach myself the program. I learned and used it some about 3 years ago, but its changed so much and a lot of the information hasn't retained, so I just need to re-learn the program.
 

Makai

Member
Programmer OCD :D.

I had similar issues when starting Unity. Trust me you are losing a lot of the benefits of the Editor doing everything in code.
Figures. It's not that I don't want to. I have tried to convert my code to using MonoBehaviours a couple of times, but I am always unable to find a suitable alternative to constructors. I need to create objects procedurally, so I can't just give them public fields and play with them in the editor. At the moment, I only modify materials in the editor.
 

Gowans

Member
Really happy with what I've been able to do in unity so far.

Created a house I can walk around in using the controller and Oculs Rift with video playing on TVs.

Now for the coding parts.
 
Figures. It's not that I don't want to. I have tried to convert my code to using MonoBehaviours a couple of times, but I am always unable to find a suitable alternative to constructors. I need to create objects procedurally, so I can't just give them public fields and play with them in the editor. At the moment, I only modify materials in the editor.

Monobehaviours can have constructors. Its still a class. As far as im aware its:

Constructor functions
Awake functions
--- Scene loads ----
Start functions

Or is the problem based on instantiation order?
 

Makai

Member
Monobehaviours can have constructors. Its still a class. As far as im aware its:

Constructor functions
Awake functions
--- Scene loads ----
Start functions

Or is the problem based on instantiation order?
I meant constructors with parameters. I'm aware of Start() but that's not enough.
 

Lautaro

Member
I'm ingrained in OO design and I just can't wrap my head around MonoBehaviours. I need my objects to have constructors. I just have one Empty GameObject with a MonoBehaviour script that contains all of my game logic and instantiate everything in script.

Sorry, but this makes little sense. I also come from a OOP background and it helps a lot because in Unity you can actually see the objects and their properties in the editor and the Scene view, you just need to make them interact.

Usually I make a "Scene" object that has a "SceneController" script, this keeps control of the general behaviour of the scenario and the GUI but individual behaviours I try to keep them separated in a logic order.

Are you familiarized with prefabs?
 

Makai

Member
Sorry, but this makes little sense. I also come from a OOP background and it helps a lot because in Unity you can actually see the objects and their properties in the editor and the Scene view, you just need to make them interact.

Usually I make a "Scene" object that has a "SceneController" script, this keeps control of the general behaviour of the scenario and the GUI but individual behaviours I try to keep them separated in a logic order.

Are you familiarized with prefabs?
Yes, I use prefabs for models. I need the constructor to pass in references and dynamically generated properties. I can get a reference the MonoBehaviour way with GetComponent<T>(), but this is unhelpful if I have multiple instances of the same component attached to the same GameObject but need to find a specific one.
 

Relix

he's Virgin Tight™
I know Unity has 2D now so I may go in and learn about it to make that top-down adventure game I've always wanted to make :p
 
Yes, I use prefabs for models. I need the constructor to pass in references and dynamically generated properties. I can get a reference the MonoBehaviour way with GetComponent<T>(), but this is unhelpful if I have multiple instances of the same component attached to the same GameObject but need to find a specific one.

Why do you have duplicate scripts attached to an object?
 
Packt 5 for $50 deal.

may come in handy?

jJ2cFwYxnnPKJ.png


http://www.packtpub.com/gamedevoffe...6cdf9f44852f8d05e&utm_source=Campaign Monitor
 

Lautaro

Member
Yes, I use prefabs for models. I need the constructor to pass in references and dynamically generated properties. I can get a reference the MonoBehaviour way with GetComponent<T>(), but this is unhelpful if I have multiple instances of the same component attached to the same GameObject but need to find a specific one.

Oh, so you have the same script multiple times in the same object? Mmm, I can't help you there, that just not the way I work with Unity, sorry.... any chance you consider another way of work? like using a single script type per object?

know any of these books? are they worth it?

I have:

Unity 4.x Game AI Programming: didn't like it because it didn't teach me nothing new and I didn't find it thorough enough. You get more AI knowledge from a site like AIGameDev.com (I guess it could be good for newbies though). You need programming knowledge for this book.

Unity Game Development Essentials: ideal for absolute newbies to the engine, won't teach you programming but you will be able to use the engine with more confidence at the end. You don't need programming knowledge for this one.
 

nynt9

Member
So, I'm working on something that needs to do level loading like Metroid Prime.

The world will be fairly large, so I can't have everything in memory at all times, and separating the areas by doors will give me the ability to design rooms independently of each other. Here's how the system is supposed to work:
* You're in a room with a door. When you do something to open the door, the next room loads. If you don't go into that room for a while, the door closes and that room unloads.
* If you go into the next room, after a while the door closes behind you and the previous room unloads.
* If you open a new door in the next room, it closes the previous door, unloads the previous room and loads the next room.
* When a room unloads, everything in the room (enemies, pickups) reset, unless they are marked by a global flag (for example if a bridge is broken, the bridge will stay broken even if you go back).

Could you point me to a resource that could help me do this? I think it would involve usage of LoadLevelAdditiveAsync, but there's no UnLoadLevelSubtractiveAsync.
 

eot

Banned
Why is there such a collective hard on for video tutorials for something like programming? I feel like it's horribly time inefficient, you can't skip around, you can't easily reference stuff, you have to go at whatever (usually slow) pace they talk at etc.
 
Why is there such a collective hard on for video tutorials for something like programming? I feel like it's horribly time inefficient, you can't skip around, you can't easily reference stuff, you have to go at whatever (usually slow) pace they talk at etc.

It's easier to disgest thanks to the glacial pace, and the instruction from an actual person means people with attention span issues have a better chance of paying attention? I honestly don't know, I personally enjoy plowing through 3x the content in half of the time if a good book on a subject is available. My employer at one point paid for a pluralsight subscription and having to watch 8 hours of videos -- with pausing and playing bringing it up to even longer -- to digest something that could be done in 15 pages drove me nuts. Having to compile my own reference material did even more, I ended up buying a few books which helped me out infinitely more. I tried to get into unity and probably will now that I have more free time but I'm annoyed by the seeming lack of good documentation and instruction.
 

Timeless

Member
I'm far more interested in Unity 2D than 3D. Someday I'll learn it. My Game Maker games back in the day were sick!!!!! (And terrible.)
Gowans said:
All I'm looking to create is a 3d house I can walk around it.

Anyone have any tutorial suggestions for that?

Guess I'll also need to model it too, any program advice?
Trying to make a Gone Home clone?
 

Horp

Member
Figures. It's not that I don't want to. I have tried to convert my code to using MonoBehaviours a couple of times, but I am always unable to find a suitable alternative to constructors. I need to create objects procedurally, so I can't just give them public fields and play with them in the editor. At the moment, I only modify materials in the editor.

Just write an init or factory method that takes whatever params you need to send to it.
For some classes that I want to have MonoBehaviour capabilities I do something similar to this:

class SomeClass : MonoBehaviour
{
object [] parameters;

public static SomeClass Construct(object [] parameters)
{
GameObject someClassObject = new GameObject("SomeClassObject");
SomeClass constructed = someClassObject.AddComponent<SomeClass>();
constructed.parameters = parameters;
return constructed;
}
}
 

eot

Banned
Just write an init or factory method that takes whatever params you need to send to it.
For some classes that I want to have MonoBehaviour capabilities I do something similar to this:

Code:
class SomeClass : MonoBehaviour
{
	object [] parameters;

	public static SomeClass Construct(object [] parameters)
	{
		GameObject someClassObject = new GameObject("SomeClassObject");
		SomeClass constructed = someClassObject.AddComponent<SomeClass>();
		constructed.parameters = parameters;
		return constructed;
	}
}

So it's easier to read.
 

Makai

Member
Why do you have duplicate scripts attached to an object?
I must be being very unclear. I don't want duplicate scripts. I want duplicate Units, with references to the Map they're on and the Player that owns them. So I instantiate them in my gamelogic with new Unit(map, player). From what I understand, the MonoBehaviour way to do this is add the Player as a component to the Map, and add the Unit as a component to the Player. This is fine if I only have one of each, but I have multiple Players who own multiple Units, and GetComponent<T>() is fruitless for finding the right one.

Just write an init or factory method that takes whatever params you need to send to it.
For some classes that I want to have MonoBehaviour capabilities I do something similar to this:
Okay, I think I understand. I thought it was impossible because they can't be instantiated with the new keyword, but I could try this.
 

Horp

Member
I must be being very unclear. I don't want duplicate scripts. I want duplicate Units, with references to the Map they're on and the Player that owns them. So I instantiate them in my gamelogic with new Unit(map, player). From what I understand, the MonoBehaviour way to do this is add the Player as a component to the Map, and add the Unit as a component to the Player. This is fine if I only have one of each, but I have multiple Players who own multiple Units, and GetComponent<T>() is fruitless for finding the right one.

Okay, I think I understand. I thought it was impossible because they can't be instantiated with the new keyword, but I could try this.

Think of it like this:
The instance isnt the behaviour, its the GameObject that is the instance. A GameObject is an entity, an actual concrete thing; while a behaviour is just that; a way in which that GameObject behaves.

Thats why you can 'new' the GameObject, not the MonoBehaviour. Think of it in real world terms, if you want to understand why a behaviour cant be 'new'-ed: You cant walk around in the real world with a coupole of behaviours in your pocket. A behaviour always belongs to someone or something. Like a dog that behaves like a dog, or a clock that ticks and keeps track of time; a behaviour of that clock which we could call 'TimeKeeper'.

Edit:
I just read the first part of your post more carefully. No, thats not the monobehaviour way of doing that map/unit example.
This is the way:
'Map' is a MonoBehaviour that you attach to a GameObject. We can call the gameobject 'Map1'.
Unit is a MonoBehaviour you add to several GameObects, one each. We can call them 'Unit1', 'Unit2', 'Unit...'.

Possibly, you might instead want to consider the Scene as the map. Then that Scene would then have to contain a GameObject (or more) with one (or more) SceneManager-Behaviours attached. These could do things like keeping track of score or similar. The Scene would also contain all the Unit1, Unit2, ... with the Unit behaviours attached.

One unit would have the MoniBehaviour 'Player'. This unit would not only behave like a unit, but also behave like a player (=listen to input).
 

z0m3le

Banned
Do yourselves a favor and script in C# please.

C# is certainly important if you plan to work for others in the future, but if you are already somewhat familiar with javascript, I recommend just continuing to use that for now, most of what you learn for one object oriented language like javascript can easily be retained when/if you move over to C#.

There is also no real advantage I'm aware of with using C#, it's more about preference then about functionality.


I have to agree, this got me started, it's just a really great resource.

I've been working with and testing RPG Maker VX Ave for a 2D Rpg, but I was wondering if thrre was anything better to use? I can't code worth a damn, so RmVXACE has been doing great for me so far.

Is Unity really good with 2D? Easy to work with?

RPG maker is the easiest to work with, it's designed for that one purpose, but there is tons of resources for RPGs on unity, it's far more powerful and you can use visual coding assets like playmaker to make your life easier.

I'd recommend installing unity and following a simple tutorial off youtube to get your feel wet, or go with the link I quoted above, once you learn a bit, you'll realize it's not so far out of reach.
 
C# is certainly important if you plan to work for others in the future, but if you are already somewhat familiar with javascript, I recommend just continuing to use that for now, most of what you learn for one object oriented language like javascript can easily be retained when/if you move over to C#.

There is also no real advantage I'm aware of with using C#, it's more about preference then about functionality.

Theres one big advantage, you won't have to use Java.
 

Horp

Member
Theres one big advantage, you won't have to use Java.

It's not Java, it's a language that is quite similar to C# in structure but have a syntax that is quite similar to Javascript.

C#
float myValue = 5;
Unity Javascript:
var myValue : float = 5;

C#
int MyMethod(float arg)
{ ... }
Unity Javascript:
function MyMethod(var arg : float) : int
{ ... }
 
It's not Java, it's a language that is quite similar to C# in structure but have a syntax that is quite similar to Javascript.

C#
float myValue = 5;
Unity Javascript:
var myValue : float = 5;

C#
int MyMethod(float arg)
{ ... }
Unity Javascript:
function MyMethod(var arg : float) : int
{ ... }

I realise that. Its still hideous as hideous as Java.
 

Anustart

Member
Question, need some help...

Say there's a room in my game and the player can dismantle said room and put half of it in his inventory. How could I display what he takes in a menu as a picture of what it did look like before he dismantled it?

Edit: Wondering if there's an easy way to get Unity to screen cap a certain area of screen coordinates.
 
Question, need some help...

Say there's a room in my game and the player can dismantle said room and put half of it in his inventory. How could I display what he takes in a menu as a picture of what it did look like before he dismantled it?

Edit: Wondering if there's an easy way to get Unity to screen cap a certain area of screen coordinates.

A quick easy method would be to have a sprite version of the object he dismantled and attach the sprite as a reference on the object itself. Then loop over all the objects in his inventory grabbing the component required and grab the sprite needed.
 

Horp

Member
Question, need some help...

Say there's a room in my game and the player can dismantle said room and put half of it in his inventory. How could I display what he takes in a menu as a picture of what it did look like before he dismantled it?

Edit: Wondering if there's an easy way to get Unity to screen cap a certain area of screen coordinates.

If you render with 3D-geometry or GUITexture/GUIText that is definitely possible. It you use OnGUI it's not possible (which is very annoying for many reasons).

You can set the target texture for a camera to be a RenderTexture. Then you can read out the pixels to a normal Texture2D. Pro only though.
 
This thread appeals to me as Ive been looking for motiation to get back into game development. I made my student project with 3 others in the Unity engine, so getting back into Unity would be sweet. Its tough as hell though trying to be self motivating cause even though I am familiar with the engine, the programming is just so daunting to me (it was always my weakpoint). I think thats more of a game dev issue than a Unity issue. I hope this thread stays active as everybody reports in on their progress, as I hope to do the same on my own as well.
 
My problem with either Unreal Engine or this is how do i make 3d models? A game will definitly need them :D Maya is complicated.
 
My problem with either Unreal Engine or this is how do i make 3d models? A game will definitly need them :D Maya is complicated.

Unity has an asset store if you're looking for models or you can see if there's a place that offers free OBJ files that you can import as placeholders. If your main focus is on the gameplay mechanics of whatever project you're working on however, u can get away with cubes and whatnot. Depends on how far you want to get with your project
 

Damaniel

Banned
I realise that. Its still hideous as hideous as Java.

This makes no sense. Java isn't even that hideous (just popular to hate on), and Java and Javascript are about as similar as apples and bowties. I still think Sun should have jumped up and smacked down Netscape the second they named their language Javascript - to this day, people still think those two languages are related.

For a beginning game developer, using Javascript for your scripting is perfectly fine. I assume there are scalability issues to be concerned with if you're making a bigger game, but I imagine that the games have to get a lot bigger than the average hobbyist game before that's really an issue. Learning C# (eventually) will result in a more transferable skill (especially if you want to write your own engine someday), but both languages will get the job done.

(Personally, I wish that Boo wasn't treated like a second-class citizen in the Unity world. I like Python a lot - so much so that I use Pygame to do game prototyping - but I wouldn't actually use Boo for scripting, since it seems that nobody ever pays it much attention.)
 

Anustart

Member
If you render with 3D-geometry or GUITexture/GUIText that is definitely possible. It you use OnGUI it's not possible (which is very annoying for many reasons).

You can set the target texture for a camera to be a RenderTexture. Then you can read out the pixels to a normal Texture2D. Pro only though.

Yeah that would be perfect. I have Pro so all things should be a go then!
 

Annubis

Member
Been using Unity professionally for 4 years so I can answer questions, if people have any.

Oh good. Which scripting language is easier to learn? Javascript or C#?

What I'd like to know is which is BETTER to use in Unity (if there's a difference)
The fact that almost every tutorial I see use C# makes me think that there would be a reason not to use JavaScript.
 

Horp

Member
Yeah that would be perfect. I have Pro so all things should be a go then!

The Camera component has a property called "targetTexture".

Create a RenderTexture through script or as an Asset (and assign it to your Behaviour in Inspector).

Camera.targetTexture = yourRenderTexture.
This will make that Camera render into that texture instead of onto the screen. And remember, Camera.Render() is a method you can call through script that forces a single rendering (so you don't have to wait a frame).
To read that texture out to a Texture2D you have to do something that might look a bit funky at first.
This link describes the process very well:
http://answers.unity3d.com/questions/27968/getpixels-of-rendertexture.html


What I'd like to know is which is BETTER to use in Unity (if there's a difference)
The fact that almost every tutorial I see use C# makes me think that there would be a reason not to use JavaScript.

C# is better.
Reasons:
1. The syntax of C# is much cleaner. Javascript syntax was never intended to have classes and be statically typed, so Javascript has been mangled with tons of stuff that Unity requires, and the result is a strange, messy language.
2. C# code is all over the web, not only related to Unity, but in all kinds of places. Need an algorithm for pixel filling a 2 dimensional Color array? Someone has probably written it in C# (for .NET), but you have very slim chances of finding the code in Unity Javascript.
Learning C# is also good if you want to do some other programming than Unity in the future.
3. These days, Javascript in Unity has nothing that C# doesn't have.
 
Top Bottom