• 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
Question by HuntyBot · Jul 20, 2020 at 10:03 AM · buildtriggerbuild-errorissue

Onscreen button (touch) trigger event doesn't trigger properly on build

Hi! I've been trying to debug t$$anonymous$$s for 2 days now: I have an onscreen button w$$anonymous$$ch uses Unity's Event Trigger to call (Pointer Down) the player's jump function [OnJump()] and a device vibration [vibrateButton()] and then it also triggers a boolean inside the code. Here's the problem: it works fine in the editor, but in build it seems to only trigger the Jump function (vibration and boolean are not affected). I've used an on-build debugger console and got the following error when I try to trigger the button:


NullReferenceException: Object reference not set to an instance of an object Vibration.Vibrate (System.Int64 milliseconds) (at :0) Button_Vibrate.vibrateButton () (at :0) UnityEngine.Events.InvokableCall.Invoke () (at :0) UnityEngine.Events.UnityEvent`1[T0].Invoke (T0 arg0) (at :0) UnityEngine.EventSystems.EventTrigger.Execute (UnityEngine.EventSystems.EventTriggerType id, UnityEngine.EventSystems.BaseEventData eventData) (at :0) UnityEngine.EventSystems.EventTrigger.OnPointerDown (UnityEngine.EventSystems.PointerEventData eventData) (at :0) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerDownHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at :0) UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at :0) UnityEngine.EventSystems.EventSystem:Update()


I've been trying to track down the source of the problem, researched a lot on forums, tested and re-tested with many changes on builds, but can't seem to be able to fix it.

Here's all the code involved in the button trigger:


Setting the action in Awake for the boolean to trigger:

     void Awake()
     {
         jumpButton = GameObject.Find(jumpButtonName);
         EventTrigger jumpTrigger = jumpButton.GetComponent<EventTrigger>();
 
         EventTrigger.Entry jumpEntryDown = new EventTrigger.Entry();
         jumpEntryDown.eventID = EventTriggerType.PointerDown;
         jumpEntryDown.callback.AddListener((data) => { OnPointerDownDelegate((PointerEventData)data); });
         jumpTrigger.triggers.Add(jumpEntryDown);
 
         EventTrigger.Entry jumpEntryUp = new EventTrigger.Entry();
         jumpEntryUp.eventID = EventTriggerType.PointerUp;
         jumpEntryUp.callback.AddListener((data) => { OnPointerUpDelegate((PointerEventData)data); });
         jumpTrigger.triggers.Add(jumpEntryUp);
     }



Triggering the boolean when the button is pressed/released (does not trigger on build):

     public void OnPointerDownDelegate(PointerEventData data)
     {
         jumpIsHeld = true;
     }
 
     public void OnPointerUpDelegate(PointerEventData data)
     {
         jumpIsHeld = false;
     }



The jump function (w$$anonymous$$ch triggers fine on both the editor and build):

 public void OnJump()
 {
     if (hangCounter > 0f && !isJumping) //If the player is on the ground;
     {
         playerRB.velocity = Vector2.zero;
         playerRB.AddForce(new Vector2(playerRB.velocity.x, jumpStrength)); 
         isJumping = true;
     }
 }



And the the vibration script w$$anonymous$$ch also does not trigger on build:

 using UnityEngine;
 using System.Collections;
 
 public class Button_Vibrate : MonoBehaviour
 {
     public long vibrationDuration = 30;
 
     public void vibrateButton()
     {
             Vibration.Vibrate(vibrationDuration);
     }
 }

It is referencing a static class from another script ("Vibration").


So, yeah. When the button is pressed, the Jump() function is triggered normally in build, but the boolean jumpIsHeld and the function vibrateButton() are not. As I said, they all behave as intended in the editor.

I've been trying to figure t$$anonymous$$s out for a w$$anonymous$$le now and have come across some people with similar issues but I haven't come to a solution...

Does anyone know what might be happening?

Comment

People who like this

0 Show 5
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 frederikedel · Jul 20, 2020 at 11:24 AM 0
Share

Hmm, i actually had the same problem, what fixed it for me was searchig for using UnityEditor or Debug.Log Method,

avatar image HuntyBot frederikedel · Jul 20, 2020 at 11:43 AM 0
Share

Hey thanks for the response! Could elaborate a little more on how exactly you solved it? I'm not sure I understand it. The debug logs work fine for me in the editor, but then again not on build :\

avatar image frederikedel HuntyBot · Jul 20, 2020 at 12:50 PM 0
Share

Oh if forgot a part of the sentence :D I meant I removed them because you're doing actions in the Unity Editor, but when you have a build version the Unity Editor isn't there anymore, so it would resolve in an error (I think so). Example: You try giving a Debug.Log in the Unity Console, which works, but in a seperate programm ther is no unity console, so this cant work.

Show more comments
avatar image HuntyBot frederikedel · Jul 21, 2020 at 09:06 AM 0
Share

Confirmation: the Input System has nothing to do with it

0 Replies

· Add your reply
  • Sort: 

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Distribute terrain in zones 3 Answers

Discrepancies Between Build and Editor 0 Answers

Issues When Building the Game for any Platforms 1 Answer

Build error 1 Answer

Material/Shader issue 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