PDA

View Full Version : UE3 - UT3 Cast Error from Mutate


Cockbite
9th Jul 2010, 08:44 PM
This code is supposed to be a simple Self Destruction mutator. The idea is you just type "Mutate Explode", and then you go out with a bang. My problem is that I'm getting an error that I don't know how to fix.

SelfDestruct.uc(11) : Error, Cast from 'Pawn' to 'SelfDestruct' will always fail

SelfDestruct() asks for a Pawn, and I would assume that 'Sender.Pawn' is a pawn, so I don't quite see what the problem is. Does anyone know how to make this work?

Class SelfDestruct extends UTMutator;

var PlayerController playerController;
var Controller InstigatorController;

function Mutate(string MutateString, PlayerController Sender)
{
Super.Mutate(MutateString, Sender);
if (MutateString ~= "Explode" && Sender != None && Sender.Pawn != None)
{
SelfDestruct(Sender.Pawn);
}
}

function SelfDestruct(Pawn P)
{
local UTProj_HeroRedeemer Proj;
Proj = Spawn(class'UTProj_HeroRedeemer', InstigatorController,, P.Location);
}

Wormbo
10th Jul 2010, 02:45 AM
Typecasting seems to take precedence over function calls. Your code really tries to typecast that Pawn reference to your mutator class.

Cockbite
16th Jul 2010, 08:03 PM
I'm still not sure I understand what you said, but I figured out the problem. The error here is that I made a function called "SelfDestruct" when the game already has a native SelfDestruct function. This apparently confuses the game and makes it angry. Once I changed the name of my function to "BlowUp", it works perfectly like I intended.

Angel_Mapper
16th Jul 2010, 08:06 PM
No, it was because the class name is SelfDestruct, so it thought you were trying to cast the Sender.Pawn to a SelfDestruct class type.

Cockbite
16th Jul 2010, 09:18 PM
No, it was because the class name is SelfDestruct, so it thought you were trying to cast the Sender.Pawn to a SelfDestruct class type.

Okay, I get it now. So, I can call my function SelfDestruct if I change the script name.