• 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 /
  • Help Room /
avatar image
0
Question by Scourmya · Jul 16, 2019 at 05:13 PM · script error

SpringJoint2D Cannot be referenced properly

So I was trying to make my joint, and when the player stops holding with his mouse, a projectile would be fired from the sling. and i get this problem when releasing the projectile from the sling :

 NullReferenceException: Object reference not set to an instance of an object
 SlingBackController.ShootProjectile ()

as if i haven't referenced anything for my breakforce to do but i did from this script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class SlingBackController : MonoBehaviour
 {
     public float MaxDistance = 5f;
     public Transform MiddlePosition; 
     private static SlingBackController _instance;
     private SpringJoint2D CurrentSpringJoint;
 
     public static SlingBackController Instance
     {
         get
         {
             if (_instance == null)
             {
                 var obj = GameObject.FindGameObjectWithTag("SlingBack");
                 if (obj != null)
                 {
                     _instance = obj.GetComponent<SlingBackController>();
                 }
             }
             return _instance;
         }
         set
         {
             _instance = value;
         }
     }
 
 
     // Start is called before the first frame update
     void Awake()
     {
         Instance = this;  
     }
 
     void start()
     {
         CurrentSpringJoint = GetComponent<SpringJoint2D>();
     }
 
     // Update is called once per frame
     void Update()
     {
         
     }
 
     public void ShootProjectile()
     {
         CurrentSpringJoint.breakForce = 1f;
         CurrentSpringJoint = null;
     }
 }
 

the spring was clearly referenced and shown as a SpringJoint2D, and it still doesn't break when player releases the projectile through my script, the problem is pointing to the ShootProjectile() problem, Can anyone please help?

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

Answer by Dragate · Jul 16, 2019 at 05:17 PM

Start() function does not get called because you forgot to capitalize the "s".

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

transformers script error 1 Answer

After converting c# Script, Unity is giving errors on multiple lines which were fine before. 0 Answers

Simple script error 1 Answer

Dont destroy object when changing scene 1 Answer

Unity 5 checking if player isGrounded 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges