Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by jake100 · Jan 03 at 03:53 AM · spriteimagerenderermaskinvisible

Sprites are invisible when passed between scenes

I am making discs that are circular double sided so you can read it both ways, the pictures will be taken from the gallery from the menu scene into the main scene. Currently when I try to pass an image into the next scene it's invisible.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Niantic.ARDK.AR;
 using Niantic.ARDK.Utilities;
 using Niantic.ARDK.AR.ARSessionEventArgs;
 using Niantic.ARDK.AR.HitTest;
 using UnityEngine.UI;
 using TMPro;
 public class Main : MonoBehaviour
 {
     public GameObject character;
     IARSession session;
     public Camera camera;
     public TMP_InputField inputField;
     public TextMesh tm;
     void Start()
     {
         ARSessionFactory.SessionInitialized += OnSessionInitialized;
         
     }
 
     private void OnSessionInitialized(AnyARSessionInitializedArgs args)
     {
         ARSessionFactory.SessionInitialized -= OnSessionInitialized;
 
         session = args.Session;
     }
     void Update()
     {
         if(PlatformAgnosticInput.touchCount <= 0) { return; }
         var touch = PlatformAgnosticInput.GetTouch(0);
         if(touch.phase == TouchPhase.Began)
         {
             TouchBegan(touch);
             
         }
 
     }
     private void TouchBegan(Touch touch)
     {
         var currentFrame = session.CurrentFrame;
         if(currentFrame == null)
         {
             return;
         }
         if(camera == null)
         {
             return;
         }
         var hitTestResults =
         currentFrame.HitTest
         (
             camera.pixelWidth,
             camera.pixelHeight,
             touch.position,
             ARHitTestResultType.ExistingPlaneUsingExtent |
             ARHitTestResultType.EstimatedHorizontalPlane
         );
         if(hitTestResults.Count == 0)
         {
             return;
         }
         //spawn ball into world
         GameObject ch = Instantiate(character, new Vector3(0, 0, 0), Quaternion.identity);
         //the 1st child is outer sphere
         GameObject ChildGameObject1 = ch.transform.GetChild (1).gameObject;//the 2nd is the 1st disc
 
         GameObject ChildGameObject2 = ch.transform.GetChild (2).gameObject;//the 3rd is the 2nd disc
         
         ch.transform.position = hitTestResults[0].WorldTransform.ToPosition();//starts by setting the postion 
         ch.transform.position = new Vector3(ch.transform.position.x, ch.transform.position.y + .9f, ch.transform.position.z);
         ch.GetComponent<Rigidbody>().velocity = Random.onUnitSphere * .5f; //shoots ball at random location
         //sets the discs to a custom sprite
         ChildGameObject1.GetComponent<SpriteRenderer>().sprite = GetComponent<ChangeSprite>().getSprite();
         ChildGameObject2.GetComponent<SpriteRenderer>().sprite = GetComponent<ChangeSprite>().getSprite();
 
 
 
 
         //takes string from the main menu
         ch.GetComponent<TextMesh>().text = PlayerPrefs.GetString("input");
 
          
     }
 
 }
 

this is the sprite picker class

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Picker : MonoBehaviour
 {
     public GameObject obj;
     public GameObject change;
     void Start()
     {
         
     }
 
     // Update is called once per frame
     void Update()
     {
              // if( NativeGallery.IsMediaPickerBusy() )
             //     return;
             //     PickImage( 512 );
     }
 public void PickImage( int maxSize )
 {
     NativeGallery.Permission permission = NativeGallery.GetImageFromGallery( ( path ) =>
     {
         Debug.Log( "Image path: " + path );
         if( path != null )
         {
             // Create Texture from selected image
             Texture2D texture = NativeGallery.LoadImageAtPath( path, maxSize );
             
             if( texture == null )
             {
                 Debug.Log( "Couldn't load texture from " + path );
                 return;
             }
             //obj.GetComponent<ImageGen>().Init(this.gameObject);
 
             GetComponent<ChangeSprite>().Init(GetComponent<SpriteRenderer>(), Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)));
             
             obj.GetComponent<SpriteRenderer>().sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
         }
     } );
 
     Debug.Log( "Permission result: " + permission );
 }
 }

this is the change sprite class

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ChangeSprite : MonoBehaviour
 {
     private static ChangeSprite instance;
     private SpriteRenderer rend;
     private Sprite sprite;
     void Start()
     {
         if(instance != null)
         {
             Destroy(this.gameObject);
             return;
         }
         instance = this;
         //stops object form deleting when changing scenes
         GameObject.DontDestroyOnLoad(this.gameObject);
         rend = GetComponent<SpriteRenderer>();
         rend.sprite = sprite;
         
     }
     public void Init(SpriteRenderer rend, Sprite sprite)
     {
         this.rend = rend;
         this.sprite = sprite;
     }
     public Sprite getSprite()
     {
         return sprite;
     }
 }



I think these are all of the relevant classes.

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 jake100 · Jan 03 at 05:58 AM

I fixed it, I don't know how but I fixed it.

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

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

207 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 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

Images/Sprites are invisible in scene view 0 Answers

Working on a character selection screen and trying to get a shader/mask over the characters for a locked look. Looking for help on the approach. 0 Answers

Programatically creating and setting UI image 0 Answers

How to place my own UI Image? 1 Answer

Get a single texture from multiply one (from atlas) 1 Answer


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