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 Gavrilakis · Aug 24, 2017 at 09:51 PM · generic list

Copy Generic List?

Hi, its the first time i'm posting here. I am using playmaker , but i just start using c# for simple things.

I have a free script i found that called "waypointNode", and uses a generic list that contains gameobjects( it says: public List <WaypointNode> neighbors;). Now i want from another script that i created to clear this list and i find out how to do it :

 waypoint = go.gameObject.GetComponent<WaypointNode> ();
 waypoint.neighbors.Clear(); 

But what i want is to clear this list and after a few seconds to get it back again. I think that i have first to copy this list to another, then clear the list and last copy the second list back to the first one.

I searching two days now for a solution in the forums, i have found same questions, but i cant find an answer that i can understand cause i am a beginner. Everything i try, i get errors. Please help because i'm really confused about this, and please consider that i am a beginner.

thanks.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TheSOULDev · Aug 24, 2017 at 10:43 PM

 public List <WaypointNode> neighbors;
 
 List<WaypointNode> CopyList(List<WaypointNode> listToCopy)
 {
     List<WaypointNode> newlist = new List<WaypointNode>();
     newlist = listToCopy;
     return newlist;
 }
 
 IEnumerator VanishAppear (List<WaypointNode> listToAlter, float delay)
 {
     List<WaypointNode> temp = CopyList(listToAlter);
     listToAlter.Clear();
     
     yield return new WaitForSecondsRealtime(delay);
     
     listToAlter = temp;
     
     yield return null;
 }

The way you'd call it in some script is:

 StartCoroutine(VanishAppear(neighbors, 1f));

Where you can replace 1f with any float depicting how many seconds you want to pass between deleting the list and recreating it.

Comment
Add comment · Show 2 · 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 Gavrilakis · Aug 25, 2017 at 01:46 AM 0
Share

TheSOULDev, thanks for your reply.

I check your code and i really try to understand it, search the manual, but i dont get it. Especially the first part. I make a mistake by telling that i want to clear the list for a few seconds. what i really want to do is to create a custom playmaker action that goes like this:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 namespace HutongGames.Play$$anonymous$$aker.Actions
 {
 [ActionCategory("$$anonymous$$")]
     public class WaypointClearAndRecreate : FsmStateAction
 {
         [RequiredField]
         public FsmOwnerDefault scriptOwner;//the owner of List <WaypointNode> neighbor
         WaypointNode waypoint;
 
         public List <WaypointNode> neighbors;
 
         public override void OnEnter()
     {
             GameObject go = Fsm.GetOwnerDefaultTarget(scriptOwner);
             waypoint = go.gameObject.GetComponent<WaypointNode> ();
 
             //maybe here the new list is created?
 
             waypoint.neighbors.Clear();
     }
 
         public override void OnExit()
         {
             
             //here i want to recreate the list
 
         }
 }
 
 }

I dont know how to use your code in my script. When i try to change it to fit my script, i get errors. It's the first time i try to work with lists so i dont get to much, and manual is hard to understand without certain examples.

Also, the neighbors list has only 4 elements, i dont know if this helps.

Thanks

avatar image TheSOULDev Gavrilakis · Aug 25, 2017 at 03:17 PM 0
Share

You didn't specify you needed it to be playmaker, which I don't even know what it is, why someone would use it, or how to use it. $$anonymous$$y chunk of code resides in some script, that you will either call from that script with the StartCoroutine, or you will define a reference to this script where you have defined "neighbor" and call it through StartCoroutine(scriptReferenceName.VanishAppear(neighbor, 1f)), but you also need to set VanishAppear to have public scope. There should be no errors, and implementation is literally copy paste with calling the routine where you want to call it from.

If you still don't understand how to use the complete method and IEnumerator I gave you, I suggest you learn C# because there's not a way I can give you an easier solution than this. If you don't understand the code, everything I used is in the unity documentation and .NET 2.0 guides if you want a generic explanation, all available on the internet for free. Also, both the Unity tutorial for lists and .NET documentation have more than enough examples to grasp the concept of lists.

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

68 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

Related Questions

4d generic list array? possible? is best solution? 0 Answers

Generic List In Custom Editor Window 2 Answers

Adding inherited class to list 1 Answer

Missing(GameObject) in Generic List (C# Unity3D) 0 Answers

generic list Take not working? 2 Answers


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