Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Caolan · Jan 27, 2016 at 02:39 PM · physicseditorasset storejointeditor extension

How to assign a joint's 'connected body'?

I have a lot of objects in my scene that need to be connected together using joints, I was wondering if anyone has come across an easier way to assign a joint's connected body than by dragging and dropping each individual object to each individual joint in the inspector?

It would be really handy if, for instance: Unity could assign a joint's connected body to any object that is intersecting with that joint's parent object in the scene view.

Has anybody come across anything like this?

Or would anyone even know the best way to go about assigning hundreds of unique objects to hundreds of separate joints efficiently?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by FortisVenaliter · Jan 27, 2016 at 02:50 PM

No, there's nothing built in like that that I know of, but it wouldn't be hard to write a script to do so. Just make sure you enable "ExecuteInEditMode" on the script, and have it search for all objects with a specific name or tag, then compare their positions to other objects and link it all up dynamically.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Caolan · Jan 28, 2016 at 01:24 AM 0
Share

Wow nice one! I didn't realize it was possible to run scripts outside of play mode!

Would you be able to point me in the right direction for learning how to do this? I understand what your saying, in theory, it's just I can't seem to figure out the right syntax or logic something. The Unity documentation on "ExecuteInPlay$$anonymous$$ode" doesn't seem to tell me a lot about how to write scripts that will run outside of play mode. Would you know of anywhere where I could find more information on this?

I have written the following script, and it works in playmode, it assigns a rigidbody on game object (a) to a fixed joint on game object (b) when the two collide:

 using UnityEngine;
 using System.Collections;
 
 [ExecuteInEdit$$anonymous$$ode]
 public class ConnectedBodyAuto : $$anonymous$$onoBehaviour {
 
     private FixedJoint BlazeIt;
     private Rigidbody targetJoint;
 
 
     // Use this for initialization
 /*    void Start () {
 
         BlazeIt = gameObject.GetComponent<FixedJoint>();
     
     }*/
     
     // Update is called once per frame
     void Update () {
 
         BlazeIt = gameObject.GetComponent<FixedJoint>();
     
     }
 
     void OnCollisionEnter (Collision col)
     {
         if(col.gameObject.name == "Cube")
         {
             Debug.Log ("hit!");
             targetJoint = col.rigidbody;
             Debug.Log (targetJoint);
             BlazeIt.connectedBody = targetJoint;
             Debug.Log (BlazeIt.connectedBody);
 
         }
     }
 }
 //when something collides with this cube, put that object in the connected body variable of the fixed joint


But when I stuck [ExecuteInEdit$$anonymous$$ode] on the script like so, it gives me no errors, but doesn't seem to do much either. Do collisions register outside of play mode? Am I going about this totally wrong?

avatar image FortisVenaliter Caolan · Jan 28, 2016 at 03:50 PM 0
Share

Collisions do not register in edit mode. You're going to need to take a distance-based approach.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

45 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can you get a visualization of joint limits in the editor as you set them up? 0 Answers

Finding a GameObject in an editor script based on position 2 Answers

Can I transfer my Unity Free License including all purchased Editor extensions to a new Computer? 1 Answer

Using a ConfigurableJoint to move an object to a postion and rotation. 0 Answers

combine Spring + Hinge in one ConfigurableJoint 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges