Forum begins after the advertisement:


[Part 14] MissingReferenceException Transform

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 14] MissingReferenceException Transform

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #14561
    Alejandro Sierra Serrano
    Level 2
    Participant
    Helpful?
    Up
    0
    ::

    Every time a floating text pops up, this error appears. I wonder if its because its trying to access ‘rect’ variable after destroying the floating text.

    IEnumerator GenerarTextoFlotanteCoroutine(string text, Transform target, float duration = 1f, float speed = 1f)
        {
            GameObject floatingText = new GameObject("Texto Flotante"); 
            RectTransform rectTransform = floatingText.AddComponent<RectTransform>(); 
            TextMeshProUGUI tmPro = floatingText.AddComponent<TextMeshProUGUI>(); 
            tmPro.text = text;
            tmPro.horizontalAlignment = HorizontalAlignmentOptions.Center; 
            tmPro.verticalAlignment = VerticalAlignmentOptions.Middle; 
            tmPro.fontSize = fontSize; 
            if (fontFamily) tmPro.font = fontFamily; 
            rectTransform.position = camaraReferencia.WorldToScreenPoint(target.position); 
    
            Destroy(floatingText, duration); 
            floatingText.transform.SetParent(instancia.damageTextCanvas.transform); 
    
            WaitForEndOfFrame wait = new WaitForEndOfFrame(); 
            float time = 0;
            float yOffset = 0;
            while (time < duration) 
            {
                yield return wait;
                time += Time.deltaTime; 
                
                tmPro.color = new Color(tmPro.color.r, tmPro.color.g, tmPro.color.b, 1 - time / duration);
                
                yOffset += Time.deltaTime * speed; 
                rectTransform.position = camaraReferencia.WorldToScreenPoint(target.position + new Vector3(0, yOffset)); 
            }
        }
    #14562
    Alejandro Sierra Serrano
    Level 2
    Participant
    Helpful?
    Up
    0
    ::

    Also noticed that when the level up screen or results screen shows up, the text keeps over those.

    EDIT: I found the solution if anyone else is experiencing this issue:
    After setting the parent I added this line:

    floatingText.transform.SetAsFirstSibling();
    #14564
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Thanks for posting the solution here Alejandro. Sorry for missing your post!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: