RSS

UnrealScript: Kismet Nodes Part One – An Introduction

16 Apr

Last week I explained how you could save your gamestate using unreal script. For this week’s tutorial post, I thought it would be a good idea to introduce the concept of Kismet Nodes and how we can write our own nodes tailored to our needs.

Difficulty: Beginners

This tutorial is aimed at those who know their way around UnrealScript and programming and would like to expand their knowledge concerning a few topics. If you don’t know what UnrealScript is or how to program using it then I suggest you look for a few getting started tutorials before attempting any of this yourself. I will one day write up a few introductory tutorials but for now I’ll stick to selective topics I feel people will most benefit from.

Note: as with most tutorials, code and concepts expressed here are simplified and are meant to serve as a stepping stone for you programming endeavors.

Kismet Briefly

Kismet is the Unreal engine’s visual scripting language. It allows people who are not familiar with programming to script complex game mechanics and interactions through Kismet. If you do not know what Kismet is or would like learn more about it, two very handy pages on the UDN have everything you need:

I’ll assume you know your way around UDK and its Kismet editor in this tutorial – if you are not familiar with either make sure you take the time to learn the tools before you attempt to do anything with them.

The Scenario

So you are part of a small team working on a game. Your game has multiple levels that the player will progress through. You wrote up your PlayerController, GameMode, and all the necessary classes your game needs. But, your PlayerController has a lot of variables that get saved through a save function. What you want to do is allow your designers some sort of way to save and load these values through Kismet. What you need to do is write a couple of quick Kismet Nodes that when activated, will trigger the save and load functions respectively.

SavePCGameState Node

Now, the best place to start is to get right into programming. If you remember last week we wrote a few functions inside our PlayerController that allowed us to save and load important variables. Now we are going to build upon that by writing a few Kismet nodes that will allow our designers to call on these functions.

Create a new .uc document and call it whatever you like (for organization’s sake you might want to include SeqAct_ before the name of the file I’ll go over what this means in a second). I called mine DH_SeqAct_SavePCGameState. Now open the file and write the following.


/**
* This kismet node is used to trigger the PC to save his stats
* @author : Daniel G Haddad
*/
class DH_SeqAct_SavePCGameState extends SequenceAction;

The first thing you will notice is the following:

extends SequenceAction;

Our script extends from the SequenceAction.uc file which is part of UDK’s source scripts. Kismet nodes have several types (Actions, Events, Conditionals…etc) what we intend to do is create an Action Node. Action Nodes, simply put, are nodes that are written to perform a certain action when you activate them in a sequence chain in the Kismet Editor.

Now fill the rest of your file as follows:


/**
* This kismet node is used to trigger the PC to save his stats
* @author : Daniel G Haddad
*/
class DH_SeqAct_SavePCGameState extends SequenceAction;

event Activated()
{
}

defaultproperties
{
ObjName=”Save PC’s State”
ObjCategory=”DH_PlayerController”
VariableLinks.Empty
}

We didn’t do anything drastic here.


event Activated()
{
}

Here we create the Activated event. Later in the tutorial we will fill the area between the curly braces with the bit of code that will trigger the PC’s save function.

defaultproperties
{
ObjName="Save PC's State"
ObjCategory="DH_PlayerController"
VariableLinks.Empty
}

Now in this bit we initialized some default properties.

ObjName="Save PC's State"
This property gives our node a name to be used inside the Kismet Editor.

ObjCategory="DH_PlayerController"
This property tells the editor what category this node fits under.

VariableLinks.Empty
This bit empties the VariableLinks – more on this later.

Now save your changes – compile your code, open up the UDK, and fire up the Kismet editor (Little green K button).

Right click anywhere in the empty space and navigate through Action. You should find a category called “DH_PlayerController” (or whatever you called your category). Hover over that and a new menu will open up having “Save PC’s State”.

Where your node should be

Navigating to your Kismet Node

If you click your node should appear looking like this.

How it looks so far

The save node

Now there is no sense connecting it since we didn’t program it to do anything yet. Close the UDK and go back to your code and write the following inside the Activate event:

/**
* When activated this node triggers the DH_PlayerController's savePCVariables()
**/
event Activated()
{
local DH_PlayerController PC;

PC = DH_PlayerController(GetWorldInfo().GetALocalPlayerController());

PC.savePCVariables();
}

