Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 RobertOne · Jul 05, 2017 at 12:31 PM · jointlimitsangular

must be fully assigned before control leaves the constructor

hey, iam writing a small joint angular limit script that looks like this:

 using System;
 using UnityEngine;
 
 namespace Physics
 {
     [Serializable]
     //public class JointAngularLimits : MonoBehaviour
 
     public struct JointAngularLimits : IPropertyBackingFieldCompatible, ICloneable, IPropertyBackingFieldCompatible<JointAngularLimits>, IEquatable<JointAngularLimits>
     {
         
         [SerializeField, PropertyBackingField]
         private float m_XMin;
 
         [PropertyBackingField, SerializeField]
         private float m_XMax;
 
         [SerializeField, PropertyBackingField]
         private float m_YMax;
 
         [SerializeField, PropertyBackingField]
         private float m_ZMax;
 
         public JointAngularLimits(float xMin, float xMax, float yMax, float zMax)
         {
             xMin = Mathf.Min(xMin, xMax);
             xMax = Mathf.Max(xMin, xMax);
             this.m_XMin = xMin;
             this.m_XMax = xMax;
             this.m_YMax = yMax;
             this.m_ZMax = zMax;
         }
 
         public JointAngularLimits(Joint joint)
         {
             if (joint == null)
             {
                 return;
             }
             if (joint is CharacterJoint)
             {
                 CharacterJoint characterJoint = joint as CharacterJoint;
                 this.m_XMin = characterJoint.lowTwistLimit.limit;
                 this.m_XMax = characterJoint.highTwistLimit.limit;
                 this.m_YMax = characterJoint.swing1Limit.limit;
                 this.m_ZMax = characterJoint.swing2Limit.limit;
             }
             else if (joint is ConfigurableJoint)
             {
                 ConfigurableJoint configurableJoint = joint as ConfigurableJoint;
                 this.m_XMin = configurableJoint.lowAngularXLimit.limit;
                 this.m_XMax = configurableJoint.highAngularXLimit.limit;
                 this.m_YMax = configurableJoint.angularYLimit.limit;
                 this.m_ZMax = configurableJoint.angularZLimit.limit;
             }
             else if (joint is HingeJoint)
             {
                 HingeJoint hingeJoint = joint as HingeJoint;
                 this.m_XMin = hingeJoint.limits.min;
                 this.m_XMax = hingeJoint.limits.max;
             }
         }
 
         public float XMax
         {
             get
             {
                 return this.m_XMax;
             }
             private set
             {
                 this.m_XMax = Mathf.Max(Mathf.Min(value, 180f), this.m_XMin);
             }
         }
 
         public float XMin
         {
             get
             {
                 return this.m_XMin;
             }
             private set
             {
                 this.m_XMin = Mathf.Min(Mathf.Max(value, -180f), this.m_XMax);
             }
         }
 
         public float YMax
         {
             get
             {
                 return this.m_YMax;
             }
             set
             {
                 this.m_YMax = Mathf.Clamp(value, 0f, 180f);
             }
         }
 
         public float ZMax
         {
             get
             {
                 return this.m_ZMax;
             }
             set
             {
                 this.m_ZMax = Mathf.Clamp(value, 0f, 180f);
             }
         }
 
         public void ApplyToJoint(Joint joint)
         {
             if (joint == null)
             {
                 return;
             }
             if (joint is CharacterJoint)
             {
                 CharacterJoint characterJoint = joint as CharacterJoint;
                 SoftJointLimit softJointLimit = characterJoint.lowTwistLimit;
                 softJointLimit.limit = this.XMin;
                 characterJoint.lowTwistLimit = softJointLimit;
                 softJointLimit = characterJoint.highTwistLimit;
                 softJointLimit.limit = this.XMax;
                 characterJoint.highTwistLimit = softJointLimit;
                 softJointLimit = characterJoint.swing1Limit;
                 softJointLimit.limit = this.YMax;
                 characterJoint.swing1Limit = softJointLimit;
                 softJointLimit = characterJoint.swing2Limit;
                 softJointLimit.limit = this.ZMax;
                 characterJoint.swing2Limit = softJointLimit;
             }
             else if (joint is ConfigurableJoint)
             {
                 ConfigurableJoint configurableJoint = joint as ConfigurableJoint;
                 SoftJointLimit softJointLimit2 = configurableJoint.lowAngularXLimit;
                 softJointLimit2.limit = this.m_XMin;
                 configurableJoint.lowAngularXLimit = softJointLimit2;
                 softJointLimit2 = configurableJoint.highAngularXLimit;
                 softJointLimit2.limit = this.m_XMax;
                 configurableJoint.highAngularXLimit = softJointLimit2;
                 softJointLimit2 = configurableJoint.angularYLimit;
                 softJointLimit2.limit = this.m_YMax;
                 configurableJoint.angularYLimit = softJointLimit2;
                 softJointLimit2 = configurableJoint.angularZLimit;
                 softJointLimit2.limit = this.m_ZMax;
                 configurableJoint.angularZLimit = softJointLimit2;
             }
             else if (joint is HingeJoint)
             {
                 HingeJoint hingeJoint = joint as HingeJoint;
                 JointLimits limits = hingeJoint.limits;
                 limits.min = this.m_XMin;
                 limits.max = this.m_XMax;
                 hingeJoint.limits = limits;
             }
         }
 
         public object Clone()
         {
             return this;
         }
 
         public override bool Equals(object obj)
         {
             return ObjectX.Equals<JointAngularLimits>(ref this, obj);
         }
 
         public bool Equals(JointAngularLimits other)
         {
             return this.GetHashCode() == other.GetHashCode();
         }
 
         public override int GetHashCode()
         {
             return ObjectX.GenerateHashCode(new int[]
             {
                 this.m_XMax.GetHashCode(),
                 this.m_XMin.GetHashCode(),
                 this.m_YMax.GetHashCode(),
                 this.m_ZMax.GetHashCode()
             });
         }
 
         public int GetSerializedPropertiesHash()
         {
             return this.GetHashCode();
         }
 
         public override string ToString()
         {
             return string.Format("[JointAngularLimits: XMin={0}, XMax={1}, YMax={2}, ZMax={3}]", new object[]
             {
                 this.m_XMin,
                 this.m_XMax,
                 this.m_YMax,
                 this.m_ZMax
             });
         }
 
     }
 }
 

