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 antotecnho · Mar 08, 2019 at 09:49 PM · prefabscript.

I have a problem whit a script and prefabs

went i create a prefab the scrip assign in that prefab disappear event went i click applied a hundred time

  • before its a prefab

alt text

  • went it become a prefab

alt text

  • and after deleting and recreating sometime a message appear in the output saying Cyclic nesting detected

before.png (74.1 kB)
after.png (75.6 kB)
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 silvematt · Mar 08, 2019 at 10:35 PM

Prefabs are assets meant to use in the same way in every scene possible. Because of that, you can't assign a reference of a GameObject in a particular scene.

The only thing you can do to keep those references in the prefab is to make the gameObject that has 'Score' and 'BallMovement' as child of Bumper, but that's not too smart in this case.

Another workaround (that can be the best) is to use the 'Score' and 'BallMovement' as a Singleton and at the start of the BumperScript you get those references.

Last one, go with tags. Tag the Score gameObject with the tag 'Score' and with a simple

 void Start() 
 {
 Score = GameObject.FindWithTag("Score");
 }


But i really suggest you to use the Singleton pattern.

Have a great dev-time!

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 antotecnho · Mar 09, 2019 at 03:43 AM

Thanks but its doesn't work because "Score" and "BallMovement" are script I reference the scripts because i want to read or change variable in those other script

here the bumper script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BumperScript : MonoBehaviour
 {
     public Animator animator;
     public Score score;
     public BallMovement BallMovement;
 
     public int Bumper_State = 0;
     public float CooldownTime = 60;
 
     private float TimeLeft;
 
     void Start()
     {
 
         TimeLeft = CooldownTime;
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
         animator.SetInteger("Bumper_State", Bumper_State);
 
         if (Bumper_State == 0 & TimeLeft > 0)
         {
 
             score.AddPoints(1);
             TimeLeft = CooldownTime;
 
         }
         else
         {
 
             TimeLeft--;
 
         }
 
     }
 
     void OnCollisionEnter2D(Collision2D collision)
     {
         if (BallMovement.GameStart == true)
         {
             Bumper_State++;
         }
     }
 
 }
 

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

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

Related Questions

Trying to have my Editor Script save the changed settings when I hit Play 0 Answers

How come I cannot set my prefab game component into a script public variable? 1 Answer

Unity project referencing another Unity project? 0 Answers

How can i add all the prefabs in the assets directory and sub directories to List or Array ? 0 Answers

Bullet Prefab spawning in multiple random positions and rarely the correct one (Unity 3D) 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