Hi, Im trying to shoot a projectile from a weapon ive picked up from the floor.
Having trouble referencing the rifle Skeletal mesh properly to then use the MuzzleFlash Socket. Picking up and firing works, but the projectile + muzzle flash emitter is not firing from the end of the gun and im receiving these errors,
Blueprint Runtime Error: “Accessed None”. Node: SpawnActor Projectile BP Graph: EventGraph Function: Execute Ubergraph Ue 4ASP Character Blueprint: Ue4ASP_Character
Blueprint Runtime Error: “Accessed None trying to read property Target_0”. Node: SpawnActor Projectile BP Graph: EventGraph Function: Execute Ubergraph Ue 4ASP Character Blueprint: Ue4ASP_Character
I see, you cannot reference the weapon bp like that, since you pickup generic actor. Best option would be to use a blueprint interface. You still need to reference the weapon, but as an actor. It is your “held item”. Then you communicate with this reference via an interface. It removes the need of casting which is good since you have probably many different type of object to pickup in your game
For example you create a blueprint interface to communicate with weapons. In this interface you create a function called “Get muzzle location_BPI” (BPI stands for “blueprint interface”, it is recommended to use the suffix in your interface function names).
This function needs to have a return, in your case a transform, or maybe just a location if it is all you need. There isn’t much to do in the interface itself, but you need 2 more things : implementing the interface in your weapon blueprints and feeding the function with the mesh and socket, and calling the function where you need it (in your first picture after the line trace, you would use the “held item” actor ref and call “Get muzzle location_BPI”. And here you have your location.
This is basically how to use an interface, if you need more precision I can provides pictures.
An other recommandation is to use parent and children blueprints especially if you have many item.
For example you have a “master weapon bp”. This is the parent of all weapons, all other are derivated from it. A first child would be “melee master bp” (and this one has its own children “knife_bp”, “wrench bp” etc…) and a second one would be “firearm master bp” (with its own children “pistol bp”, “shotgun bp” etc…). See this as a genealogic tree with different levels.
One big advantage is that variables, functions, components and interfaces implemented in a blueprint are inherited by its chidren. Concretely you would put the interface in the “master weapon” once and that’s it. You don’t need to do it each time you create a new weapon.
Even better, the “Get muzzle location BPI” could be simply renamed in “Get socket location_BPI” with a name input so you can get any socket (I don’t know, maybe the knife has a socket for blood splatter but this socket isn’t named “muzzle”).