but now iam getting these errors: JointAngularLimits.m_XMin' must be fully assigned before control leaves the constructor

JointAngularLimits.m_XMax' must be fully assigned before control leaves the constructor

JointAngularLimits.m_YMax' must be fully assigned before control leaves the constructor

JointAngularLimits.m_ZMax' must be fully assigned before control leaves the constructor

JointAngularLimits.m_XMin' must be fully assigned before control leaves the constructor

any idea why?

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
0
Best Answer

Answer by merkaba48 · Jul 05, 2017 at 12:43 PM

In all code paths in your constructors, be sure to assign those vars to a value even if you don't need to. At least, that's what I've had to do when encountering this error. I'm not sure why you have to in your case, as I thought floats automatically initialized to 0.

Try setting the variables to 0 where you declare them in the class body, if that doesn't work, try doing it at the beginning of the constructor with the if clauses, otherwise, I'm not sure.

Comment
Add comment · Show 1 · 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 RobertOne · Jul 05, 2017 at 01:11 PM 0
Share

thnaks, declare them before the if with just this.m_X$$anonymous$$in = 0; worked out :)

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

66 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 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

Hinge joint limits not working. 2 Answers

Hinge Joint Limits in C sharp 1 Answer

How to set a different linear limit for each axis on a configurable joint 0 Answers

Tie objects together 5 Answers

How do I see a Configurable Joint in the Scene Window? 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