Incorrect display of sprites when using Addressables - unity3d

The Addressables Package has been imported and configured in Unity 2019.4.16f. In the first two modes (see Fig. 1) the project works correctly.
But in a running project with Use Existing Build, the following problem occurs:
Objects created from prefabs with preset sprites on stage and in the game have different sprites. In this case, the correct link is set in the Image component, but the image is different.
Here's what I noticed:
If, in the running application, replace the sprite in the Image component with any other (or the same) one, then it will be displayed correctly (turning off / on Image does not give a result).
The problem affects only the preset Images in prefabs, which do not change during the execution of the application. And it looks like those sprites that are in Packages (or in atlases, I'm not sure) could not be reproduced with "custom" ones.
Prefabs are loaded into the preload scene using Addressables.
Then there is a change to the main stage. On it, objects are created from prefabs in the usual way (using Instantiate) they are created through a factory.
Please let me know if you encounter a similar problem. Would like to know if this is a bug in the package.

Related

Unity, Sprite textures don't load when pushed on github

I'm actually working on a Unity project and I'm using Github.
I decided to do again the menu of the game but when I switch computer to work again on the project I got some issues with it.
As you can see a big part of my Sprites and Fonts don't load. When i set back the menu by putting Sprite textures to Sprite (2D and UI) and adding the component it works well. But when I push the modification and pull to another computer, the same problem happen. The Sprites textures are back to default :
All the other sprites or prefab are working well so I don't understand.
Version : 2021.3.4f1
Make sure you are using VisibleMetaFiles in ProjectSettings -> Version Control -> Mode
Make sure that the metafile for the texture with issues is not corrupted and is under version control (it will be right near your texture with the same name and the .meta extension)
Check the history of this metafile to make sure that it is really pushed to the repo and then downloaded from there
Import settings for the texture are stored in this metafile, so you need to make sure that it shares correctly between two computers

How to recognize a multiple Vuforia AR targets in Unity without creating a separate object for each?

I'm trying to do a simple AR app using Unity and Vuforia.
I have a large number of AR targets in the Vuforia database, and my goal is that each of them be recognized by the AR camera and the target name was displayed on the screen (to understand which one was recognized).
I'm new to development in Unity, so now I've made only an application in which all the targets are located in one scene as ImageTargets and on top of them are the objects that are displayed when recognised. I want to increase the number of targets, but creating separate objects for all of them inside the scene looks wrong.
Is there a way to add a large number of targets to the scene without creating them all manually?
I think one game object per image target is the right way to do it. If you don't want to start with lots of complex objects in the scene, you can instantiate the targets' content dynamically using prefabs and tracking events instead of objects on top of them.
More details here: https://library.vuforia.com/articles/Solution/Working-with-Vuforia-and-Unity.html

Texture stuck on Black! Unity 5.6

I copied a project over from a different PC which had multiple scenes that needed to be baked.
The problem is in this one scene there are several different objects that textures seen to be stuck on black, even though I've changed the color of them. Some materials that where imported also seemed to be grayed out and I couldn't make any changes to them.
I'm not sure whether this is a baking issue or something to do with the material. I have tried to put the object on a different layer and used a real-time light and it does make it lighter but still nowhere near the color i set it too.
There are some textures/ Objects that are used in different scenes that seem to work fine but in this scene they don't...
None of the settings have been changed and it is the same version of unity on both PC's.
The issue:
What it is supposed to look like (from previous version):

Share same Navmesh with Duplicated Scenes

I had a Scene with a map (some buildings and roads) and Baked Navmesh, then I started Duplicating the Same Scene with modifying some objects inside (not the map or the world), so all the Scenes were sharing the same Navmesh somehow, then I deleted the Navmesh accidentally, Now the only way I seem to find is to create a new baked Navmesh for every Scene which will increase the build size too much!, How can I re-share the same baked Navmesh with all Scenes since all have the same map inside ? I am using Latest Unity3D.
Before You Start: if you have a lot of assets in your project changing serialization to Force Text may take a lot of time. So you may want to copy the target scenes to a new project, do the below mentioned steps and paste them back. :)
There is no way to do this from Unity editor, but there is a workaround:
Go to Edit > Project Settings > Editor and change the Asset Serialization to Force Text (default is Mixed) - this makes sure all assets, including your unity scene files are saved as text documents
Now open your scene file (the one with baked NavMesh) in any text editor
CMD+F or CTRL+F to focus on search bar and type "NavMeshSettings". In NavMeshSettings the last entree should be m_NavMeshData:{fileID:1234 //and some more stuff here} - this is reference to your baked NavMesh asset file. Copy the whole line
Now open the second scene that you want to share your NavMesh to (open in text editor again). Find exactly the same line starting with m_NavMeshData, delete it and past the line from the previous scene.
BOOM!
Edit/Tip: You may want to change serialization to Mixed again if you want to. The only downside of texted serialization is bigger files. It is mostly used for version controlling and merging and the scenes and stuff...

Is there a way to build asset bundle that exclude texture2d from an image?

In unity 4.x, I can archive this because I can select my resource type directly as Sprite variable before putting it into the bundle via BuildAssetBundle. However, in Unity 5.x, I need to put the name in the Editor can I cannot choose my resource type as Sprite only in the Editor. When I make the bundle, bundle will have both Texture2D and Sprite which I only want Sprite to save the memory and disk space. The bundle will exclude Texture2D only if I create the bundle from Prefab not the image itself but I want only the raw image. What should I do?
As clarification for future readers, I'm taking into account your other question, and that the reason you want to exclude the original texture is because you use the atlas that the Sprite Packer generates.
Short answer: Just don't add the textures in any bundle and let everything be taken care of in the shadows. For each bundle, any sprite or atlas needed will be referenced by the object that needs it, so they will be included.
Long, but insightful answer: First, let's compare the two AssetBundle buidling pipelines:
In Unity 4.X, to create an AssetBundle you chose the assets you wanted to bundle together. You would then call BuildPipeline.BuildAssetBundle, using the BuildAssetBundleOptions to optionally CollectDependencies or include the CompleteAssets.
In Unity 5.X, the old system is flagged as obsolete but still supported, though according to this post it might not be in the future. Adding to that, the new system will be further developed, so using the old one should be avoided.
The new pipeline is now integrated into the AssetImporter. Now, when building a bundle, the behaviour is that of having both CollectDependencies and CompleteAssets enabled in the old method.
Sprites are generated by the texture's import settings, and don't have any AssetImporter of their own. The texture atlases created by the Sprite Packer are cached in \Library\AtlasCache, so they don't have AssetImporters either.
This means that individual sprites and packed atlases can only be included in a bundle when they are dependencies of another included asset. As said by someone working on it.
If you add a texture to a pack, all the sprites it created will be added (this is the CompleteAssets behaviour), but of course this will add the texture itself too.
If a sprite is added, the texture it uses will be added too (CollectDependencies behaviour), regardless of if it's a texture file in the project or a Sprite Packer atlas.
The bottom line is that you don't want to add the texture. At all. Never. The original textures are for editor work only. Instead, you need to do add to the bundle anything else that references the sprites, but not the texture itself.
The hackiest way to do that is using a prefab with a script like this:
public class SpriteReferences : UnityEngine.MonoBehaviour {
public UnityEngine.Sprite[] sprites;
}
But chances are that among all the things you want to add to the bundle (prefabs, scenes, scriptableObjects) the sprites you need are already referenced, so they will be added, and in turn any needed atlas will be added too. And everything done without adding the original texture.
Beware: If a single object in an asset bundle references a sprite, its whole atlas will be added. Keep your packing tags organized, they should roughly correspond to the bundles you make.
This issue has been fixed by Unity in Patch 5.1.2p1. You don't need to do anything fancy at all. Unity will do it all for you. Just follow the simple build asset bundle step and that's it. :)