• Unity3D - Discussion
    5,004 replies, posted
So I've figured out something that should have been obvious from the beginning of working with Unity; Occlusion Culling doesn't work in Unity Free. There are, however, a number of plugins exist in the Unity store for such a thing. Does anyone have any recommendations?
snip
I'm currently having a lot of problem getting the text font in Unity 4.6 to show up crisp and not blurred. I've tried setting the font size bigger on the font, but despite that, it still isn't crisp. [thumb]http://files.atrblizzard.com/sharex/2014-09-24_23-19-36.jpg[/thumb] Does anyone know a possible solution? Canvas is also set to pixel perfect.
[QUOTE=atrblizzard;46067297]I'm currently having a lot of problem getting the text font in Unity 4.6 to show up crisp and not blurred. I've tried setting the font size bigger on the font, but despite that, it still isn't crisp. [thumb]http://files.atrblizzard.com/sharex/2014-09-24_23-19-36.jpg[/thumb] Does anyone know a possible solution? Canvas is also set to pixel perfect.[/QUOTE] I've had a lot of trouble with text; the only thing that I've found to work is scaling the text UI down to something like 0.1 X and Y, increasing the width and height of the transform rect to something that looks reasonable, and then making the font size waaay bigger (I've used > 100 recently). Generally a small font size will make the font go all blurry, so even if you scale it down, a large font size will be very crisp (though I have had some problems with AA doing it like this).
[QUOTE=Maloof?;46063463]So I've been going through a beginners tutorial for C# and Unity, and I've been supplementing it with little challenges of my own. For this tutorial, we're creating a player moving at a constant speed, with a queue-based backdrop made up of cubes that recycles once each cube is a set distance behind the player. I thought I'd try and make it more interesting by having each backdrop cube fade out before vanishing, but several hours later and I still can't get the change in alpha to have a visible effect, even though my print() statements show the math is working. Any ideas? The skyline manager instantiates the prefab cube, and the FadeOut script is a component of the prefab cube. [code] using UnityEngine; using System.Collections.Generic; public class SkylineManager : MonoBehaviour { public Transform prefab; public int numberOfObjects; public Vector3 startPosition; public Material prefabmat; private Vector3 nextPosition; private Queue<Transform> objectQueue; private float recycleOffset; private FadeOut fadeOut; void Start () { objectQueue = new Queue<Transform>(numberOfObjects); nextPosition = startPosition; recycleOffset = numberOfObjects/2; for (int i = 0; i < numberOfObjects; i++) { Transform o = (Transform)Instantiate(prefab); o.localPosition = nextPosition; nextPosition.x += o.localScale.x; objectQueue.Enqueue(o); } } void Update () { if (objectQueue.Peek().localPosition.x + recycleOffset < Runner.distanceTraveled) { Transform o = objectQueue.Peek(); fadeOut = o.GetComponent<FadeOut>(); fadeOut.enabled = true; //o.transform.localPosition = nextPosition; //nextPosition.x += o.localScale.x; //objectQueue.Enqueue(o); } } }[/code] [code] using UnityEngine; using System.Collections; public class FadeOut : MonoBehaviour { public Material material; float matA; float mattest; // Use this for initialization public void Start () { enabled = false; //mattest = gameObject.renderer.material.color.a; Material mat = (Material)Instantiate(material); matA = mat.color.a; } void Update() { //matA = Mathf.Max (matA -= 0.05f, 0f); // matA = 255f; // // if (matA == 0f) // { // enabled = false; // } // print (matA); // print (this.enabled); mattest = Mathf.Max (mattest -= 0.05f, 0f); //gameObject.renderer.material.SetColor("_color", Color(1, 2, 3)); if (mattest == 0f) { enabled = false; } print (mattest); print (this.enabled); } } [/code][/QUOTE] I see you creating a material but I don't see you applying it to anything. [editline]24th September 2014[/editline] Something like this maybe? [code] public class FadeOut : MonoBehaviour { Color matColor; float matAlpha; // Use this for initialization public void Start() { enabled = false; matColor = renderer.material.color; matAlpha = matColor.a; } void Update() { matAlpha = Mathf.Max( matAlpha - 0.05f, 0f ); matColor.a = matAlpha; renderer.material.color = matColor; if ( matAlpha == 0f ) { enabled = false; } print( matAlpha ); print( this.enabled ); } } [/code]
[QUOTE=foszor;46068532]I see you creating a material but I don't see you applying it to anything.[/QUOTE] I was assigning the material (to public Material material) in the inspector - is that not enough? I think I'm probably misunderstanding some logic around how Unity and C# does stuff
You apply the material to the object, creating a public field just allows you to assign a value in the component. I updated my previous post with some code that might help. [editline]24th September 2014[/editline] By the way, all the MonoBehaviour events like Start, Update, FixedUpdate, etc are all private methods in the class; you shouldn't override them as public. They're called in specific order by the engine and you shouldn't call them manually. It's also wise to keep as many of your custom methods private unless you need to access them from another component (and choose not to use SendMessage)
[QUOTE=foszor;46068585]You apply the material to the object, creating a public field just allows you to assign a value in the component. I updated my previous post with some code that might help.[/QUOTE] Woah awesome, cheers. I'm seeing some effects in the game view now. So when I create a float variable and assign the value to the value of the material, I'm only reading that value, and anything I do to that float variable won't make any changes to the material [I]until[/I] I explicitly assign the float variable to the value of the material, right? I also found that if I did [code]renderer.material.color.a = matAlpha;[/code] it threw an exception, and only worked when, as you did, I created a Color variable and went [code]matColor.a = matAlpha;[/code]. Is it always required that you create a variable to put you one level away from the variable (in this case, alpha) that you want to change? So we're using matColor to put us in the Color class of the material, from which we can access the alpha variable. Sorry if these questions are super noob, it's been a couple of years since I've done any coding.
[QUOTE=Maloof?;46068683]Woah awesome, cheers. I'm seeing some effects in the game view now. So when I create a float variable and assign the value to the value of the material, I'm only reading that value, and anything I do to that float variable won't make any changes to the material [I]until[/I] I explicitly assign the float variable to the value of the material, right?[/quote] That is correct. [QUOTE=Maloof?;46068683]I also found that if I did [code]renderer.material.color.a = matAlpha;[/code] it threw an exception, and only worked when, as you did, I created a Color variable and went [code]matColor.a = matAlpha;[/code]. Is it always required that you create a variable to put you one level away from the variable (in this case, alpha) that you want to change? So we're using matColor to put us in the Color class of the material, from which we can access the alpha variable. Sorry if these questions are super noob, it's been a couple of years since I've done any coding.[/QUOTE] Many values of different types are properties and cannot be assigned individually. The material color is an example, which is why you need to keep a reference to a Color value and update the alpha before applying it. Not everything is like that; there are other that allow you to use methods such as SetColor or something similar to change property values. You'll find out which is which as you move along through your coding experience.
I guess in principle we could use matColor.a instead of matAlpha in those calculations, and that would save us from having to manually update it, but then it would be constantly switching the [I]real[/I] value of our material's color.a with every alteration the code made to that value, instead of once per frame as it does when we manually set it, is that right?
OK, so as far as this: [code] renderer.material.color.a = bla; [/code] Throwing an error... This goes back to what I was talking about, [B]properties[/B]. In Flash AS3, this is a property: [code] public function get yourPropertyName() : int { return someIntegerValue; } public function set yourPropertyName( value : int ) { // do something with value, generally you store it in a private variable } [/code] Now, you can access this as if it were a variable, like so: [code] var someVar = yourPropertyName; yourPropertyName = someVar + 1; [/code] The first line internally calls the get method, and the second one internally calls the set method. Now, in C#, these are implemented like so: [code] public int yourPropertyName { get { return someIntegerValue; } set { // 'value' contains the value which is assigned, so you might do something like: // someIntegerValue = value; } } [/code] And can be accessed, like I mentioned, as if they were a variable. Now, here's the thing. Let's say I've got a Vector3 property 'position': [code] public Vector3 position { get { // bla } set { // bla } } [/code] And I try to do this: [code] position.x += whatever; [/code] This will blow up in my face and throw a compiler error. You CANNOT modify individual fields of a [I]property which contains a value type such as a struct - which Vector3 is[/I]. You MUST get the value, modify the field, and then assign it back. Just about every field of built-in Unity classes are implemented as properties. So for instance, the [I]color [/I]field of material is a Color property - Color being a value type.
[QUOTE=KillaMaaki;46068747]OK, so as far as this: This will blow up in my face and throw a compiler error. You CANNOT modify individual fields of a [I]property which contains a value type such as a struct - which Vector3 is[/I]. You MUST get the value, modify the field, and then assign it back. Just about every field of built-in Unity classes are implemented as properties. So for instance, the [I]color [/I]field of material is a Color property - Color being a value type.[/QUOTE] Wicked, I understand that now. Thanks for the explanation! [QUOTE=foszor;46068733]That is correct. Many values of different types are properties and cannot be assigned individually. The material color is an example, which is why you need to keep a reference to a Color value and update the alpha before applying it. Not everything is like that; there are other that allow you to use methods such as SetColor or something similar to change property values. You'll find out which is which as you move along through your coding experience.[/QUOTE] Awesome, gotcha! I really appreciate the help guys, cheers
[QUOTE=Maloof?;46068746]I guess in principle we could use matColor.a instead of matAlpha in those calculations, and that would save us from having to manually update it, but then it would be constantly switching the [I]real[/I] value of our material's color.a with every alteration the code made to that value, instead of once per frame as it does when we manually set it, is that right?[/QUOTE] Yes that would be a better approach. In my example I tried not to stray too far from your code so you would understand the changes. There are a few more improvements you could make to your code, such as [url=http://docs.unity3d.com/ScriptReference/RequireComponent.html]RequireComponent[/url], but I was just addressing your original concern
[QUOTE=atrblizzard;46067297]I'm currently having a lot of problem getting the text font in Unity 4.6 to show up crisp and not blurred. I've tried setting the font size bigger on the font, but despite that, it still isn't crisp. [thumb]http://files.atrblizzard.com/sharex/2014-09-24_23-19-36.jpg[/thumb] Does anyone know a possible solution? Canvas is also set to pixel perfect.[/QUOTE] Sorry for going a bit offtopic but are you actually a project vaulderie dev?
[QUOTE=Jcorp;46067898]I've had a lot of trouble with text; the only thing that I've found to work is scaling the text UI down to something like 0.1 X and Y, increasing the width and height of the transform rect to something that looks reasonable, and then making the font size waaay bigger (I've used > 100 recently). Generally a small font size will make the font go all blurry, so even if you scale it down, a large font size will be very crisp (though I have had some problems with AA doing it like this).[/QUOTE] I've already given this solution a try from a different thread at Unity forums, but it wasn't as smoothed as I was hoping for. I was hoping that someone to have miraculously found a solution to it, but thank you for the suggestion nonetheless. [QUOTE=superstepa;46069180]Sorry for going a bit offtopic but are you actually a project vaulderie dev?[/QUOTE] Yes I am, I'm one of the lead developers on this project.
[QUOTE=atrblizzard;46070419]I've already given this solution a try from a different thread at Unity forums, but it wasn't as smoothed as I was hoping for. I was hoping that someone to have miraculously found a solution to it, but thank you for the suggestion nonetheless. Yes I am, I'm one of the lead developers on this project.[/QUOTE] The only other thing I can think of is to try turning on DirectX 11 in your project settings, if you haven't already. Some people have said that helps a number of things like this.
Yes, it's already running in DirectX 11 mode by default, but this bug has already been fixed for DirectX 9 too in beta 19.
snip
Does anyone know how to set shader/material property in LineRenderer? [code] Debug.Log(lineRenderer.materials[0].GetFloat("HueShift")); [/code] Returns me error "property does not exist". Any clues? [IMG]http://i.imgur.com/QRKvy01.png[/IMG]
[QUOTE=Fourier;46080858]Does anyone know how to set shader/material property in LineRenderer? [code] Debug.Log(lineRenderer.materials[0].GetFloat("HueShift")); [/code] Returns me error "property does not exist". Any clues? [IMG]http://i.imgur.com/QRKvy01.png[/IMG][/QUOTE] In your code, I believe you need to change "HueShift" to "_HueShift"
So I'm working on remaking my old Flash sidescroller, and I'm not sure what the best system is for handling the world. On the one hand, I know that using a square sprite tile-based construction would cut the file size down a lot, but on the other hand I'm not sure whether I'd be happy with the aesthetic. That being said, if I did choose to go with a sprite tile-based system, there are a couple of problems I ran into with my prototype. I'm not sure whether there are best practices for handling collisions. Should they handled purely with a single player collider and code (testing the angle of the collided surface, etc) or is it acceptable to just have three seperate colliders on the character, each listening for a collision then triggering their respective 'touchingWall' (etc) states? I'm also not sure how best to handle placement and recording of my sprite tiles. I really want to be able to manually drag and drop them in the editor for ease of level design and puzzle prototyping, but I get the idea that I need to put them into arrays if I want to be able to do optimization things like limiting hit detection to only a couple of tiles either side of colliding objects, etc. What do you reckon?
What's the easiest way for me to stop an animation half-way through and start another animation?
[QUOTE=LuckyLuke;46096492]What's the easiest way for me to stop an animation half-way through and start another animation?[/QUOTE] Mecanim could do this i think
[QUOTE=Fleskhjerta;46081161]In your code, I believe you need to change "HueShift" to "_HueShift"[/QUOTE] Thanks, how could I have missed that... h-,ho-, how did you know?
[QUOTE=Fourier;46098034]Thanks, how could I have missed that... h-,ho-, how did you know?[/QUOTE] Just about all shader parameters are prefixed with _ for some reason. Convention I suppose?
Is it just me or is it OnCollisionEnter and OnCollisionStay piece of shit? (it is returning me fucking triggers, which do not even collide)
Fuuuuck me. I've just spent the last 5 hours writing and rewriting my line of sight script because I was having an issue that made me think instantiating was the issue. Rewrote it to use instanceids and shit. How do I fix it? By changing the value of a single drop down box.
Ah! Finally fixed all of my bolt-related issues, but now I have another question for you folks. I have searched for this for quite some time now, to no avail. Is there any way for me to render my weapon models in the game without wall-clipping and with dynamic shadows? How can I handle that?
[QUOTE=cam64DD;46114984]Ah! Finally fixed all of my bolt-related issues, but now I have another question for you folks. I have searched for this for quite some time now, to no avail. Is there any way for me to render my weapon models in the game without wall-clipping and with dynamic shadows? How can I handle that?[/QUOTE] Unity Free, or not? Unity Free, nope. No good way to do it. Unity Pro, eh. There still isn't really a good way to do it, but you CAN use light probes so that your weapon darkens and lightens as you enter/exit shadows. That's what nearly all Valve games do, and also what Halo 4 does oddly enough.
[QUOTE=KillaMaaki;46115122]Unity Free, or not? Unity Free, nope. No good way to do it. Unity Pro, eh. There still isn't really a good way to do it, but you CAN use light probes so that your weapon darkens and lightens as you enter/exit shadows. That's what nearly all Valve games do, and also what Halo 4 does oddly enough.[/QUOTE] Well weapons are dynamic, he could "cut" the Mesh easily if it hits the wall (every frame of course)
Sorry, you need to Log In to post a reply to this thread.