Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Dismortus · Sep 23, 2013 at 08:09 PM · jointhingejointmotor

Store Joint Motor as temporary variable?

Hi all. I'm trying to access the motor properties of a hinge joint. I assign a variable to access the joint in the first place, but when I try joint.motor, i'm not allowed to change values. I want to be able to change the target velocity of the motor property at runtime.

 HingeJoint joint;
 
 void Awake()
 {
     joint.motor.targetVelocity = 10.0f;
 }

Is giving me error:

 Assets/example.cs(13,23): error CS1612: Cannot modify a value type return value of `UnityEngine.HingeJoint.motor'. Consider storing the value in a temporary variable
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
3
Best Answer

Answer by clunk47 · Sep 23, 2013 at 08:15 PM

First off, you need to define your joint variable in awake before you can access its properties, or you'll get a null reference exception at runtime. Unless you have this as a public HingeJoint that you can assign in the inspector. Then you need to use a JointMotor as that temporary variable for your motor property.

 using UnityEngine;
 using System.Collections;
 
 public class example : MonoBehaviour
 {
     HingeJoint joint;
     JointMotor motor;
     
     void Awake()
     {
         joint = GetComponent<HingeJoint>();
         motor = joint.motor;
         motor.targetVelocity = 10.0f;
     }
 }

There are plenty of good references from googling this: https://www.google.com/#q=unity+joint+motor

Comment
Add comment · Show 4 · 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 Dismortus · Sep 23, 2013 at 08:20 PM 0
Share

Well thanks for the answer, but not for telling me to google... I didn't know what to search for on google so yeah. Anyway thanks, the ANSWER part of this works for me :)

avatar image clunk47 · Sep 23, 2013 at 08:55 PM 1
Share

You say "I'm trying to access the motor properties of a hinge joint.", you also tag your question with "joint" and "motor". $$anonymous$$y google link is a perfect reference in this case. Google: Joint $$anonymous$$otor. $$anonymous$$akes sense no? Take suggestions on UA as advice, not as offensive remarks. I took the time to help you out with something you obviously needed help with. Every part of my ANSWER is my ANSWER. Glad I could be of help, happy developing~:)

avatar image Dismortus · Sep 23, 2013 at 09:37 PM 0
Share

Ok will do... Thx.

avatar image levis501 · Nov 28, 2014 at 11:07 PM 0
Share

I found that this code works in unity 4.6 only if you execute "joint.motor = motor;" after setting the motor's target velocity. Oh, and I got here by searching google for those exact terms :)

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

16 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

Related Questions

How can i change HingeJoint's axis from code? 0 Answers

Trying to use JointMotor, nothing happens 1 Answer

unity3d motorScript 0 Answers

Pushing a cart with a vehicle (Not generating initial torque) 0 Answers

HingeJoint Motor's values not being changed by script (show in debug, but not inspector) 1 Answer


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