how can i “set simulate physics” after “spawn actor from class” ?
I need to deactivate the simulate physics to equip the weapon with all functions to my character.
Have allready created a socket on my character to attach them to.
The Editor tells me this error: “Primitve Component Reference is not compatible with Actor Reference”.
How to make a dynamic Actor Reference to a primitive component reference?
Hey Todesklinge. I’m not sure what BP this is (character?) but I think this can be solved by casting to your weapon class. After the ‘SpawnActor’ node drag out the Return Value and ‘Cast to XXXX’ (where XXXX is your weapon class). Then from the Return of the Cast you can drag out again and ‘Get Skeletal Mesh’ and then ‘Set Simulate Physics’ off that. After that you’ll also need an ‘Attach to’ node to select the socket the weapon attaches to, but I think you may already have that off screen.
Glad it’s working. About the attachment - I’m at work and away from Unreal at the moment but you should have an Attach to node in your graph. Could you post a screengrab of the graph around that? Also, what is this Blueprint? I think it’s your character Blueprint, right?
I’m pretty sure the problem is the socket name. If you look at the attach to node you can see it says ‘In Socket Name: None’. You’ll need to include the socket name there. The ‘Parent’ input doesn’t work the same way as a socket.
For future projects if your NPCs and Characters are using the same functionality then it might be better to have the weapon attachment logic in a base class that both inherit from.
Hey again Todesklinge. I wanted to reply here rather than private message in case it can help anyone else.
First I’d check that you have a socket set up correctly on the skeleton. If your NPCs and Characters use the same skeleton then this should be fine I think but you should double check that your Character is using the same skeleton and that the socket exisits. Copy the exact text of the socket name - in mine below I’m using ‘RightHandSocketRifle’.
Second I’ve noticed that you’re using a deprecated node for the Attach. I’d suggest replacing that and using ‘AttachToComponent’. Others may work but if you have trouble then it’s worth replacing any deprecated nodes as a first trouble shooting step. Create the AttachToComponent node by pulling out from your MyCharacter node.
Third paste the Socket name (‘RightHandSocketRifle’ in my case) as the socket name on the AttachToComponent node. I think the ‘Parent’ input should be direct from your ‘MyCharacter’, not the ‘RightHand’ variable, then you have the rest of the options correct already. Without the socket name here the weapon will not be attached to your character’s skeleton and I’m pretty sure that’s why the weapon is just floating.
Ah, this is slightly different from what I thought was happening. Your thread title mentioned you wanted to set simulate physics (deactivated) so I thought you wanted no physics at all on the weapons. You mention throwing or kicking the weapon and that’s not something I’ve really experimented with personally, but I think what you’ll want to do is deactivate physics when the character picks up a weapon, then activate physics when the weapon is released by the character. That should get you close to the behaviour you want.
I have tested now my setting on MyCharacter Blueprint and it works.
Have connected the node to EventBeginPlay and spawn one single weapon with the same nodes like above on it, and it works!
The weapon is attaching and the physics works well.
I found an error in the communication between “InventoryMenu Blueprint” and MyCharacter (all equip things works are in my InventoryMenu Blueprint, i dont want to messy it on MyCharacter.
How can i “CastTo…” the Physics of a weapon to MyCharacter?
Have tested much, from CastToMasterItemClass over MasterItem and difference CastToMyCharacter, but it dont works.
Anyone have an idea how can i give the information about Physics directly to MyCharacter?
You’ll need a reference to your Weapon from MyCharacter. There are a number of ways of doing that but I think the simplest way would be to promote the Weapon to a variable (right click on the return value from the SpawnActor node for that) in the InventoryMenu blueprint. Call it RightHandWeapon or something similar. Then in MyCharacter from a reference to the InventoryMenu you can drag out and GetRightHandWeapon, then CastToMasterItem (it’s a reference now, not a class, because it’s already been spawned), and then from that GetSkeletalMesh / GetStaticMesh (depending on which your weapon has), and finally from that you can SetSimulatePhysics.
With regard to Blueprint Communications this video is long but I found it really helpful: