Results 1 to 7 of 7
  1. #1
    MSgt. Shooter Person
    Join Date
    Dec 2009
    Posts
    149

    Question How to Share Data Between Pawn and Controller?

    Thanks for your time.

    I'm trying to figure out how to have a variable stored *ONCE* (that means not two variables that mean the same thing, but rather one sort of globalized variable between these two classes) and able to be referenced between a pawn and its controller without network overhead (that is, without using a PRI that will get noticed by anything else, be it servers, peers, etc).

    This is not the same question as asking, "Can I have one definition of a variable in a class and dependsOn() the other class but still have to declare it a second time?"

    Is this possible?

  2. #2
    MSgt. Shooter Person
    Join Date
    Apr 2011
    Posts
    175

    Default

    Why not? Declare a variable in the controller. You can now access that variable from the Pawn too since the Pawn class always stores a reference to its controller. Like this: Pawn.Controller.yourvariablehere = 100.

  3. #3

    Default

    If you have for example a pawn class called TestPawn and controller class called TestController, declare your variable.. say vector TestVariable in TestPawn, to get it in TestController and assign the pawn location do:
    Code:
    TestPawn(Pawn).TestVariable = Pawn.Location;

  4. #4

    Default

    Made me double post for some reason ._.

  5. #5
    MSgt. Shooter Person
    Join Date
    Dec 2009
    Posts
    149

    Default

    Must you question my reasoning? I just want to know if it can be done. I specifically posted thorough information on what this question was and was not, so as to avoid getting these kinds of responses.

    Thank you for your time, but my problem remains unsolved.

    I love you.

    PS: Think pointers. I want one object that both classes talk to, not indirect referencing by typecast. Thanks.

  6. #6
    Prisoner 849
    Join Date
    Nov 2007
    Location
    Austin, Tx.
    Posts
    858

    Default

    You don't have pointers in UnrealScript and you don't have control over memory assignments. Also, casting is how it's done. So, I think the answer to your question is no. You can not do what your trying to in UDK.

  7. #7
    Boomshot
    Join Date
    Aug 2011
    Posts
    2,920

    Default

    You just need a third-party object to store your data, and references to it. I don't know what context you're using it for, but I'll assume single-player as that's the safest for this kind of thing.

    Code:
    class CommonData extends Object;
    
    var int Foo1, Foo2;
    var string Bar1, Bar2;
    You need to instance the object once, perhaps in the player controller.

    Code:
    var CommonData CD;
    
    // ...
    event PostBeginPlay()
    {
        super.PostBeginPlay();
    
        CD = new() class'CommonData';
    }
    Then your custom pawn and controller each need a reference to it (obviously if the PC hosts the object then it already has it). There are different ways to do this depending on your situation - if your possessing/unpossessing pawns then you need to handle the exchange and release of references carefully, which can get ugly.

    A safer way would be to store a single reference in the controller and then have pawns request it through their controller.

    CustomPlayerController.uc:

    Code:
    var CommonData CD;
    
    //...
    function CommonData GetCommonData()
    {
        return CD;
    }
    CustomPawn.uc:

    Code:
    function DogsAreSmelly()
    {
        local CommonData CD;
    
        if( CustomPlayerController(Controller) != None )
        {
            CD = CustomPlayerController(Controller).GetCommonData();
    
            CD.Foo1 = 5;
            CD.Bar1 = "Dog shampoo."
        }
    }
    Obviously the controller just uses the CD reference directly.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.