Reach Mutator class from PlayerController

  • 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/

Schneider95

FNG / Fresh Meat
Jan 7, 2012
306
1
0
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:

forrestmark9

FNG / Fresh Meat
Nov 29, 2011
1,110
40
0
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:

Schneider95

FNG / Fresh Meat
Jan 7, 2012
306
1
0
Paris
In fact, in the PostBeginPlay of MyMutator, i defined the value of a property of MyMutator. I need to retrieve it in MyPlayerController.

I look your code.
 
Last edited:

Ducky

Super Moderator
May 22, 2011
6,358
237
0
Netherlands
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:

Schneider95

FNG / Fresh Meat
Jan 7, 2012
306
1
0
Paris
Where do you call the FindBaseMutator method ?

I have search in Mutator.uc file and there is no trace of NotifyLogin function
 
Last edited:

Dr_Killjoy

FNG / Fresh Meat
Sep 30, 2012
260
0
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:

TheMutant

FNG / Fresh Meat
May 31, 2012
562
4
0
Germany
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:

forrestmark9

FNG / Fresh Meat
Nov 29, 2011
1,110
40
0
Where do you call the FindBaseMutator method ?

I have search in Mutator.uc file and there is no trace of NotifyLogin function

I call FindBaseMutator usually in a if statment checking if the basemut is none incase of the function is called before PostBeginPlay
 

forrestmark9

FNG / Fresh Meat
Nov 29, 2011
1,110
40
0
My bad. I thought I was on the RO2 coding section :D

NotifyLogin is in UE2 it's not in Mutator, usually found in GameInfo

The mutator does have NotifyLogout but sadly that would be useless, but there is ModifyPlayer
 
Last edited: