Why am I receiving an access violation error when attaching a weapon to player?
I have this code to attach a weapon to my main character:
The problem is that as soon as I hit play, Visual Studio comes up and tells me there is an access violation somewhere in the attachment code. Does anyone know why this doesnt work?
Ok... I'm a bit stumped but I have a hunch.
You are getting the error when trying to reference the
I do have a suggestion though... and equipping things the way the developers of the engine do in their samples might be the way to go. Read on if you are interested in a test that might fix this issue and also help you learn a better way to equip items and weapons at the start of the game.
I'm sorry I don't know why it's currently causing the error for you. Another method of implementing the same thing is not a great fix but it might help =/
I think proper implementation of weapon equipping is needed here. If you have no desire to use this method of equipping items just ignore the rest of this post... but this is the way it's done in all the examples and in 2 of my current projects. Not only is it extendable, but it works perfectly.
You are trying to start the game and have the
I know nothing of your implementation or other classes but I would suggest this...
Control your weapon attaching from your
To do this, in your
So, now back to your
Again, to do this you will need a Blueprint of your
In the editor, you simply set the
Now, I have mine set up for a
So what you do is select your
answered May 16 '14 at 09:08 PM
I'm not sure, but I think that an Actor must be attached to a USceneComponent, not a Mesh. Try creating a mount point using a USceneComponent in your character and then attach to it.
If it does not work, perhaps you could try using the AttachRootComponentTo (https://docs.unrealengine.com/latest/INT/API/RuntimeModules/Engine/GameFramework/AActor/AttachRootComponentTo/index.html). I'm using it and it works for me. It even has a EAttachLocation::Type parameter to define the offset after attached.
Follow this question
Once you sign in you will be able to subscribe for any updates here