Announcement

Collapse
No announcement yet.

Calling Functions From Other Classes

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

    Calling Functions From Other Classes

    So in my PlayerController class I'm trying to to call two functions from my Pawn class, which is also the default player class.

    The functions in the Pawn Class add and remove a particle system component to the player. I call this function when the left mouse button is pressed and released.

    When I actually attempt to do this in game I am the log says " Accessed None 'Pawn' " which I am guessing means there is no 'Pawn' in the level because it is something like 'player' because of it being the default player class.

    I'm sure this is something fundamental I am missing, and was wondering if someone could tell me how to do this properly?

    Thanks!
    ForbiddenSoul

    #2
    The log message means that a variable named "Pawn" was not pointing to an actual Pawn instance at the time you accessed it.
    And there is not much we can do to help you if you don't show your code.

    Comment


      #3
      You have to cast to the actual instance of your pawn. From your playercontroller it could be written like this:

      Code:
      function YourFunction()
      {
      local YourPawnClassName P;
      
      P = YourPawnClassName(Pawn);
      
      }

      Comment


        #4
        Excellent, thank you! Works great now that I added P = YourPawnClassName(Pawn);

        Comment


          #5
          And what would it be if I was trying to reference something in player controller?

          Code:
          local SpaceBoxPlayerController SPBC;
          SPBC = SpaceBoxPlayerController ();
          
          SPBC.GiveObtainium(100);
          I can get it compile with 'other' but then I get this:

          Comment


            #6
            Originally posted by Jestersheepy View Post
            And what would it be if I was trying to reference something in player controller?

            Code:
            local SpaceBoxPlayerController SPBC;
            SPBC = SpaceBoxPlayerController ();
            
            SPBC.GiveObtainium(100);
            I can get it compile with 'other' but then I get this:
            Assuming that this is in your pawn class, you have a variable that stores the controller being used called 'Controller'. You will need to cast that to your custom class. So:

            Code:
            SPBC = SpaceBoxPlayerController(Controller);

            Comment

            Working...
            X