typemask and type are null
what I'm trying to do is avoid having to push a button and allowing this info to pass on start instead, the button works and passes the selected type but in the start function it is null, ive tried multiple ways and its always null I have a suspicion but cant find any info on it, that its because one derives from monobehavior? is there a simple way to make this function work?
using UnityEngine;
namespace CharacterEditor
{
public class characterLo : TextureTypeMaskSelector
{
public int which;
public characterLo instance;
protected override void OnClick()
{
TextureManager.Instance.OnNextColor2(which,types); //types work here
}
void Start()
{
instance = this;
instance.types = types; // ?
Debug.Log ("whats going on");
Debug.Log (instance.typeMask);
if(Application.loadedLevelName != "CharacterCreation"){
string SaveLoadSlot = PlayerPrefs.GetInt ("Player_SaveLoad_Slot").ToString();
instance.which = PlayerPrefs.GetInt (SaveLoadSlot + instance.typeMask.ToString() + "Color",1);
TextureManager.Instance.OnNextColor2(instance.which, instance.types);
//doesnt work as "types" or "instance.types" >>>>returns null<<<<
}
}
}
}
Here is texturetypemaskselector
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace CharacterEditor
{
public abstract class TextureType$$anonymous$$askSelector : $$anonymous$$onoBehaviour, IPointerClickHandler
{
[EnumFlag] public TextureType type$$anonymous$$ask;
protected TextureType[] types;
[EnumFlag] public TextureType clearType$$anonymous$$ask;
protected TextureType[] clearTypes;
private Button button;
protected abstract void OnClick();
public virtual void Start()
{
button = GetComponent<Button>();
List<TextureType> list = new List<TextureType>();
foreach (var enumValue in System.Enum.GetValues(typeof(TextureType)))
{
int checkBit = (int) type$$anonymous$$ask & (int) enumValue;
if (checkBit != 0)
list.Add((TextureType) enumValue);
}
types = list.ToArray();
list.Clear();
foreach (var enumValue in System.Enum.GetValues(typeof(TextureType)))
{
int checkBit = (int) clearType$$anonymous$$ask & (int) enumValue;
if (checkBit != 0)
list.Add((TextureType) enumValue);
}
clearTypes = list.ToArray();
Config$$anonymous$$anager.Instance.OnChangeCharacter += DisableActionBtns;
}
private void DisableActionBtns(object sender, EventArgs e)
{
var interactable = false;
foreach (var type in types)
{
if (Array.IndexOf(Config$$anonymous$$anager.Instance.Config.availableTextures, type) != -1)
{
interactable = true;
break;
}
}
button.interactable = interactable;
}
public void OnPointerClick(PointerEventData eventData)
{
if (!button.interactable)
return;
OnClick();
}
}
}
Answer by Bunny83 · Mar 02, 2018 at 06:27 PM
You did not override the virtual Start method in your derived class and you did not call base.Start() in your derived method. That means the code in Start in your abstract base class is never executed.
honestly I'm confused, it is assigned in inspector as skin, but when I build a start function using unityengine, does that make it separate, as far as textortypemaskselector is concerned? because I can click that button and types is working but start types is null, so is types not initialized versus executed? sorry if I'm misunderstanding I know what I want to achieve but the path there is more advanced then me for sure lol
void Start()
{
base.Start ();
instance = this;
instance.types = types; // ?
Debug.Log ("whats going on");
Debug.Log (instance.type$$anonymous$$ask);
if(Application.loadedLevelName != "CharacterCreation"){
string SaveLoadSlot = PlayerPrefs.GetInt ("Player_SaveLoad_Slot").ToString();
instance.which = PlayerPrefs.GetInt (SaveLoadSlot + instance.type$$anonymous$$ask.ToString() + "Color",1);
Texture$$anonymous$$anager.Instance.OnNextColor2(instance.which, instance.types);
//doesnt work as "types" or "instance.types" >>>>returns null<<<<
}
}
this actually worked perfectly, passed the info and changed the color, thanks kindly!!
Your answer
Follow this Question
Related Questions
Using GetComponent without knowing the script name? 1 Answer
NullReferenceException: Object reference not set to an instance of an object in Singleton class. 1 Answer
Help in conversion of variable types c# 1 Answer
http://answers.unity3d.com/questions/8472/help-with-error-expression-denotes-a-type-where-a.html 1 Answer
String variable declared in editor goes blank at runtime 0 Answers