Results 1 to 9 of 9
  1. #1
    MSgt. Shooter Person
    Join Date
    Sep 2010
    Location
    San Marcos, Texas
    Posts
    64

    Default How to access a new class in game?

    I've subclassed pawn to create a new type of "navPoint", which can define areas of cover, overwatch positions, etc.

    I want to have a class which will keep an array of these points. In its simplest form, it is a placeable actor which has an array of my navPoints.

    Each bot controller would have a reference to this class, which would be used to find nearby points of interest (say, in state 'Patrolling' or 'Seeking Cover').

    However, here's where I come up against a brick wall. If it's placeable, then how do I get access to it? If (as I would rather do), I create an instance of the class and fill its array of NavPoints upon level start, where do I do that?

    Would I do that in GameInfo, say in BeginPlay(), then have my bots grab a reference to it in PostBeginPlay()?

    My question then, is how and where to create an instance of a new class so that it is script accessible, and once it is instanced, how to set a reference to it.

  2. #2
    MSgt. Shooter Person
    Join Date
    Sep 2010
    Posts
    51

    Default

    i couldnt get the static method to work no matter how many variations i tried... what u should do is just extend gameInfo with your own class and put in some functions which hold on the info, then u can call gameInfo.getYourData() from each of your pawns, and it should be the same instance of the data since gameInfo is only spawned once.

  3. #3
    Skaarj
    Join Date
    Oct 2010
    Location
    Georgia(country),Tbilisi
    Posts
    27

    Default

    Seems one more class to copy, one more day to wait

  4. #4
    MSgt. Shooter Person
    Join Date
    Nov 2009
    Posts
    115

    Default

    Quote Originally Posted by beeph View Post
    i couldnt get the static method to work no matter how many variations i tried... what u should do is just extend gameInfo with your own class and put in some functions which hold on the info, then u can call gameInfo.getYourData() from each of your pawns, and it should be the same instance of the data since gameInfo is only spawned once.
    I've wondered about this myself.

    What about when you load a new level? Will any data held by the GameInfo be lost?

  5. #5
    MSgt. Shooter Person
    Join Date
    Sep 2010
    Location
    San Marcos, Texas
    Posts
    64

    Default

    The problem is that I want to have a list of these nodes accessible to my pawns so that they can decide where to move next. It seems rather contradictory to OOP methodology to have the GameInfo hold a copy of it. I should be able to grab a reference to that class.

    Any ideas?

  6. #6
    Veteran
    Join Date
    May 2007
    Location
    Above KillZ, Below StallZ
    Posts
    9,953

    Default

    you would need a reference to an instance of that class, not a reference to the class. And you can store that reference in your GameInfo if it's never needed on clients, or GameReplicationInfo if it is needed on clients. Or iterate AllActors() every time you need something .. sure, go ahead
    http://www.ericbla.de http://www.dungeondefenders.com http://en.wikipedia.org/wiki/Warm_Gun http://www.rekoil.com http://www.groundbranch.com

    - Please don't send me private messages asking programming questions, those would be better asked on the Programming forum here. Thanks

  7. #7
    MSgt. Shooter Person
    Join Date
    Apr 2010
    Posts
    137

    Default

    I have used custom classes based on UTSquadAI and ActorFactoryAI: The factory creates a SquadAI and assigns it to the bots so all Bots share the same SquadAI and can use its functions for navigation.

    This can help you searching for your InfoActors:
    Code:
    class MySquadAI extends UTSquadAI;
    
    var array<Actor> TargetsChill;
    
    auto state init{
    	function BeginState( Name PreviousStateName ){
    		FindTargets();
    		GotoState('Idle');
    	}
    }
    function FindTargets(){
    	local MyDestinationChill Chill;
    	
    	ForEach AllActors(class'MyDestinationChill',Chill) {
    		TargetsChill.AddItem(Chill);
    		`Log("found"@Chill.Name@"at"@Chill.Location);
    	}
    }
    HTH
    Last edited by eurosat7; 10-08-2010 at 03:39 AM.

  8. #8
    Skaarj
    Join Date
    Oct 2010
    Location
    Georgia(country),Tbilisi
    Posts
    27

    Default

    Try like this:

    Code:
     function SomeFunction()//where u want to get data
             {	
             local NavPoint tmn;
             local array<NavPoint> NavPoints;
    	
    	foreach WorldInfo.AllNavigationPoints(class'NavPoint',tmn)
    		 NavPoints.AddItem(tmn);
             }
    If u want to access custom variables in your gametype:

    Code:
     function SomeFunction()//where u want to get data
             {	
             local SomeVariable sv;
    	
             sv = MyGameType(WorldInfo.Game).SomeVariableName;
             }
    Last edited by Delfistyaosani; 10-08-2010 at 05:41 AM.

  9. #9
    MSgt. Shooter Person
    Join Date
    Sep 2010
    Location
    San Marcos, Texas
    Posts
    64

    Default

    I got this working last night. All I really had to do was create my NavPoint class (subclass of Actor) and the container for it (called NPNet, subclass Info). Once that was done, I spawned an instance of it in my GameInfo class's auto State, because that way it was created before my bots were spawned.

    The only slightly tricky thing was getting access to the NPNet in my botControllers. Because I subclassed GameInfo, I had to use the following line:

    Code:
    navNet = ProjectGame(WorldInfo.Game).navNet;
    Done. It really wasn't that hard, I was just a little confused on where in code to spawn it, etc. Thanks for the help, guys.


 

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.