Attach And Detach Props To Any Character With This Node!

Discussion in 'How Can I...?' started by Ivan Perfetti, Mar 15, 2021.

  1. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181
    Problem solved! Here's the node:
    https://indym.itch.io/prop-attach-node-for-buildbox-3.


    Hi guys, I'm trying to attach a gun to the hand of an FBX model using Subscene.
    After a little tinkering I managed to attach the gun model using the attachEntity() method (https://www.buildbox.com/help/buildbox-3-api-reference/nodes-sub-scene/#attachentity).
    The gun model gets animated together with the FBX model and looks like it's moving and rotating the right way but it's not in the right position and I couldn't find a way to put it in the right place.
    I tried with different FBX models and it looks like any attached object always end up at (0, 0, 0) instead of being in the same position of the joint it's been attached to so it usually ends up being in between the feet of the FBX model.
    I tried to use the jointTranslation() method but it always return (0, 0, 0) so it wasn't useful in my case.
    Am I missing something? Any help appreciated, thanks!


    Here's a clip:
     
    Last edited: Apr 7, 2021
    Hue Buildbox likes this.
  2. Tars Tarkas

    Tars Tarkas Avid Boxer

    Joined:
    Jul 17, 2018
    Messages:
    303
    Likes Received:
    228
    This is great stuff. Maybe you can share the code with us :)
    It looks like the gun needs to moved in the z and y direction. If you type numbers till it matches the position of the hands doesn't work?
    like in the image below?
    I am just guessing here.
    Capture.JPG
     
  3. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181
    Hey @Tars Tarkas, I'd love it to be that simple but that wouldn't work; actually you'd be moving the object away from its centre so even if you manage to place it in the right spot you'd end up with something reacting the wrong way to an animation.
    The real problem imho is that the attached object doesn't get positioned the right way once it is attached to the fbx model.
    You can actually use something as simple as a centered sphere and no matter which joint you decide to use it will always end up between the feet of the fbx model.
     
    Last edited: Mar 15, 2021
  4. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181
    Here's the code I'm using to attach a prop to a specific joint in a FBX model; please note the model and its animation comes from Mixamo.com:

    let enabled = false;
    let fbxModel;
    let prop;
    let jointName = 'mixamorig:RightHandIndex1'; //Name of the joint you want to attach the prop to

    function signal(name, value, sender){
    if (value){
    enabled = true;
    prop = this.scene().find('Gun')[0]; //Name of the prop to be attached
    fbxModel = this.entity().component('Mousey_Shooting'); //Name of the FBX model
    fbxModel.attachEntity(jointName, prop); //This line attaches the prop to the model
    prop.setScale(10, 10, 10); //OPTIONAL: This line is used to scale up prop because in my case it gets scaled down once attached
    }
    }

    Joints names can be found by exploring the FBX model in Blender (look for armature).
    upload_2021-3-15_16-52-24.png

    This is the very simple setup of the Mousey character with FBX model, animation and the Attach node to attach a prop to it.
    upload_2021-3-15_16-55-38.png
     
    Last edited: Mar 15, 2021
    Tars Tarkas likes this.
  5. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181
    @Sean Buildbox So if anybody knows how to fix entities attached to a Sub Scene (FBX) using the attachEntity method that would be of great help, there's not much in the documentation as of now. Thank you!
     
  6. Jackazoid

    Jackazoid Avid Boxer

    Joined:
    Sep 7, 2017
    Messages:
    176
    Likes Received:
    72
    Just drop the gun on the character in 3D world and change position there
    . Screenshot 2021-03-15 at 15.39.31.png
     
  7. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181
    @Jackazoid Thanks but that doesn't help, I've already tried before. If you managed to correctly attach an entity to a joint then please share it if you wish, that would be very useful to many. Anyway, I'm not looking to just add an object as a child, this is something very different. Just making it clear since it looks like this is what you're suggesting to do.
    The point is that the solution cannot be to manually move the prop and that's because I'm attaching an entity to a joint of a Sub Scene using the attachEntity method; this method is supposed to attach an entity to a specific bone in the skeleton of the model and it actually does it because you can see that after that the attached entity, a gun in my case, is following the animation, the problem is that the gun is not in the same position of the joint; the attachEntity method should be responsible to place it in the right place, its just that it's not doing it so my guess is that it is not working as intended.
     
    Last edited: Mar 15, 2021
    Jackazoid likes this.
  8. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181
    @Sean Buildbox @Tars Tarkas Fixed in Buildbox 3.3.10!
    Now it is possible to attach assets to joints without problems.
    Thank you to the BB team for this and for the long list of fixes in the latest releases!
     
    Tars Tarkas likes this.
  9. Jackazoid

    Jackazoid Avid Boxer

    Joined:
    Sep 7, 2017
    Messages:
    176
    Likes Received:
    72
    Unfortunately there is no node for this :(
    I suppose your coding this yourself?
     
  10. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181
    @Jackazoid Well, no, there is no node for this, I'm coding It and will publish in a couple of days on indym.itch.io. Feel free to suggest features!
     
  11. Jackazoid

    Jackazoid Avid Boxer

    Joined:
    Sep 7, 2017
    Messages:
    176
    Likes Received:
    72
    Sounds great. I would like to attach and unattach a pair of shoes to my character but right now I have no suggestion because I'm not sure what the possibilities are. Looking forward to the node.
     
  12. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181
    @Jackazoid @Tars Tarkas This node will help you attach and detach props to any character.
    I'm going to publish it in a day or two on indym.itch.io, stay tuned!

    Meanwhile here's a clip, comments and suggestions are always appreciated!
     
  13. Tars Tarkas

    Tars Tarkas Avid Boxer

    Joined:
    Jul 17, 2018
    Messages:
    303
    Likes Received:
    228
    This looks amazing. It opens a lot of opportunities
     
    Ivan Perfetti likes this.
  14. Jackazoid

    Jackazoid Avid Boxer

    Joined:
    Sep 7, 2017
    Messages:
    176
    Likes Received:
    72
    Exactly my thoughts!
     
  15. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181
  16. swiftcurrent

    swiftcurrent Avid Boxer

    Joined:
    Mar 12, 2017
    Messages:
    306
    Likes Received:
    381
    Appreciate the hard work you put into making this, however it doesn't work for me; the attached object is always static or it disappears
     
    Last edited: Apr 2, 2021
  17. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181
    Hi, I'm sorry about that, let's see how to fix it. Which asset do you have multiple sub-scenes into? Is it a character or a prop you want to attach to it? Please explain me in detail how you're using the node and how your assets are configured and/or share with me an example of your setup; in DM if you prefer. Also, in case you haven't, please check the demo game, it shows how to configure the node for a few basic use case.
     
  18. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181
    Also, if the object becomes static or disappears it might be because the attach point is not a valid one or the object is attached to the attach point and is now hidden/covered by the model mesh.
    As mentioned in the node description, you may select the attach point by either using the dropdown list or by setting a specific name, here's that in more detail:

    - Attach Point: a dropdown list with all of the 65 standard attach points (bones) available in most models rigged with Mixamo (www.mixamo.com). While this would work for many models, please note that not every model on Mixamo uses the same bone structure and names; in such cases you'll still be able to attach a prop by using the "Alt. attach point" attribute as described in next point.

    - Alt. attach point: here you can specify an alternative attach point in case the FBX model you're using wasn't rigged with Mixamo or isn't using the standard bones names used by Mixamo, to discover names you have to check inside the FBX model you're using, for example by opening it in Blender (www.blender.org) and checking bones under "Armature", there you'll find the complete skeleton of the model and the name of each of the bones that are part of it; for example the neck bone in Mixamo might be called "mixamorig:Neck".
     
  19. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181
    @swiftcurrent @Jackazoid @Tars Tarkas
    Hi there! I've just published a small update of the Attach to Target node to improve error checking and messages so now you'll get even more information in case there is something not setup the right way; on the node page I've also added F.A.Q. and Troubleshooting guide, you'll find it here: https://indym.itch.io/prop-attach-node-for-buildbox-3.

    Here's the F.A.Q. and Troubleshooting guide as visible in the node page.

    F.A.Q.
    Q. The attached object is always static or it disappears, why?

    A. it might be because the attach point is not a valid one or the object has been correctly attached to the attach point but is now hidden by the model mesh.
    For more information check "Attach Point" and "Alt. attach Point" in NODE ATTRIBUTES.

    TROUBLESHOOTING

    ERROR
    : Target Asset is null!
    REASON / SOLUTION: Make sure you've selected an asset in 'Target' attribute, usually this is the character you want to attach the prop to.

    ERROR
    : Target Asset "..." not found in current scene!
    REASON / SOLUTION:Make sure the 'Target' asset exists in current scene. For example: to attach a gun to your character's hand you have to make sure your character exists in current game scene.

    ERROR
    : Target Asset "..." does not contain a Sub Scene (FBX model)!
    REASON / SOLUTION:The 'Target' asset you've selected exists but does not contain a Sub Scene node.

    ERROR
    : Cannot attach "..." to attach point "..." of target asset "...", check its Sub Scene FBX model in Blender and make sure its skeleton (armature) contains the specified attach point (bone)!
    REASON / SOLUTION:The node wasn't able to attach the prop to the target asset; this usually happens when the attach point doesn't exist. For more information check "Attach Point" and "Alt. attach Point" in NODE ATTRIBUTES.

    ERROR
    : One or more errors occurred! The node won't work properly!
    REASON / SOLUTION:This is only shown when one or more error occur to signal that the node won't work properly.

    WARNING
    : Multiple Sub Scenes found in Target Asset "...", the one named "..." will be used!
    REASON / SOLUTION: The target asset contains multiple Sub Scene nodes (FBX models); in such a case the last one found will be used and the prop attached to it.
     
  20. Ivan Perfetti

    Ivan Perfetti Avid Boxer

    Joined:
    Sep 9, 2018
    Messages:
    203
    Likes Received:
    181

Share This Page