Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411493 Posts in 69372 Topics- by 58428 Members - Latest Member: shelton786

April 25, 2024, 06:02:38 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)Tutorials[New Inheritance Vid up!] Beyond Beginner Unity Tutorials
Pages: [1]
Print
Author Topic: [New Inheritance Vid up!] Beyond Beginner Unity Tutorials  (Read 7043 times)
coAdjoint_Tom
Level 0
***


View Profile
« on: March 28, 2013, 04:50:19 PM »

Hi Guys,

I've started a little tutorial series mainly covering applications of the .net framework to Unity. I've started the series for two reasons:

1) I don't think there's a great deal of info on youtube about this stuff, and I've found what I've learnt extremely useful.
2) I feel that if I had had this info a few months ago I would have saved myself a great deal of time and effort.

I'm really interested in feedback and what topics people would like covered so please hit me up with suggestions.

VIDEO: Coroutines and Animation





VIDEO: Lambda Expressions and Actions





VIDEO: Mesh creation and Real Time Modification
http://www.youtube.com/watch?v=ZJR6atRMcuo

VIDEO: Threading in detail
http://www.youtube.com/watch?v=qlLEpf4Pih0

VIDEO: Properties and Static variables (to make a very simple damage system)
http://www.youtube.com/watch?v=AEVL46CLgjM

VIDEO: A nice Finite State Machine
http://www.youtube.com/watch?v=lo80BOomaU4

NEW VIDEO: Undo/Redo system for Unity
http://www.youtube.com/watch?v=5tgTa5gJ8hU

NEW VIDEO: Class Inheritance example in Unity




COMING SOON: BUILD-A-LONG EDITOR EXTENSION TUTORIAL SERIES!

Hope you find these useful!
« Last Edit: April 23, 2014, 11:42:20 PM by coAdjoint_Tom » Logged

Working on skill modelling and adaptive AI systems in video games http://www.youtube.com/coAdjointTom

Game Ai blog:

http://coadjoint.wordpress.com/
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #1 on: March 28, 2013, 10:49:25 PM »

Great I had to look for co routines
Logged

coAdjoint_Tom
Level 0
***


View Profile
« Reply #2 on: March 29, 2013, 10:04:05 AM »

Added two new tutorials today, on on real time mesh creation and modification and..

Threading in Unity using threaded Queues as an example.

Check it out here!




Logged

Working on skill modelling and adaptive AI systems in video games http://www.youtube.com/coAdjointTom

Game Ai blog:

http://coadjoint.wordpress.com/
coAdjoint_Tom
Level 0
***


View Profile
« Reply #3 on: April 17, 2013, 11:36:14 AM »

Hi everyone,

here's another video on coroutines. Shows you how to control them on your command!

If anyone has any questions feel free to ask



Logged

Working on skill modelling and adaptive AI systems in video games http://www.youtube.com/coAdjointTom

Game Ai blog:

http://coadjoint.wordpress.com/
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #4 on: April 17, 2013, 06:09:13 PM »

I tried using coroutines once, for a repeated timer (every 5s) but it stare at me 5s (yes!) and then nothing (each frame no!)
Logged

coAdjoint_Tom
Level 0
***


View Profile
« Reply #5 on: April 18, 2013, 12:26:46 AM »

so did you want something that just went off every 5 seconds? If so you could do something like...

(Call it once at startup) Use a coroutine manager to stop it if you ever need to.

Code:
void Timer()
{
   float timer = 0f;

   while(true)
   {
      yield return new WaitForSeconds(5f);
      //Insert game logic here
      timer += 5f;
   }
}
Logged

Working on skill modelling and adaptive AI systems in video games http://www.youtube.com/coAdjointTom

Game Ai blog:

http://coadjoint.wordpress.com/
Brainswitch
Level 0
**



View Profile WWW
« Reply #6 on: April 30, 2013, 04:09:27 PM »

so did you want something that just went off every 5 seconds? If so you could do something like...

True, or you could just use InvokeRepeating.

I use co-routines all the time, mostly for AI and animation. They can be very useful, both for creating clean code (as in easy to read and maintain) and quite optimized too.
Logged

Richard Kain
Level 10
*****



View Profile WWW
« Reply #7 on: May 02, 2013, 09:00:29 AM »

I have a question that you might be able to help me out with. (based on the content of some of your videos)

I've been working on developing a lip-sync animation system in Unity. At the moment, I was basing the system on Unity's legacy animation system. But I'm a little leery of leaning on that, as it might get phased out in the future.

After watching your coroutine tutorial, and reading up a little on them, I'm thinking there might be some real potential for using them as the basis for my lip-syncing. All I really need to do is run basic functions in a sequence based on pre-determined time intervals. And the WaitForSeconds functions supports float values.

What are your thoughts? Do coroutines have adequate performance for that kind of implementation?
Logged
coAdjoint_Tom
Level 0
***


View Profile
« Reply #8 on: May 03, 2013, 05:11:27 AM »

With regards to InvokeRepeat, I would personally stay clear of using this as it's very poor performance-wise. Having said that, as long as you're not using it several times per frame it's probably okay.

With regards to the lip-syncing, I would say that coroutines would be my first choice. Building a class that made use of delegates, lambda expressions and coroutines would probably get the job done quite well.

If you do go down the coroutine route, I would seriously recommend making a coroutine manager so you can cancel them neatly. I've been having serious problems with destroying game objects even with a coroutine manager to kill running coroutines!
Logged

Working on skill modelling and adaptive AI systems in video games http://www.youtube.com/coAdjointTom

Game Ai blog:

http://coadjoint.wordpress.com/
Richard Kain
Level 10
*****



View Profile WWW
« Reply #9 on: May 03, 2013, 07:47:34 AM »

Thanks! I'll play around with my prototype today and start testing the coroutine approach. I don't know if I will need a manager, I wasn't planning on ever deleting the objects that it would be applied to. I'm treating the lip-sync events as their own GameObjects. They can continue to exist under the hierarchy of the object they are intended to affect. It would be important for me to be able to pause or possibly interrupt the coroutines, but I'm not sure would need a separate manager for that. The nature of this implementation would never have more than three or four of these coroutines running at the same time, and usually no more than two. The most common case would be just one running at a time. (it's impolite to talk over others)
Logged
coAdjoint_Tom
Level 0
***


View Profile
« Reply #10 on: May 03, 2013, 09:48:33 PM »

Nice! How do you plan on pausing them?
Logged

Working on skill modelling and adaptive AI systems in video games http://www.youtube.com/coAdjointTom

Game Ai blog:

http://coadjoint.wordpress.com/
Richard Kain
Level 10
*****



View Profile WWW
« Reply #11 on: May 07, 2013, 11:19:59 AM »

Nice! How do you plan on pausing them?

Well, I'm looking into using StopCoroutine. I've also found that coroutines respond just as you'd expect them to to the timeScale variable. So I always have that option available.

After a little more research, I think I might have an idea how I could pull off effective pausing. I do have a question though. You have to use StartCoroutine when coding in C# for Unity. There are two primary overloads for that method, one that takes a dirrect function reference, and one that takes a string function name. As I understand it, the performance overhead is less for the first option. How much less is it?
« Last Edit: May 07, 2013, 11:58:29 AM by Richard Kain » Logged
coAdjoint_Tom
Level 0
***


View Profile
« Reply #12 on: May 07, 2013, 10:55:21 PM »

Although I don't have numbers the method which takes a string argument is considerably worse since it uses reflection to find the coroutine you're referring to. Okay for the occasional call but not good for one call per frame and up sort of stuff.

I know I keep harping on about this but the beauty of a coroutine manager is that you can set them up like Tasks in C# 5.0. If you're looking at the string version to cancel your coroutines then you might face a problem with the fact StopCoroutine doesn't close around an instance of that coroutine. It just stops all coroutines with a particular name. A coroutine manager allows you to close around an instance of a coroutine and stop that particular instance. Might not be relevant to you but thought it'd be worth mentioning.
Logged

Working on skill modelling and adaptive AI systems in video games http://www.youtube.com/coAdjointTom

Game Ai blog:

http://coadjoint.wordpress.com/
Richard Kain
Level 10
*****



View Profile WWW
« Reply #13 on: May 08, 2013, 07:51:44 AM »

I know I keep harping on about this but the beauty of a coroutine manager is that you can set them up like Tasks in C# 5.0. If you're looking at the string version to cancel your coroutines then you might face a problem with the fact StopCoroutine doesn't close around an instance of that coroutine. It just stops all coroutines with a particular name. A coroutine manager allows you to close around an instance of a coroutine and stop that particular instance. Might not be relevant to you but thought it'd be worth mentioning.

Yeah, I thought reflection might be coming into play for that scenario.

I'm not sure a coroutine manager will be necessary for my purposes. For what I'm doing, I will never need more than two coroutines per character, and they won't even be running all the time. I don't think I will need to use the StopCoroutine method either. I have the option of using the StopAllCoroutines method instead. That function will stop all coroutines that were started by that component.

My thought is that I can start one coroutine for executing function calls at pre-defined times, and another for constantly keeping track of the current eleapsed time for the speech event. Having a record of the play position as a float value will make it possible for me to stop the animation, and then restart it from the same point in time. (which is effectively what pausing does) There are several other benefits from tracking the current playing position, so its worth a second coroutine.
« Last Edit: May 09, 2013, 08:01:43 AM by Richard Kain » Logged
coAdjoint_Tom
Level 0
***


View Profile
« Reply #14 on: May 08, 2013, 11:48:59 PM »

Sound really interesting! If you want my opinions on anything make sure you let me know. Looking forward to seeing this one in action.
Logged

Working on skill modelling and adaptive AI systems in video games http://www.youtube.com/coAdjointTom

Game Ai blog:

http://coadjoint.wordpress.com/
coAdjoint_Tom
Level 0
***


View Profile
« Reply #15 on: May 29, 2013, 06:40:20 AM »

Here's a tutorial for a Finite State Machine I put together in a couple of hours!

I think the benefit of this implementation is that it cleans up your code significantly. Long running or repetitive tasks such as vision checking can be initialised when you enter a state, leaving your Update method clean and simple.

Transitions between states are handled with delegates and Lambda functions keeping down code bloat.

Hope you like it, tell me if it's useful!



Logged

Working on skill modelling and adaptive AI systems in video games http://www.youtube.com/coAdjointTom

Game Ai blog:

http://coadjoint.wordpress.com/
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic