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 /
This question was closed Jan 22, 2019 at 01:42 AM by jiggish for the following reason:

reposting in a more general topic

avatar image
0
Question by jiggish · Jan 19, 2019 at 11:03 PM · listserializationlistsmonobehaviour

Start function on a listed non mono script?

I'm trying to create an editable list from the inspector, which calls on another list from another object. I am having a problem with the LearnableMoves function not being called, and i'm wondering why it's not running and how I could get around this.

public List<LearnableMoves> learnableMoves = new List<LearnableMoves>();

 [System.Serializable]
 public class LearnableMoves
 {
     private GameManager gm;
     private GameObject gameManager;
     public int LearnedLevel;
     public int MoveSelectionCaller;
     private string MoveSelectionCallerT;
     public PokemonMoves pokemonmove;
     public string pokemonmovename;
     public int pp;
     public LearnableMoves(){
         gameManager = GameObject.FindGameObjectWithTag ("GameManager");
         gm = gameManager.GetComponent<GameManager>();
         pokemonmove = gm.allMoves [1];
         pokemonmovename = pokemonmove.Name;
         pp = pokemonmove.PP;
     }
 }
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

  • Sort: 
avatar image
0

Answer by ray2yar · Jan 21, 2019 at 01:56 PM

It looks like your "learnablemoves" is setup to initialize a custom class. So it would only be called when you write something like this elsewhere:

 LearnableMoves MyMoves = new LearnableMoves();

That said, I think you should pass your class some information rather than assume it all... maybe like this:

 public LearnableMoves(int level, int select, PokemonMoves moves, string name, int p)
 {
 
         //assign all these passed variables to your public declarations
 
 }

If you switched to this then in your other script when you initialize the class you'd write something like this:

 LearnableMoves MyMoves = new LearnableMoves(5, 1, //pokeman moves?, "pikachu", 3);
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 jiggish · Jan 22, 2019 at 05:59 AM

@ray2yar this is my first time using the forums, so idk if I have done everything correctly, but I do use the LearnableMoves at the beginning of the script in a list, which I have to keep. The problem is this script is copied multiple times so I have to keep it ambiguous, and I can't create all the different MyMoves methods. I realize I forgot to mention this, but allMoves is another list that I have already defined under another game object, and that's where most of my problem is. I'm trying to call on the list created there, and I can't find out how to, as I can't make this script mono or it won't let me edit the variables from the inspector, and I can't find any way to run a function from this script. Thank you for your help though, and I will attach the full script , as well as the other list it calls on below.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.UI;
 
 public class BasePokemon : MonoBehaviour {
 
     public string PName;
     public Sprite image;
     public BiomeList biomeFound;
     public PokemonType type;
     public Rarity rarity;
     public int HP;
     private int maxHP;
     public Stat AttackStat;
     public Stat DefenceStat;
 
     public List<LearnableMoves> learnableMoves = new List<LearnableMoves>();
 
     public PokemonStats pokemonStats;
 
     public bool canEvolve;
     public PokemonEvolution evolveTo;
 
     private int level;
 
     void Start () {
         maxHP = HP;
     }
     void Update () {
     
     }
 
     public void AddMember(BasePokemon bp)
     {
         this.PName = bp.PName;
         this.image = bp.image;
         this.biomeFound = bp.biomeFound;
         this.type = bp.type;
         this.rarity = bp.rarity;
         this.HP = bp.HP;
         this.maxHP = bp.maxHP;
         this.AttackStat = bp.AttackStat;
         this.DefenceStat = bp.DefenceStat;
         this.pokemonStats = bp.pokemonStats;
         this.canEvolve = bp.canEvolve;
         this.evolveTo = bp.evolveTo;
         this.level = bp.level;
     }
 }
 
 public enum Rarity
 {
     VeryCommon,
     Common,
     SemiRare,
     Rare,
     VeryRare
 }
 
 public enum PokemonType
 {
     //removed to meet character limit, just a list of types
 }
 
 [System.Serializable]
 public class PokemonEvolution
 {
     public BasePokemon nextEvolution;
     public int levelUpLevel;
 }
 
 [System.Serializable]
 public class PokemonStats
 {
     public int AttackStat;
     public int DefenceStat;
     public int SpeedStat;
     public int SpAttackStat;
     public int SpDefenceStat;
     public int EvasionStat;
 }
 
 [System.Serializable]
 public class LearnableMoves
 {
     private GameManager gm;
     private GameObject gameManager;
     public int LearnedLevel;
     public int MoveSelectionCaller;
     public PokemonMoves pokemonmove;
     public LearnableMoves(){
         gameManager = GameObject.FindGameObjectWithTag ("GameManager");
         gm = gameManager.GetComponent<GameManager>();
         pokemonmove = gm.allMoves [MoveSelectionCaller];
     }
 }
     public List<PokemonMoves> allMoves = new List<PokemonMoves>();
 [System.Serializable]
 public class PokemonMoves
 {
     public string Name;
     public MoveType category;
     public Stat moveStat;
     public PokemonType moveType;
     public int PP;
     public float power;
     public float accuracy;
 }






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 jiggish · Jan 21, 2019 at 11:54 PM 0
Share

the list and everything thereafter is on a separate script

avatar image ray2yar · Jan 22, 2019 at 10:33 AM 0
Share

As far as I can see, even in that script you never initialize your learnablemoves. To add to the list you would have to do something like this:

 Learnable$$anonymous$$oves AName = new Learnable$$anonymous$$oves(**pass variables**);
 learnable$$anonymous$$oves.Add(AName);
avatar image jiggish ray2yar · Jan 22, 2019 at 11:05 PM 0
Share

It's added in the inspector. I was able to solve the problem here, I realize I was asking too broad a question. What I'm looking for was a way to call a function within the Learnable$$anonymous$$oves, and I was having trouble with using FindGameObjectWithTag before serialization.

Follow this Question

Answers Answers and Comments

106 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

Related Questions

Creating a list of singletons? 1 Answer

A node in a childnode? 1 Answer

List of custom classes in MonoBehaviour's Data gets lost after Re-Opening Unity!!! 0 Answers

Accessing a MonoBehaviour List within a Non-MonoBehaviour Script 2 Answers

How can I set the properties of serialised fields on an object recusively? 0 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