In my resources folder structure I have myself a file, now in the unity editor this file is a Texture Type Sprite (2D and UI), now when I attempt to run this code in one of my scripts
var icons = Resources.LoadAll<Sprite>("Images/BuffIcons");
My icons variable is empty, now if I change the line above to
var icons = Resources.LoadAll("Images/BuffIcons");
It comes back with an array which has a Texture2D and then multiple Sprite objects. Now why can't I cast the objects to a Sprite?
Also just for your information the Sprite (2D and UI) is a Multiple sprite so this sprite in total has like 42 different sprites. It seems to me the sprite which holds all the other sprites is classed as a Texture2D and then all the sprites inside of the Texture2D are Sprites. How can I just tell the Resources.LoadAll to load the sprites?
So this is a really silly answer however I'm not going to delete this question because around the web I have seen this question in a view places and all the answer's didn't work for me so. Here is my fix :D
Basically I have a Sprite (2D and UI) file in Assets/Resources/Images/BuffIcons, in my code I have this line
BuffIconSprites = Resources.LoadAll<Sprite>("Images/BuffIcons");
Basically all I had to do was simply close Unity and re-open it, it seems if you create the sprite asset which contains multiple sprites you need to close and reopen Unity, I think this is something to do with the solution file which is constantly updated when stuff changing in your Unity file.
P.S. as you can see the line of code I provided hasn't changed. So I'm 100% sure this problem is something to do with the Unity solution
Related
So, i've been trying to make a videogame on unity, and i made my first sprite on piskel. Exported it as PNG but can't seem to make it work on Unity. I imported it as a new sprite and even selected sprite (2D and user UI) on the menu.I selected 2D sprite but it doesn't work. It's just like if I put an image there, and not a sprite.It stays still I even tried using another sprite format More rows
I can't find anyone else with the same problem out there on the internet, so help would be much appreciated. Thank you.
Selecting 2D sprite isn't the full story. You will also need to make the sprite "multiple" instead of "single" and split it up in the editor (now available in the package manager).
That will split it up into frames for you, then you drag and drop a single frame.
https://docs.unity3d.com/Manual/SpriteEditor.html
I've been trying to fix this for quite some time now. All the solutions I find seem to be for sprite sheets. I am using tiles I downloaded from the asset store. They are not sliced up by unity but rather single pngs already separated in the asset folder.
When I combine them to platforms I sometimes get lines between the tiles where the background shows through. These lines are only visible while moving over the tiles.
I couldn't manage to screenshot it as of yet.
I have tried creating a material with Pixel snap on and assign it to my prefab but that didn't work. Even assigning the material to all the pieces of the prefab didn't work. The lines usually only show in between prefabs anyway.
Thank you very much!
I know I can use sprite packer to pack sprites so that there will be only one drawCall. If I slice a sprite sheet into multiple sprites, will it have the same effect? I experimented on my own, but there is no batching saved and I am afraid I did something wrong?
I used UI Image. And I used same material on them to hope batch them.
You may open the Frame Debugger to inspect whether your sprites are batched.
See also DrawCallBatching for more details on when and how draw-calls will be batched.
In Unity3d I found the feature of saving GameObjects through dragging them from the Hierarchy into the Assets Folder. I'm using this to test stuff in a different scene.
Strangely, I it doesn't work with this one properly:
after readding it, all meshes are missing:
Do you know how to fix this?
Is there a possibility to move gameObjects, maybe through code, from one scene to another one(in editor)?
It is possible to move GameObject from one scene to another by using DontDestroyOnLoad, if you need to do so in runtime.
I'm trying to do some Augmented Reality in Unity using the Vuforia plugin. I've managed to get everything working (I'm using a 3d model of a car), only the position of the car relative to the marker is wrong when I come to preview it (click the 'Play button at the top and watch through the computer's camera - is 'preview' the right name for this?).
It should be sitting on the the marker in the center, but instead it's floating above the marker and off to the side by quite a bit. The positioning is definitely right in the program itself, so I'm not sure why this isn't reflected in the preview.
Also: at the moment the car is simply an untextured grey object. I realise the textures are included in a subfolder, however I can't drag the entire car's folder (including the Textures subfolder) into the ImageTarget, only the .3ds file itself. Does anyone know how to apply the original textures to the car?
Thanks so much for your help in advance!
Ben
Well, to start answering your question about the drifting away part, you've probably got a Rigidbody attached to your Car? Well, if that's the case, then Go to the Inspector where the Rigidbody is and you'll see constraints.
To avoid it floating off, you might want to check Freeze Positions for whichever direction it needs. Probably Y axis.
Now, I'm not entirely sure if you're using Vector.AddForce to move your objects, but if you are then just check if your car can move if you've put all constraints on.
If you can't then in your code trying using Object.Rigidbody.SetActive(true) when you need it to start moving, and Object.Rigidbody.SetActive(false) when its done.
On the other hand, if you aren't using Vector.AddForce() then remove Rigidbody component if you've used it.
As for the material. If you've got the material in your folder that you've downloaded then just drag and drop it into Assets. Now sometimes your car may be one solid mesh, but some times it may be multiple meshes. So which ever the case. Drag the material from your Assets onto the Hierarchy panel over your car mesh/meshes and it should turn into that color.
Hope it helps. :)