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 kaden1023 · Jan 26, 2020 at 06:36 PM · beginnerinventorydisappearfloating

Inventory problem: items disappear or float away...

I am making a game and I have an inventory where you press E in the trigger zone but for some reason first, almost every object in the area comes, then it either disappears completely or it just floats away through the floor, wall, or roof.this is my script: using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class PickUp : MonoBehaviour
 {
 public Transform theDestination;
     void OnTriggerStay()
     {
      if (Input.GetKeyDown(KeyCode.E))
     {
     GetComponent<Rigidbody>().useGravity = false;
     this.transform.position = theDestination.transform.position;
     this.transform.parent = GameObject.Find("Thedestination").transform;
     }
     void Update ()
     {
     if (Input.GetMouseButtonDown(1))
     {
     this.transform.parent = null;
     GetComponent<Rigidbody>().useGravity = true;
     }
 }}}

can anyone help/ tell me why it is happening? Thanks in advance,

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by austephner · Jan 31, 2020 at 04:37 AM

If the objects you're picking up all have this behaviour and they all happen to be calling OnTriggerStay (no matter what object is causing them to "trigger"), they will all perform the same action of changing their position to the theDestination.transform.position value. Likewise, when doing Input.GetMouseButton(1) all the objects that were just gathered to the destination point will lose their parent and receive gravity again.

You can fix this by ensuring that the object is triggering with the correct trigger-er.

 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject == <the-correct-object-you-want-to-check-for>)
     {
         DoPickupStuff();
     }
 }

I'm curious how you've set up the project though, as changing the layer collisions could potentially change my answer (and reasoning why things float through other things).

Also, what's the difference between public Transform theDestination and then calling GameObject.Find("Thedestination").transform? Are those two different objects that have the same-ish name? If you have a reference to the destination object why are you trying to find it again?

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
avatar image
0

Answer by kaden1023 · Feb 02, 2020 at 04:22 PM

@austephner I realized that I just forgot about the fact that I was going to use the public Transform and used gameobject.find instead... so that's the answer to one of the questions. But I can't work on it right now because unity kind of broke it's self so I have to fix it first

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.

Follow this Question

Answers Answers and Comments

132 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 avatar image avatar image

Related Questions

Adventure Game tutorial, Replacing models in the game world? 0 Answers

Pick up ability? And inventory? 1 Answer

Item/inventory system-equipable items 1 Answer

Hello, could I get some help with my inv system? 1 Answer

How to create collectiable documents or notes in my game 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