New Developer With Some Questions!

Hii Everyone,
Im nearly new with unreal and i have some questions if anyone could help me, thank you.
First of all sorry for my bad english!
Im doing a third person shooter and im using the pickups, and i have a fatherPickup that the code says that the player can pickup it and is destroyed with the pickup event, in the other hand i have the PistolChild that have the fire function, and finally i have the bp_thirdPerson with the Equip Function calling the pickup and equiping on the place, i will post here all the codes for beeing more clear.
Thank you all a lot!



Hello, @OjusMan can you explain what problem are you exactly facing ? And send a better picture of the equip event because it’s very blury.

Hii Aob,

Thanks for your quick answer and Sorry for my bad photos, here i post again the Equip event.


I hope is more clearly.
The problem im faceing appears when i stop runion the game and is the next one:

Blueprint Runtime Error: “Attempted to access ArmaHijo_C_UAID_00D861E65A4893CF01_1748309624 via property As Pistol, but ArmaHijo_C_UAID_00D861E65A4893CF01_1748309624 is not valid (pending kill or garbage)”. Node: Fire Graph: EventGraph Function: Execute Ubergraph BP Third Person Character Blueprint: BP_ThirdPersonCharacter.

I think the problem may be because when i take the pickup it gets destroy so im not capable to call the function of the Pistol or i dont understand well the problem.

Thanks.

@OjusMan Are you sure the cast node even works because you are trying to cast a pick up base blueprint to a pistol try to do print string out of cast failed. And destroy the pick up blueprint at end because even if the cast works you already destroyed the array element so there is nothing to cast to

Hi sorry for my delay,
yes the cast node works because the BP_ThirdPerson when he equips the pistol it appears in the spine shocket, and i dont have any problems with it not even when i equip on my hands, here i add that part of the code

Thanks

And finally i have the ainm and fire events that call the pistol fire function, the problem only appear when i shoot, well before shooting and stoping the game, here are the anim and fire events code.


thanks

EDIT: The reason why you are getting the errors is because of As Pistol as you can see from the error you are getting:

Attempted to access ArmaHijo_C_UAID_00D861E65A4893CF01_1748309624 via property As Pistol, but ArmaHijo_C_UAID_00D861E65A4893CF01_1748309624 is not valid (pending kill or garbage)

So it should be because you are destroying your pick up first.

@OjusMan sorry for my late responses i just had a very busy day. Here’s a way that you can do it without getting the error you can copy the things you need from this system if you want. Also using this system you will be able to add different items easily:

  1. Create a folder called PickUp_System and add two folders in it: Items and Interfaces

  2. In the Interfaces folder you will need to create two interfaces: BPI_Weapon_Pick_Up and BPI_Weapon_Fire

  3. In the Items folder add a folder called Pistol and create two blueprint actors: BP_Pistol_Pick_Up and BP_Pistol

  4. In your character skeleton add a socket for the pistol and attach to hand_r or hand_l

  5. Go to your character blueprint and create a new component with type child actor and rename it to Weapon or Item
    1

  6. In the BP_Pistol_Pick_Up we need to add interface BPI_Weapon_Pick_Up and a static mesh for the pistol and a sphere collision. Here is the code for the PickUp function:

  7. In the BP_Pistol we need to add interface BPI_Weapon_Fire and again add a static mesh for the pistol. The code we need is:
    4

  8. In the BP_ThirdPersonCharacter


I hope this helps you at least a bit.

Hii Aob,
Sorry for my late replay and thank you very much for your response, i have some doubts about the ChildActor component because i already use one ChildSkeletalMesh on my blueprint to equip the pistol on the spine and then to take it out to the hands

Yes i know that. But i think it will be better to use the Actor child because you don’t have to cast to your pistol blueprint. And it’s easier to add a new weapons to the game. You just have to create pick up actor and a weapon actor and implement the interfaces. As you saw from my example in the BP_Pistol_Pick_Up i just set the Actor child(Weapon) in the character to a pistol and destroy the collectable actor. Avoiding casting and getting reference to other stuff but the player character. As i mentioned earlier the errors you are getting are coming from As Pistol so if you do it with Actor child you won’t even need to worry about it and it will be easier to work with as well. I hope that it make sense.

@OjusMan i just took a closer look to your solution here is what you can do if you don’t want to use Actor child:

  1. The reason why you are getting the error is as i said already is because you are destroying the As Pistol variable so you can’t access it anymore after it gets destroyed. If you replace the delay until next tick node with just delay and put a big value like 100 and play for a while you will notice that you won’t get any issues but after the 100 seconds pass then there is going to be problems.
  2. That’s why i suggested to use Actor child because this way we only destroy the pick up and not the weapon.
  3. So you could use Actor child or you can move your fire event in the character blueprint and out of left mouse button event you check what weapon is the player holding and then call the necessary event based on the result.

I am so sorry for all the confusion it just took me some time to understand your code.

NOTE: If you choose to keep it with the skeletal mesh way and just store the fire event in the character blueprint you won’t be able to put any code in your Pistol blueprint because you can’t access it. So i recommend using the method i showed you earlier.

Hii AoB!!!
Thak you very much for your help, im very greatfull, now i understand it and finally it works, and it doesnt appear more problems.
I feel very grateful for all the help you have given me during all this time and thank you very much for been so patient with me.
It has been a pleasure to lern from your avices, thanks.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.