Change Child Actor Class through Blueprints

Hello all! I’m working on a weapon system for my game. How I currently have it setup is I created an actor called AB_ItemSystem, and added it to AB_Character (my character) as a child actor. I then have another actor I created called AB_Item which I use to derive item classes from (i.e. AB_ItemFlashlight). How AB_ItemSystem works is when the player presses the Interact/Pickup button or key (R or Gamepad Face Button Top), I send a trace out toward the camera’s forward direction, check if whatever is hit can be cast to an AB_Item, and if so, I add it to my Inventory Array (array of AB_Item) and attach it to the root of the AB_ItemSystem. While this works pretty well, as you can see in the image below:

The problem is, that I can’t get any input to work from the flashlight or any other items. I believe it is not working because I just attached the flashlight to the root rather than making it the child actor’s class. I’ve also tried using “Enable Input” and it still did not work. So this brings me to the title of this post, can I set the child actor’s class from Blueprints? Or is there something that I’m missing? Thanks! :slight_smile:

Hey ,

I don’t think the child actor’s class is the problem you are encountering, it sounds like like one of the blueprints you have in use may have the Block Input option set to true and that is causing your input to not make it to your flash light. I would check your Controller and Character blueprints (those are the ones most likely to be above your item in the input stack), go to Defaults and check the Block Input option to see if it is checked.

-Steve

I’ve checked all of my blueprints and Block Input was set to false. But the flashlight works when I set it as a child actor. Is there a way to do this in Blueprints? Change the child actor class during runtime? Thanks! :slight_smile:

Hey ,

A better way to implement what you’re trying to do as far as attaching the blueprint to the player character and still have access to inputs, is to just attach the flashlight via an Attach Actor to Actor node (you can set the flashlight’s relative position immediately after to place it where you need it in relation to your Player Character’s root).

Currently, input doesn’t route down to child actor components and you also can’t change a child actor component’s class at runtime.

Try the above solution and see if that is suitable for your goal. If it isn’t, just let us know.

Thanks,

-Steve

Hey Mr. Allison! I finally fixed it. Not exactly sure what was going on, but setting Enable Input in the Construction Script wasn’t enough. Instead, I went to my Item System Blueprint, and in the function in which I update the current item, I use a for loop to compare each item’s index in the Inventory array to a integer called CurrentItemIndex, and if they are equal (meaning that is the current item), I enable input for that item and disable input for items where CurrentItemIndex is not equal to the item’s index in the array. Thanks for the help! :slight_smile: