Cast to (insert class/blueprint name here)

I’ve started playing around with casting and there are few things.

I made class Gun, and classes Pistol, Shotgun and Bazooka that inherits from Gun.

In C++ (as far as I know) you can’t have an instance of a parent and cast it to childs. You need a child that is type of it’s parent, for example:

Gun* myGun = new Bazooka();

If I understand correct you are trying to do something like:

Gun* myGun = new Gun();
((Bazooka*)myGun)->Shoot();

Normally in C++ it will cast, but it will still execute Shoot method from Gun, not Bazooka. In blueprints it doesn’t cast at all. That’s because the program would have to have information about every children in one parent.

But you can create an array of Guns and fill them with different kind of guns and then pick them (based on index) and shoot.

Edit 21.11.2014:
I’m not sure if that’ll help, but I found old code from UE3 in UnrealScript, where I was casting almost dynamically. I had class named PackageTemplate and a TesterPackage that inherits from it. There I had some function like:

function LoadPackage(class<PackageTemplate> PackageType)
{
   local PackageTemplate PackageToLoad;
   PackageToLoad = new PackageType;
   PackageToLoad.Load();
}

And I was running it using:

LoadPackage(class'TesterPackage');

If it was possible in UnrealScripts it should be possible in C++ too. But still you need proper parent-children structure for this.