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
0
Question by oinkoinkflapflap · Sep 03, 2012 at 08:52 PM · functionsendmessageturretfreezingbuilder

game freeze problem

as said in the title, the game freezes, but only on the built game... after trying again and again to find where it's freezing, i see it's when two of the same type of turret shoot two of the same type of zombie, each type of zombie has a different script, the turret sends a message to the scripts.

here is a section from the turret script:

 function Fire () {
     if (target != null) {
     var dist : float = Vector3.Distance(target.position, turret.position);
     if(dist <= distance){
         target.SendMessage("CheapGun", gameObject);
     }
     }
 }

and here from one of the zombies:

 function CheapGun () {
     health -= CheapGunDam;
     var spawning = Instantiate(blood ,transform.position,Quaternion.identity);
 }
 
 function Death () {
     var death = Instantiate(ragdoll ,transform.position,Quaternion.identity);
     Destroy(gameObject);
     spawner.alive -= 1;
     Money.money += 10;
 }

some help would be really appreciated as i've finished the game and can't sell it with it freezing! if anyone knows a reason or something to try it'd be really appreciated!!! thanks

Comment
Add comment · Show 7
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 arkon · Sep 06, 2012 at 02:19 PM 0
Share

is it freezing in the editor or just on the target? What target is it freezing on?

avatar image jaskij · Sep 06, 2012 at 02:59 PM 0
Share

Try switching on the debug console in Unity, that might help some.

Also, I'm not too sure how exactly your code is structured, but destryoing the current object from inside is ALWAYS a bad idea, even if that's not the cause of your freezing.

avatar image oinkoinkflapflap · Sep 06, 2012 at 04:50 PM 0
Share

it's freezing in the built game never actually in the unity editor test - it seems it shoots when two off the same zombies are being shot by two of the same turret - two targets are being sent the same message to identical scripts from two identical scripts.

the console is on... i should have mentioned, i'm getting nullRefrenceExceptions, a missingRefrenceException to the shoot effect - as it goes un-active, and an unassignedRefrenceException and PPtr a cast not dereferencing. not sure, will these be reasons of freezing?

avatar image hvilela · Sep 06, 2012 at 04:55 PM 0
Share

missingRefrenceException means you're accessing an object that is not there anymore. If two turrets are killing the same zombie at same time, when the second shoots arrive the zombie object is destroyed already.

avatar image oinkoinkflapflap · Sep 06, 2012 at 05:10 PM 0
Share

there are two clone turret prefabs, and two clones of the same zombie prefab... will a missingRefrenceException be a reason for freezing?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by hvilela · Sep 06, 2012 at 04:14 PM

I don't know if it's what causing the freeze, but there's something wrong with you code. Take a look at the documentation and you will see that the second parameter of SetMessage is SendMessageOptions, but you're sending you're game object. This parameter are optional, so your options are:

 1 - target.SendMessage("CheapGun", SendMessageOptions.RequireReceiver);
 2 - target.SendMessage("CheapGun", SendMessageOptions.DontRequireReceiver);
 3 - target.SendMessage("CheapGun"); // Same as 1, cause RequireReceiver is the default value.

Also, in your Dead function you're changing the values of your game object AFTER destroying it. Try to invert it.

 function Death () {
     var death = Instantiate(ragdoll ,transform.position,Quaternion.identity);
     spawner.alive -= 1;
     Money.money += 10;
     Destroy(gameObject);
 }

Comment
Add comment · Show 3 · 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 by0log1c · Sep 06, 2012 at 04:33 PM 1
Share

Actually, Send$$anonymous$$essage has an overload that do take an object as parameter - and the receiving function can ignore it, so that's totally valid. As for the Destroy(), I've read somewhere that it will always yield until the method exit...or the frame ends, or something like that - I've never tested it, really - but I'm pretty sure that has nothing to do here. We don't have much of the Zombie script, I'm curious as to how Death() is called, etc...

avatar image oinkoinkflapflap · Sep 06, 2012 at 05:01 PM 0
Share

i'm currently working to putting these suggestions into all my scripts... will keep you updated but thanks!

the death function is called in the update function

if(health <= 0){ Death(); }

avatar image oinkoinkflapflap · Sep 07, 2012 at 05:48 PM 0
Share

i've changed all the parts you suggested hvilela but the game still freezes... :/

avatar image
0

Answer by oinkoinkflapflap · Sep 08, 2012 at 11:37 AM

i don't know what it was... but somehow i've fixed it! i went through removing NullRefrenceExceptions and other console errors kept trying it still wouldn't work but continued and just tried it... it worked! thank you all for your input!

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

10 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

Related Questions

built game freezing 1 Answer

How to call a function from another script in C# from array? 1 Answer

Raycast is being unreliable 1 Answer

My SendMessage is problematic [SOLVED] 1 Answer

How to activate a function (or equivalent) in a specific gameobject 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