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
1
Question by Thomas-Hawk · Jun 18, 2018 at 11:27 PM · coroutineframeratecoroutinesenumbehaviour

Need opinions, or facts, about how to best go about programming this behavior. Basically Redstone.

So, in the most condensed way I can put it, here is what I need:

  • My player can place wires which each can be connected to eachother (with a linerenderer, visually).

  • Right now, each wire has its own little script containing its "are we powered" boolean and a little function to tell the other wires what their state should be - when they are placed, a "placer" script handles giving the wire, and its connections, cross-references to eachother at the moment they are placed, filling an array, they have a "refresh" function which loops through the list of connections to set their new state, and then tell them to refresh also (i prevent a loop/crash by only "refreshing" wires which needed changing)


-The player can use a "lever" item to give power to the wires, and to any number or connected wires arranged in any number of ways, like Redstone in minecraft


-Doing this with a lot of wires in a frame-based function causes severe framerate drop when there are a lot of wires, obviously


  • I understand that I need to use Coroutines to arrange the logic in a way that makes all the wires update relatively simulatenously in a way that will not slow the framerate


I implemented coroutines in a baseline successful way: I am using WaitForSeconds to wait just a moment before one wire updates the next wire.


-However, I am still pretty sure I am using them the wrong way. What is the best way to handle this situation? I have considered using BitArray to handle all of the wires within one script, just to give an idea of my needs here: I need the wires to update pretty instantaneously, but not so instant that it slows anything else about the game down. How to get one coroutine that handles all the wires in a way respective to their logic (i,e, "one wire can remember a connection to 6 other wires [currently doing this with an array of behaviours on each wire objects' script] and will push its current state to those wires [currently doing this with SendMessage on each individual referenced wire]")*


So far I've gotten the basic logic functional. I can place a lever, connect a wire from it to a lamp (or to another wire to another wire to a lamp) and I've also got a "signal inverter" working (like a redstone torch, it takes a signal and outputs the opposite, rather, stays on as a true state until it receives one) and the lever does successful transfer its state to its connected nodes. Just need a general idea of how to boil it down to one script / coroutine instead of one coroutine instance per wire. alt text

scree.png (478.7 kB)
Comment
Add comment · Show 2
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 NoDumbQuestion · Jun 19, 2018 at 01:33 AM 0
Share

Obviously you are thinking the wrong way and using "coroutine with new" express how inexperience you are with coding.

avatar image NoDumbQuestion · Jun 19, 2018 at 01:38 AM 0
Share

Here is how I would approach this problem. Of course you are gonna rework the entire thing.

  1. Power Supply -- I got power. I send power to any connect to me. (have Update() function)

  2. Station -- I got Line. I send power to anyone connect to me. (have function SendPower()). And have a List. When receive power in update --> Send power to connected Station. (If Station already powered -- do not send power anymore) (make overpowered station if you want)

  3. Line -- Connect between 2 station.

Hey I am crossing over another wire(line). I must connect to power to anyone connect to that Line too. (Only called CheckCrossOver() when place down)

Adding connected Station to the line crossing over.

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.

Follow this Question

Answers Answers and Comments

94 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

Related Questions

Example of co-routine for documentation 1 Answer

Using Time efficiently regardless of current frame rate. 0 Answers

Running a coroutine without StartCoroutine 1 Answer

StateMachineBehaviour + StartCoroutine() 2 Answers

How to wait for a co routine to finish when calling from a method 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