Download

Best way to Create a destructible pong paddle

So I’m working on creating a pong-like game in 3d space with 6 degrees of freedom movement, and weapons. Currently I’m having some weird issues. So I was having trouble getting my custom collision channels to work. Which I outline here Help Using Custom Collision Channels. - UE4 AnswerHub Which is still sort of an issue, but I’m currently working on just using the built in channels to try to accomplish my goals.

I decided that I had to make the actors back into components, because things were hitting my outer actor, but I couldn’t figure out how to get it to fire the hits on the subactors. Its like once they’re attached to another actor they lose the ability to have collisions themselves. In order to have this work, I have to construct all the blocks in the constructor for the paddle actor. So I have it able to create a paddle now, and even have the collision stuff working for the regular projectiles to register a hit event. I also am able to get it have each block with a pointer to each neighbor so I can have some AOE effects hit the paddle. I have some testing actors that just fire a projectile at you on a timer. Its plane locked so I can choose to take a few shots on the paddle where I want to with relative ease, then move off the plane it’s shooting on… Here’s an image of what I’m talking about with the paddle taking damage. The blocks with zero hitpoints left turn off their visibility and set their collisions off.

Basic Paddle

So I have a couple issues with this still. When I have the ball (its pong after all) colliding with it, I can’t get it to not collide with the whole actor and only hit the sub components. If there’s a big hole in your paddle and you try to hit the ball, it should fly through the hole, not bounce off where the blocks were. This is what I was trying to accomplish with my custom collision channels, but it hasn’t worked out so far.

The other, and honestly more major issue I have with my current setup is that I cannot easily create blueprint children from this and have them use a different block type to build their paddle from. The custom movement component I’ve written takes the sum of all the blocks movement characteristics and uses that to defines the way it moves. Initially I want to just be able to make an entire paddle construct from just a single different block type. The grey blocks you see in the image are the default paddle, but I want there to be able to be paddles made of different materials with different properties without having to take a complete copy of the paddle base class and changing just the single index value. Like, a Steel paddle might be slower but have more Hp and be heavier, causing its impacts against the ball to be more intense. The Bamboo Paddle could be faster but break more easily and have softer hits.

A section of my current problematic code is below This is how I’m spawning the blueprint class from the C++. In the Code I reach up to the game instance blueprint, where I store an array of BP block types, and then I use a block type index int to grab which class of block to create. I have made the BlocktypeIndex a Uproperty that can be edited anywhere. When I create blueprint child class however and change that blocktypeIndex on it, the engine crashes.




static ConstructorHelpers::FObjectFinder<UClass>DataObjectAsset(TEXT("Class'/Game/BP_HyperPongGameInstance.BP_HyperPongGameInstance_C'"));
if (DataObjectAsset.Succeeded()){

   TheData = Cast<UPuzzlePlatformsGameInstance>(DataObjectAsset.Object->GetDefaultObject());
   BuildingBlockClass = TheData->BlockTypes[BlockTypeIndex];
   
    if (BuildingBlockClass) {

   FVector Loc;
   for (int32 i = 0; i < PaddleHeight; i++){
      for (int32 j = 0; j < PaddleWidth; j++) {
         FName name = *FString::Printf(TEXT("Block %i, %i"), i, j);


         UPaddleBlockBase* NewBlock = (UPaddleBlockBase*)CreateDefaultSubobject(name, UPaddleBlockBase::StaticClass(), BuildingBlockClass, true, false);

         Loc.Y = -(BlockWidth * PaddleWidth) + (j * BlockWidth * 2) + BlockWidth;
         Loc.Z = BlockHeight * PaddleHeight - (i * BlockHeight * 2) - BlockHeight;


         NewBlock->SetWorldLocation(Loc);
         NewBlock->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);


         PaddleBlocks.Add(NewBlock);



         }
      }
   }
}


I have also tried generating the components at runtime, but I’ve run into mad crashes doing things that way too. I’ve also tried creating c++ children of the paddle class and changing the block type index in them, but it also crashes my editor.

I’m lost. I’m totally willing to rearchitect my strategy for this, but at the moment I have no idea how, or what direction to go. I have a ton of ideas for this game, but I just gotta get the basic collisions working before I can dive in on that. Any and all help would be greatly appreciated.