Creating Working Reference

Hey all, i feel stupid for asking this but it drives me crazy and i just cant figure it out.

I have a Master BP for all weapons and child of this BP as a Rifle.

Im trying to call reference to rifle to get socket location as a starting point for bullets etc.

I understand that creating reference based on BP creates empty reference but for the love of god i cannot figure out what to enter as object when trying to set it as i get accessed none error. i watched countless tutorials and understand how to set character, GM, or object thats being spawned but for some reason i cannot set reference to the gun in a working order.

Presumably, the parent BP has a mesh, and that mesh will have sockets?

Then, in a child, you can set the mesh to an X gun.

Then the code to fire, can use the world location of the sockets. Or you can override the fire event if it’s a special case.

Hey,

what you saying is pretty much what im trying to do but its not really the problem at the minute.

Parent BP doesnt have mesh at All. Child BP have mesh with sockets.
Problem isnt Parent or child BP but referencing Parent BP as a variable without having to manually add it (instance editable) but to add it as reference so i can find sockets by name. At the minute all i get is access none issue.

at the minute im trying using “Get all Actors from class” instead but id prefer to reference BP instead. sadly all Tutorials ive watched ask to manually add it from instance.

Can you just use

image

There is no parent?

Thats what i want to do :slight_smile:

but skeletal mesh as well as socket are in the weapon BP, and i cannot reference it as im getting accessed none error. Gun reference visible above is for Master Item BP for guns if i reference main bp or main skeleton i end up with accessed none as it creates and empty reference and im not sure how i can set it in order to avoid it without setting it in instance via instant editable option

Ok, so this code is not in the gun, it’s in the player?

When you spawn the gun, you get the reference you need.

so the gun is on the ground from BP i have a code to pick it up but when it comes to shooting emitter and and bullets are off so i wanted to add it to the weapon socket. i don’t have any spawn code done. but i guess that would fix it moving forward as then i could use it to cast to ItemMaster.

As the minute though i dont know what else i can enter there.

I think, normally when you ‘pick a weapon up’, what really happens is the one on the ground is destroyed, and a new one is spawned in your hands. Then you have your reference :slight_smile:

If you want to actually pick it up ( which it sounds like you’re doing? ), you must have a reference to grab it, that’s the reference you need.

Hey sorry for late response i had loads of work and couldn’t have strength for UE :slight_smile:

i have this for spawning items but it doesnt concern only weapons not sure if that would be an issue moving forward

WHen im equipping weapon from my inventory im using this node which give back only a Boolean which i cannot use for reference.
image

so should i use item master ? or create another master gun BP as a child to item master just for the reference but can i reference it then as a gun out of node that represents master item BP ?
what im trying to do is to have different types of items and maybe i went the wrong way. :slight_smile:

PS: Just tested reference off the spawn node for all items and it gives me back access none error :slight_smile:

You could add the sockets to the parent BP, and just reference the parent BP’s sockets. That should carry over when the child BP is what’s actually being used in the game. You won’t be casting or referencing child BP.

Anything specific to the child BP you can just change in its BP. Even if you reference the parent, it will still utilize the child’s specifics.

Pretty much all of your work should be done in the parent BP.

Yeah thats what ive got done but i still cannot get a working reference only to guns, all guns BPs have sockets so thats not the issue but without a reference i cannot connect what im doing to a certain item in game. also if i have more then 1 it seems like the one on the ground is getting all the attention when done with cast to class.

In that case maybe some advice on how to reference weapon that is attached ? to make sure that im connecting everything to correct item ?

What two items specifically are you trying to couple? I’m a little lost but try this.

Create an interface BP if you don’t already have one.

Create a new function in the interface and title it “get reference”

Add an Output titled “reference” and make it whatever actor type you need the reference of. Compile.

Now, go to the blueprint you need the reference to, and add that interface under the “Defaults” tab.

Once added, look to the left side panel, under “interface” double click the new “get reference” function.

This will open up a new page with an input and return node. The return node should have an open pin.

Right click the graph and get a reference to “self”. Attach that to the open pin on the return node. Compile.

Go to the blueprint you’re trying call upon the reference from, and also add the interface in its default tab.

On the begin play node, drag off a new execution and search for “get reference” and select the one under the interface entry. This will add a node with an open pin. Drag off of that pin an promote to variable. That will be your reference. For the target input pin, attach an actor object that you can retrieve of the blueprint you want the reference to, however it is you do that. Not sure what the work flow is for your project.

You can add an “Is Valid?” node afterwards. Attach to the pin on the “get reference” function before it. Print a string to determine whether it is fetching the reference properly.

Hey i tried the reference thing but still cannot access the Gun Master BP with accessed none error.

I changed now so fire action is in Gun BP but still no luck.

Im gonna start over and maybe it will work next time as i have no idea what else i can do. This time i only call Action Fire from main BP and still access none maybe i need to redesign how im equipping weapon to have spawn instead of attach component to component i dont know but will try again.

Thank you all for support i appreciate it !

Post pictures of the interface in the two blueprints, lemme see what you’ve got.

Thank you im starting so ive deleted it from weapon BP again when it comes shooting 1st SS is in the first post and here you have how i add item to character and how i attach component to component to equip it:



Gun Equipped Boolean was added recently for testing, had error with and without it just FYI.

Thanks again, as i said im starting everything over but i feel like there is a big lesson here for me so if i can find out whats wrong its like a weight off my shoulders :slight_smile: