hello,
Setup;
Gameobject ActiveCharacterInfo (ACI), which holds a “stat” storing script name CharacterInfo (CI). One of those stats is the character name
A UI Button calls a method in (CI) which instantiates a prefab InputField (NameChangeBox). the only extra script on that prefab is as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NameChangeFieldScript : MonoBehaviour
{
GameObject activeCharacter;
InputField nameInputField;
private void OnEnable()
{
nameInputField = gameObject.GetComponent<InputField>();
activeCharacter = GameObject.FindGameObjectWithTag("Player");
nameInputField.onEndEdit.AddListener(afterReturn);
}
private void afterReturn(string iName)
{
activeCharacter.GetComponent<CharacterInfo>().updateName(iName)
Destroy(gameObject.GetComponent<InputField>());
//Debug.Log(iName);
}
}
ctiveCharacter.GetComponent().updateName(iName) WORKS FINE, it deletes the old save and replaces it with a new one under a new character name.
Destroy(gameObject.GetComponent()); does not work. it also does not work when used as Destroy(nameInputField);
Both Destroy() methods ive tried seems to disable the input field component, as I cannot click on it anymore or input anything. It still on screen though, and still in the Hierarchy.
If I click the button again, it instantiates a new iField. I don’t know what to try form here. I did attempt to redefine everything as a plain Gameobject but that ran me into more issues. any advice would be awesome