PDA

View Full Version : Class 'instanceof'?



Gedden
05-26-2011, 11:52 AM
I am having a little trouble figuring out the proper syntax for what I want to do. What I *really want is the equivalent of the 'instanceof' operator in Java.

What I am trying to do:
Basically I want to get 'the world' under my mouse, which may be a BSP, height map, static mesh... (basically *not a skeletalmesh).

I noticed that all Objects have a Class member/reference. However I seem to be having an issue with the syntax... The following code does not compile, and im not exactly sure how to compare classes, or find out if a specific actors class inherits ...



simulated function GetWorldUnderMouse(out Vector hitLocation, out Actor TraceActor)
{
local Vector hitNormal;

foreach TraceActors(class'Actor',TraceActor, hitLocation, hitNormal, mouse3D + worldDireciton * 5000, mouse3D )
{
if( TraceActor == WorldInfo || TraceActor.Class == StaticMeshActor )
return;
}
TraceActor = none;
}


I realize I could accomplish this task by doing three raycasts, on class'Actor' and check for worldinfo (for bsp), on class'StaticMeshActor' and whatever actor a terrain is.. however that seems wasteful.

Solid Snake
05-26-2011, 11:57 AM
Actors that are considered to be world geometry have a flag called bWorldGeometry set to true. So you can just filter for that.

That is to say:



if (Actor.bWorldGeometry)
{
// Trace has hit the world
}

Gedden
05-26-2011, 01:26 PM
Thanks, that should work for me, and would most likely be faster doing any class / inheritance checks anyway.

That being said, for future reference, does anyone know if there is a way to do a class / inheritance check?

ffejnosliw
05-26-2011, 02:03 PM
In Object.uc:



/**
* Determine if a class is a child of another class.
*
* @return TRUE if TestClass == ParentClass, or if TestClass is a child of ParentClass; FALSE otherwise, or if either
* the value for either parameter is 'None'.
*/
native(258) static final function bool ClassIsChildOf( class TestClass, class ParentClass );
native(197) final function bool IsA( name ClassName );