Announcement

Collapse
No announcement yet.

How to Access ANY Custom Class Unreal Script Variable in Kismet

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to Access ANY Custom Class Unreal Script Variable in Kismet

    Dear Everyone,

    I thought you'd like this tutorial!

    Summary:
    1.You can use the Kismet variable "player" to access your custom PlayerController class.

    2. If you store the custom class variable that you want inside of your pc class, you can then access it in Kismet.

    3. Use your custom GameInfo class to pass data between your custom classes and your Player controller class

    4. Use Object-> Get Property in Kismet on your player variable to access any variables you create, any time


    ~~~

    It can seem quite difficult to get your custom unreal script class variables into Kismet!


    Let's say you set a boolean state like isInEditorMode in your unreal script, and every time player presses F3 you want n mesh selection screen to load, but ONLY if isInEditorMode == true. This is all happening in game of course, not in UDK, and is a dynamic instance of your classes in your level.


    And lets say that in Kismet, you want to do something every time F3 is pressed that is easier to code quickly in Kismet, but ONLY if isInEditorMode == true;

    But isInEditorMode is a custom variable made by you, stored in a custom class version of your WorldInfo or your HUD or even a projectile class (it doesn't matter)

    ~~~

    How in Heaven's name are you going to access a custom variable from a custom script class in Kismet???

    ~~~


    I have a solution for you!


    Step by step

    1. Move your custom variable into the PlayerController class you are using, it can be a custom PlayerController class (I am using a custom pc class myself)

    2. If you need help getting your playercontroller class to communicate with your custom class, say your HUD or a projectile class, use your custom GameInfo class as an intermediary and set variables using

    Code:
    YourJoyfulCustomGameInfo(WorldInfo.Game).YourCustomVar
    or

    as a wonderful forum member (Spoof I believe) told me:

    you can use this version if your class doesn't recognize WorldInfo.Game

    Code:
    YourJoyfulCustomGameInfo(class'WorldInfo'.static.GetWorldInfo().Game).YourCustomVar

    You can pass variables back and forth between any classes this way and keep a version in WorldInfo, where it likely belongs if it is important info about world/ game state.


    So now you have gotten a copy of your very important custom variable into your custom PlayerController class using GameInfo!!

    ~~~

    Kismet Step

    3. Go into Kismet and right click, action-> Object -> get property

    4. Your custom variable must be a basic type like bool or float, look at the options you have in the get property node as outputs

    5. As the input node, which is type object, do the following:

    6. Right click -> new variable -> Player

    7. In properties of this player var, uncheck "all players" and use player0 (unless you have multiplayer game of course, but then you need a player object for each player index 0 to number of players - 1

    8. THIS IS YOUR CUSTOM PLAYER CONTROLLER CLASS!

    player 0, this happy little object variable, is a link to your custom var

    9. Make sure that in UDK in World Info you have the game type set to your custom game type

    10. Now go back into Kismet

    11. For the input of Object->Get Property Node, set it to Player 0 or whichever player

    12. Enter the name of your custom variable that is in your custom PlayerController class

    13. Create a new variable of the appropriate type based on your custom variable

    In my example we had a boolean value isInEditor mode, so make a new boolean and connect it to the Bool output spot of the Get Property node


    You Are Done!

    You have now accessed an unreal script custom class, custom variable in Kismet!


    I have thoroughly proven that this method works



    Enjoooy!



    Rama

    PS: sorry no Kismet pic at moment, post any questions you might have in this thread.

    PSS: whether or not it is good to necessitate a link between Kismet and unreal script is not the focus of this tutorial, perhaps ideally there should not be such interdependence, but the fact is it will occur for many of you, and has happened to me, and I have a solution for you! ♥

    #2
    Thank you for the tutorial - this is just what I'm looking for.

    Unfortunately I am stuck on step 2 - please help I'm sure if the code in step 2 belongs in the playercontroller class or gameinfo class, I have tried both and both returns the same compiler error.
    Error, Unexpected 'MyGameInfo'
    Any ideas?

    Comment


      #3
      All Actors (controllers, pawns, projectiles, anything in the world) have the WorldInfo property, which is a reference to the current WorldInfo instance hosting the game world. The WorldInfo object has a property called Game, referencing the GameInfo instance.

      Game points to your own game info instance, but is typed to the generic base class GameInfo. To access your own variables and functions you have to cast the reference to your own class type.

      Code:
      local MyGameInfoClass G;
      
      G = MyGameInfoClass( WorldInfo.Game );

      Comment


        #4
        Originally posted by Spoof View Post
        All Actors (controllers, pawns, projectiles, anything in the world) have the WorldInfo property, which is a reference to the current WorldInfo instance hosting the game world. The WorldInfo object has a property called Game, referencing the GameInfo instance.

        Game points to your own game info instance, but is typed to the generic base class GameInfo. To access your own variables and functions you have to cast the reference to your own class type.

        Code:
        local MyGameInfoClass G;
        
        G = MyGameInfoClass( WorldInfo.Game );
        Based on my compiler errors, I'm guessing the code I have below is incorrect.
        Code:
        class SeqAct_GiveCannonAmmo extends SequenceAction;
        
        var() int amount;
        
        event activated()
        {
        	local X1GameInfo G;
        	G = X1GameInfo( WorldInfo.Game );
        
        	X1GameInfo(WorldInfo.Game).cannonAmmo = X1GameInfo(WorldInfo.Game).cannonAmmo + amount;
        	`Log("Give-Cannon-Ammo kismet action activated");
        	
        }
        
        DefaultProperties
         {
            ObjName="Give Cannon Ammo"
            ObjCategory="X1A"
        	HandlerName="GiveCannonAmmo"
         }
        I apologise to keep asking questions but this is the first experience I've had with class-referencing and its a little confusing >__<

        If I'm correct, the code you provided above allows me to access a variable in the gameinfo class right? In which case, should I be moving my cannonAmmo variable to the gameinfo class, instead of the playercontroller class?
        I really do apologize if I've misunderstood

        Comment


          #5
          Bump - can anyone help with this please? ^^

          Comment


            #6
            Sorry, I didn't see your post earlier. The SequenceAction class isn't based on Actor, so it has no direct access to WorldInfo. Instead you have to use a static accessor function of the WorldInfo class itself:

            Code:
            G = X1GameInfo( class'WorldInfo'.static.GetWorldInfo().Game );
            Also after doing that you can replace...

            Code:
            X1GameInfo(WorldInfo.Game).cannonAmmo = X1GameInfo(WorldInfo.Game).cannonAmmo + amount;
            ... with...

            Code:
            G.cannonAmmo += amount;

            Comment


              #7
              Yes! Thank you - its working - I am successfully querying a variable stored in my gameinfo class from a kismet action!

              One final question - my ammo variables are all stored in playercontroller at the moment. Should I:
              A) Move those variables to my gameinfo class,
              or
              B) Change the code you gave me to access the playercontroller class?

              Comment


                #8
                If your game is single-player it doesn't matter too much, and depends how you prefer to organise your project. PlayerController may be a more logical place for it.

                For networked/multiplayer games it's a different story and a very important decision. The preferred location for such data might be the PlayerReplicationInfo object, but then 'ammo' is generally associated with a Weapon, not the player.

                Comment


                  #9
                  So I get how to access a player or pawn variable, but how would I get a variable on a weapon class the player is holding? Do I put the weapon as the object var on the GetProperty node somehow?

                  Comment


                    #10
                    Jlhill, there seems to be an answer for that here: http://forums.epicgames.com/threads/...4#post30778354
                    Check post by ffow near the bottom

                    Comment


                      #11
                      This makes no sense, point 5 and 11 are exactly the same
                      Could you post a picture? because this really makes no sense at all. You write 2 times the same stuff

                      Comment


                        #12
                        this is a bit odd how its done, i guess he had his reasons..

                        to change a variable in/from your player controller an alternative is to use the console command node and an exec function in your controller.

                        Comment


                          #13
                          Saving vars set in Kismet

                          Hi,

                          I'm using a serialize/deserialize gametype that collects vars from the pawn class, such as var() string Mystring;
                          Your method for accessing an unrealscript variable via player0 in kismet calls on the controller class. Can those variables be serialized too?

                          Tom


                          Originally posted by evernewjoy View Post
                          Dear Everyone,

                          I thought you'd like this tutorial!

                          Summary:
                          1.You can use the Kismet variable "player" to access your custom PlayerController class.

                          2. If you store the custom class variable that you want inside of your pc class, you can then access it in Kismet.

                          3. Use your custom GameInfo class to pass data between your custom classes and your Player controller class

                          4. Use Object-> Get Property in Kismet on your player variable to access any variables you create, any time


                          ~~~

                          It can seem quite difficult to get your custom unreal script class variables into Kismet!


                          Let's say you set a boolean state like isInEditorMode in your unreal script, and every time player presses F3 you want n mesh selection screen to load, but ONLY if isInEditorMode == true. This is all happening in game of course, not in UDK, and is a dynamic instance of your classes in your level.


                          And lets say that in Kismet, you want to do something every time F3 is pressed that is easier to code quickly in Kismet, but ONLY if isInEditorMode == true;

                          But isInEditorMode is a custom variable made by you, stored in a custom class version of your WorldInfo or your HUD or even a projectile class (it doesn't matter)

                          ~~~

                          How in Heaven's name are you going to access a custom variable from a custom script class in Kismet???

                          ~~~


                          I have a solution for you!


                          Step by step

                          1. Move your custom variable into the PlayerController class you are using, it can be a custom PlayerController class (I am using a custom pc class myself)

                          2. If you need help getting your playercontroller class to communicate with your custom class, say your HUD or a projectile class, use your custom GameInfo class as an intermediary and set variables using

                          Code:
                          YourJoyfulCustomGameInfo(WorldInfo.Game).YourCustomVar
                          or

                          as a wonderful forum member (Spoof I believe) told me:

                          you can use this version if your class doesn't recognize WorldInfo.Game

                          Code:
                          YourJoyfulCustomGameInfo(class'WorldInfo'.static.GetWorldInfo().Game).YourCustomVar

                          You can pass variables back and forth between any classes this way and keep a version in WorldInfo, where it likely belongs if it is important info about world/ game state.


                          So now you have gotten a copy of your very important custom variable into your custom PlayerController class using GameInfo!!

                          ~~~

                          Kismet Step

                          3. Go into Kismet and right click, action-> Object -> get property

                          4. Your custom variable must be a basic type like bool or float, look at the options you have in the get property node as outputs

                          5. As the input node, which is type object, do the following:

                          6. Right click -> new variable -> Player

                          7. In properties of this player var, uncheck "all players" and use player0 (unless you have multiplayer game of course, but then you need a player object for each player index 0 to number of players - 1

                          8. THIS IS YOUR CUSTOM PLAYER CONTROLLER CLASS!

                          player 0, this happy little object variable, is a link to your custom var

                          9. Make sure that in UDK in World Info you have the game type set to your custom game type

                          10. Now go back into Kismet

                          11. For the input of Object->Get Property Node, set it to Player 0 or whichever player

                          12. Enter the name of your custom variable that is in your custom PlayerController class

                          13. Create a new variable of the appropriate type based on your custom variable

                          In my example we had a boolean value isInEditor mode, so make a new boolean and connect it to the Bool output spot of the Get Property node


                          You Are Done!

                          You have now accessed an unreal script custom class, custom variable in Kismet!


                          I have thoroughly proven that this method works



                          Enjoooy!



                          Rama

                          PS: sorry no Kismet pic at moment, post any questions you might have in this thread.

                          PSS: whether or not it is good to necessitate a link between Kismet and unreal script is not the focus of this tutorial, perhaps ideally there should not be such interdependence, but the fact is it will occur for many of you, and has happened to me, and I have a solution for you! ♥

                          Comment


                            #14
                            I recommend you make your own kismet nodes, this tutorial is just a quick way to access class vars

                            really you should use a custom kismet node

                            and then you can retrieve any data you want from unrealscript

                            Custom Kismet Nodes
                            http://forums.epicgames.com/threads/...0#post30720380



                            Rama

                            Comment

                            Working...
                            X