Firstly, we create a local variable PC of type DH_PlayerController which is my player controller.

local DH_PlayerController PC;

In the next bit of code we call a function called GetALocalPlayerController() and cast its result into our PC variable.

PC = DH_PlayerController(GetWorldInfo().GetALocalPlayerController());

GetALocalPlayerController() is located inside the Actor.uc class and it has the following description:

/** Return first found LocalPlayerController. Fine for single player, in split screen, one will be picked. */

So this function will return our player controller. This method is fine for any single player game (I’ll demonstrate an example of what you would do if you had a multiplayer game later in this tutorial) so it suits us perfectly for now.

In the next bit of code all we do is call the save function we wrote last week.

PC.savePCVariables();

Ideally, you might want to run a few checks on PC depending on the situation but I left all that out for simplicity’s sake.

So there you have it. Our save node is now ready to be hooked up inside our level. Writing up a load node should now be very easy to do since it follows similar steps so go ahead and write that load node up and then fire up UDK to test it out.

What We Just Accomplished

We knew that the player will be progressing through a set of levels and we would like to carry his state through each one. Using the save and load nodes, our designers can now hook up some very basic Kismet scripts that will load the player’s state in the new level and save it out once the player finishes a level or exits.

A quick example Kismet map is shown bellow:

Sample save Kismet map

How wed use our save node

Example load map

How wed use our load node

So there you have it. By now you should have a much better idea about how to write your own Kismet Nodes. Remember that this is only an introduction, Kismet nodes can be used to do a whole lot of things. In my next tutorial I’ll go over variables/variable links and how they work with Kismet nodes. Stay tuned.

Important Links:

Notes:

If you are writing a multiplayer game or are unsure about whether or not your game will have multiplayer, you can get the player controller using the following method:


event Activated()
{
local WorldInfo wInf;
local DH_PlayerController PC;

wInf = class’WorldInfo’.static.GetWorldInfo();

if (wInf != None)
{
ForEach WI.AllControllers(class’DH_PlayerController’, PC)
{
//Now for each occurrence of DH_PlayerController in your game this section of code will run
PC.something();
…etc
}
}
}

I’ve made a game!

For the past year I’ve formed a small game studio called Cwerki Studios and we’ve been hard at work on our debut game, Min: A Space Adventure! Min built using UDK and was approved by Apple and will become available worldwide on June 18th! Check out our launch trailer!

Click here to download Min for Free from the App Store!

Make sure you like our video and share it with your friends!

It doesn’t end there, Min would not have been possible without the help and support of our community, we have huge, huge plans for Min but more importantly we want to include our community in this future. Head over to our Facebook page and like us to take part in polls and discussions we’ll be orchestrating to decide on Min’s future.

Advertisements
 
 

Tags: , , , , , , , , , , ,

14 responses to “UnrealScript: Kismet Nodes Part One – An Introduction

  1. Goran Milisavljevic

    17/04/2011 at 3:37 PM

    Thank you so much for this tutorial! Cheers.

     
    • danhaddad

      17/04/2011 at 6:16 PM

      Glad you liked it, I’m going to try and write one up every weekend so stay tuned 🙂

       
  2. Martin Krol

    12/05/2011 at 2:14 AM

    Cool. But I have one question. We make savestates to a file saved on the hard drives. What command would we use to load up the save state. I am trying to make a load/save button for my interface and all is well. Got the save buttons in place, and the save code..from this tutorial and the one before it.. but I am curious what command you use to actually load the saves after it is saved out.

    Cheers.

     
  3. Kwiatek

    24/11/2011 at 12:42 AM

    How can I get a value of loaded viariables in Kismet ? For example experience ?? Is it in DH_PlayerController class ?? If yes, how can i throw it into Kismet node ? 😀

     
  4. g3n3fyp

    30/11/2011 at 5:33 AM

    Hi, thanks for replying my previous comment. =]

    btw can i ask for help? XP, I’ve followed your tutorial thoroughly, but why isn’t my Remote Event showing a tick? its still a red cross instead of a green tick. ='( am i’m missing something?

    I have not done the part two of this tutorial yet, and i noticed that the event name is “Save_EXP_Variables”, has that to do something about it? cuz my game does not intend to have exp so I did not want to implement it. is it inter-related?

    sorry I’m quite lost here please help? Thanks again in advance. =)

     
  5. danhaddad

    05/12/2011 at 7:36 PM

    Usually when a remote event shows a red X instead of a green tick it means the remote event it is meant to fire does not exist.

    To use a remote event you need 2 kismet nodes New Action -> Event -> Activate Remote Event (when fired this will look for the remote event by the name you specify and fire it)

    And the event itself New Event -> Remote Event. They must both have the same name.

    Hope this helps.

     
    • g3n3fyp

      15/12/2011 at 8:35 AM

      thanks so much. The ticks appears, but do I have to connect the “Activate Remote Event” to anything? Cuz its like its a lone node itself… http://i43.photobucket.com/albums/e368/capricorn_5566/UDK/saveloadnodes.jpg

      Can I link this to the Game Menu? The GameMenu is created using Scaleform. and how do I go about testing it?

      Sorry for asking so many questions, and thanks again in advance. =]

       
  6. danhaddad

    16/12/2011 at 11:26 PM

    Yes you need to activate the “In” nodes of the ActivateRemoteEvent nodes whenever you want to fire the events.

    You can link it but that involves delving into more UnrealScript.

     
  7. g3n3fyp

    19/12/2011 at 6:33 PM

    Hi, thanks again for the reply~

    I see~so is there a tutorial available in the internet for linking this save game to the game menu?
    I’ve tried searching is unable to find it… I’ve tried with epic game forum as well but not so sure…

    Mind directing me? Any directions would be greatly appreciated. =]

     
  8. danhaddad

    19/12/2011 at 7:19 PM

    I don’t know of any, so you are going to have to figure it out on your own or keep searching yourself, I could look into it but I don’t have much time to complete this tutorial series let alone look into that matter.

    Sorry about that, try reading documentations on UDN and checking other people’s code.

     
  9. Russ Sharpe

    15/02/2012 at 2:17 PM

    Hi,

    I am hoping somebody on here can help me…I am using this tutorial to save the score from one level to the next. I have set the int var in the gamestate class that extends object and followed all the steps in this tutorial and the previous one. My kismet nodes save state & load state show up in kismet as they should, but I am confused about how to save and load the data? My score is an int value and all I want to do is to pass this value onto teh next level to add to that levels score and so on. How do I get the int value fincal score from level 1 to save when I fire the save state node and the same applies when I fire the load state node in the next level? Basically I am looking for the link between the load/save state nodes & the int that is my score. Do I have to name my score int the same as the var int referenced in my gamestate script? Do I need to use an external variable in kismet and name it the same as the var int referenced in my gamestate script and if so how do I link the 2? Am I missing the boat completely and overlooking something really simple?

    Thanks in advance

    Russ

     
    • danhaddad

      15/02/2012 at 5:59 PM

      Hello Russ,

      So it isn’t really too complicated. Basically when you want to “save” your score you store it in that gamestate class that you did and you call the save function. Then you can load the new level, and when you are in that level, all you need to do is call the Load function and the variable inside your gamestate will now contain the old saved value of that score variable. Then you can take it, update it, and save it again…

      Calling the save and load can be done through the kismet nodes, so basically at the end of your level you should run the save kismet node, and at the beginning of your level you should run the load kismet node.

      Please make sure you update the score in that “gamestate” class (make sure your variable is there or you store a copy of it there) since that is what ends up being saved.

      Hope this helps, good luck.

       
      • Russ Sharpe

        15/02/2012 at 7:06 PM

        Hi Dan,

        Thanks for your reply, that is what I am doing regarding the kismet nodes but I still don’t understand how to get the int from my class to be the int within kismet (or vice versa). My class is shown below and as you can see is really simple:

        class MyGameState extends Object;

        var int finalscoretoload;

        /**
        * Here I default the values of the variables.
        **/
        defaultproperties
        {
        finalscoretoload = -1

        }

        How do I get the int finalscoretoload into kismet? Do I use an external variable and edit the var name/label or could I use a named variable? I can’t seem to make either of these methods work, I’m sure there is a really simple way to access (and save/load to) the int within my class but I just can’t see it. I don’t know if I should be doing something with the targets section in the load/save states maybe?
        The ultimate end game is to have an int that I can convert to a string and use the draw text kismet function to output the int score to the screen as I do with the current levels score. This is why I need the int in kismet as a variable so I can plug it into the convert to string and ultimately the draw text node.

         

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: