• 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.

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

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

How to reference a prefab to the script that doesn't exist in Hierarchy 0 Answers

Prefab Puzzle 1 Answer

Getting last sprite from prefab. 1 Answer

SetActive() not working 0 Answers

When building a game, are unused prefabs and scripts affected? 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