• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Reach Mutator class from PlayerController

Schneider95

Grizzled Veteran
Jan 7, 2012
303
1
Paris
Hello,

in my PostBeginPlay method of my MyMutator class, i do this :

Code:
gameRules.mutatorRef = self;

This way, i can access property from MyMutator.

But what if i want to reach a MyMutator's property from my MyPlayerController class. Can i do something like "playerController.mutatorRef = self" ? Or is there another solution to reach the MyMutator properties from another classes ?

Thank you by advance.
 
Last edited:
Hello,

in my PostBeginPlay method of my MyMutator class, i do this :

Code:
gameRules.mutatorRef = self;
This way, i can access property from MyMutator.

But what if i want to reach a MyMutator's property from my MyPlayerController class. I define this controller like this :

Code:
gameType.PlayerControllerClass= class'KFNodePlayerController';
Can i do something like "playerController.mutatorRef = self" ? Or is there another solution to reach the MyMutator properties from another classes ?

Thank you by advance.

Here is some code I use to get my base mutator in my playercontroller
Code:
var Mutator BaseMut;

simulated function PostBeginPlay()
{
    local KFGameType KF;
    local Mutator M;
    
    Super.PostBeginPlay();
    
    if( Level.NetMode != NM_DedicatedServer )
        return;
    
    KF = KFGameType(Level.Game);
    
    for ( M = KF.BaseMutator; M != None; M = M.NextMutator ) 
    {
        if ( M.IsA('FMXBaseMut') )
        {
            BaseMut = M;
            break;
        }
    }
}

function Mutator FindBaseMutator()
{
    local KFGameType KF;
    local Mutator M;
    
    KF = KFGameType(Level.Game);
    
    for ( M = KF.BaseMutator; M != None; M = M.NextMutator ) 
    {
        if ( M.IsA('FMXBaseMut') )
        {
            BaseMut = M;
            break;
        }
    }
    if ( BaseMut == none ) {
        log("FMXBaseMut not found!", class.outer.name);
    }
    
    return BaseMut;
}

I'm not entirely sure what you're asking though
 
Last edited:
Upvote 0
The instance of your MyPlayerController class is created before the MyMutator::NotifyLogin function is called. You can simply add a public MyMutator variable to your MyPlayerController class and then set it in the MyMutator::NotifyLogin function.

MyPlayerController:
Code:
var MyMutator MutatorRef;

MyMutator:
Code:
function NotifyLogin(Controller NewPlayer)
{
    if (NewPlayer.IsA('MyPlayerController'))
    {
        MyPlayerController(NewPlayer).MutatorRef = self;
    }
}

One thing though, the MyPlayerController::postBeginPlay function will be called before MyMutator:NotifyLogin. This means that you can't access MutatorRef in PostBeginPlay (it's not yet set). If you need it there, then forrestmark9's suggestion is the way to go.
 
Last edited:
Upvote 0
The most general way to do this here :

Code:
class MyUtil extends Actor abstract;

var MyMutatorClass MyMutator;

static function MyMutatorClass GetMyMutator(optional Actor A)
{
	local Mutator result;
	
	if (default.MyMutator == none)
	{
		if (A == none)
			return none;
		for(result=A.Level.Game.BaseMutator; result!=none; result=result.NextMutator)
		{
			if (MyMutatorClass(result) != none)
			{
				default.MyMutator = MyMutatorClass(result);
				break;
			}
		}
	}
	return default.MyMutator;
}
Then you can call this function from any actor typing this:

Code:
MyMut = class'MyUtil'.Static.GetMyMutator(Self);
 
Last edited:
Upvote 0
Code:
static function GetMyMutator(optional Actor A)
{
    local Mutator result;
    
    if (default.MyMutator == none)
    {
        if (A == none)
            return none;
        for(result=A.Level.BaseMutator; result!=none; result=result.NextMutator)
        {
            if (MyMutatorClass(result) != none)
            {
                default.MyMutator = MyMutatorClass(result);
                break;
            }
        }
    }
    return default.MyMutator;
}
Sadly, it won't work like that. BaseMutator is defined in GameInfo, so you need Level.Game. Furthermore, you need a return type.
 
Last edited:
Upvote 0