I want to create a 2D object with a visual component. However, I don’t want it to have an underlying sprite. I’d rather have it just come from a material.
(For example, a red rectangle that has a material based on a shader that returns red for every pixel. It doesn’t have a sprite, because the material provides all the required visual information.)
To my knowledge, a material can simply be applied to a 3D object, but not a 2D object?
I am aware that this can be achieved with a ‘dummy’ sprite, with a custom material applied on top, but that seems like a bit of a hacky solution. It also leads to the sprite renderer complaining about the material not having a _MainTex texture property.
I apologise if this question has been asked before - I couldn’t find a solution.
Thank you very much for your help. Let me know if I need to clarify anything.
Actually, this is very simple, long as you’re fine with doing some work. Put a white square(or whatever shape you need) sprite in a SpriteRenderer on a game object, then go into the hierarchy, take the material, then just drag it to the gameObject.
To make sure it doesn’t yell about a missing variable, just make sure the material uses a shader with a variable with a reference to a “_MainTex” texture property.
And btw, you could literally just use a 3D object with a 2D collider if you absolutely need to.
And also, there is no such thing as “cheap” in game making, less you are doing some type of self inflicted challenge, in which case you have only yourself to blame.
Yourreply of "there are no “cheap ways to do stuff in GameDev” " was actually the best. Ive ben trying to make a 2D shape have a texture but i think i wil just use 3D primituves because i just wont have to go though the unnecessary hustle of figuring this out.
Id still like that it would be easier to apply materals just like with 3D objects tho.
Just for your information: Technically the GPU will see no difference
GPUs nowadays do not differentiate between 2D and 3D in terms of the underlying data structure (only in terms of projection settings aka camera used). That used to be different when the word “sprite” (which means “ghost”) was coined: An image that was ghosting in memory and could be copied into the output buffer any time with an offset to display something in 2D.
In Unity however a sprite even has a mesh and the SpriteRenderer is a wrapper around the same functionality which the MeshRenderer uses too.
This makes working with pure 2D a tad less intuitive but when you wanna do a 2.5D game or even have just a 3D effect via lights it saves a ton of hassle that sprites work seamlessly with almost all 3D features.