cannot cast IIGameObject of type Spline to IIGameSpline

 
 
 
Posted by:paolo83
Data created:24 August 2011

i have IIGameObject obj of type ObjectTypes.Spline but when i try to call

IIGameSpline spline = obj as IIGameSpline;

spline == null

the same with other types es. IIGameMesh when type is Mesh.

Naturally even the is operator return false.

In c++ IGameSpline * spline = (IGameSpline*)obj;  works.

I'm supposed to convert/cast in a different way?

i have some issue too~

Hi,

 

I realise i am about 2 years late to this, but it seems like a stumbling point for a few people so i will post it in case anyone else comes lookiung for an answer. The .NET SDK doesn't allow casting in that way. Doesn't matter what types you want to cast, nothing will work. The way around it is to go through the GlobalInterface like so

 

IIGameSpline spline = GlobalInterface.Instance.IGameSpline.Marshal(obj.NativePointer);

 

That will work. The same goes for getting other things like IGameMesh etc. Another example

 

IIGameMesh mesh = GlobalInterface.Instance.IGameMesh.Marshal(obj.NativePointer);

 

That will work. While i have not worked with splines, this is how i case an IIGameObject to IIGameMesh