• Unity3D - Discussion
    5,004 replies, posted
Anyone got tips for creating a chatbox in the new UI? Never created one, and obviously every multiplayer game should have one :v:
So does StopCoroutine still only work with coroutines started by string? The api says you can stop it with the IEnumerator but it's not working for me.
Alright so I'm having a lot of trouble optimizing my game. I am currently making some Minecraft type of game just for fun & training, I made the day-night system, block placement, behaviour-per-block (Sand falling), and the mighty epic map generation system, so all that works nice, however, the huge problem is that I am generating single cubes for each block, and for a 16x16x16 blocks map, it's lagging like crazy, those damn draw calls... So I heard about Dynamic Batching, however since a few days I just can't get it to work. I have read, reread & rereread the conditions into making Dynamic Batching work, but it simply does not. Is there like some kind of thing obvious i'm missing here ? Maybe there's another method to reduce draw calls ? Maybe an easy way to "combine" those damn blocks to make a single mesh, or at least, decrease the mesh count drastically ? Any help would be appreciated, as having a lot of blocks & cubes in a Minecraft type of game is quite primary, thanks.
You need to read up on the Minecraft mega-thread over on the Unity forums. [url]http://forum.unity3d.com/threads/after-playing-minecraft.63149/[/url] tl;dr you have to separate your world into chunks, and for each chunk you must generate the mesh yourself. To get any reasonable performance, you need to only draw the cube faces that could possibly be visible (are touching air).
[QUOTE=Fleskhjerta;45876063]Alright so I'm having a lot of trouble optimizing my game. I am currently making some Minecraft type of game just for fun & training, I made the day-night system, block placement, behaviour-per-block (Sand falling), and the mighty epic map generation system, so all that works nice, however, the huge problem is that I am generating single cubes for each block, and for a 16x16x16 blocks map, it's lagging like crazy, those damn draw calls... So I heard about Dynamic Batching, however since a few days I just can't get it to work. I have read, reread & rereread the conditions into making Dynamic Batching work, but it simply does not. Is there like some kind of thing obvious i'm missing here ? Maybe there's another method to reduce draw calls ? Maybe an easy way to "combine" those damn blocks to make a single mesh, or at least, decrease the mesh count drastically ? Any help would be appreciated, as having a lot of blocks & cubes in a Minecraft type of game is quite primary, thanks.[/QUOTE] You're going to need to move away from using a GameObject for each block and use a procedural mesh
KillaMaaki, is it possible to stop DFTweens?
Yes. You should just be able to call Stop() on the given tween.
[QUOTE=KillaMaaki;45876182]You need to read up on the Minecraft mega-thread over on the Unity forums. [url]http://forum.unity3d.com/threads/after-playing-minecraft.63149/[/url] tl;dr you have to separate your world into chunks, and for each chunk you must generate the mesh yourself. To get any reasonable performance, you need to only draw the cube faces that could possibly be visible (are touching air).[/QUOTE] [QUOTE=foszor;45876196]You're going to need to move away from using a GameObject for each block and use a procedural mesh[/QUOTE] Alright guys, thanks to you two, i'll see what I can do from there.
Are custom Bolt state properties meant to be completely unusable? You're meant to inherit from IBoltStateProperty and then set the state property in the Attached method, this is impossible because the generated set method throws an exception if you don't own the entity. About to throw Bolt away and use something better, I've had nothing but problem after problem. For now I've just removed that check from the code generation and now it works fine, so I have to wonder why have it there in the first place.
Why would you want to set the entity without owning it? [code] public class PlayerSerializer : BoltEntitySerializer<IPlayerState> { public override void Attached(IPlayerState state) { if (boltEntity.spawnedRemotely) return; //If client return. state.cust = new Cust() { str = "Hello World" }; } } [/code]
Maybe layla is trying to set the value from the [I]controller[/I] rather than the [I]owner[/I]? In which case, there's two options: 1.) Try to figure out whether that logic can be moved to the owner rather than the controller 2.) Otherwise, change the code to allow changing property from controller as well as owner, and bring it up with FHolm on the forums.
You can access and change properties but you can't change the state object itself right? Are there any samples with custom state properties yet?
What would be the best way to detect objects in the world that are near a character, and enable usage on them when they're clicked, and when they're clicked run a "OnUsed" function? I'd assume the best way would be to have a collider attached to each of my characters, and when certain tagged objects are touching the collider, enable a constant ray trace to see what the mouse is over, and if the mouse button is clicked down, call the function? This is a pretty fundamental thing for the games logic so I want to make sure I'm using the most efficiant method, which is why I ask.
My TrackIR came in today and naturally I had to see if there was a way to get it to work in Unity. It was a huge pain in the ass to hunt down, but after trying to compile something from their SDK, I found a Swedish guy who managed to [url=https://github.com/byBrick/Unity-TrackIR-Plugin]get it working in a neat little package[/url]. [vid]http://a.pomf.se/qynrwg.webm[/vid]
So I tried baking lightmaps to a terrain and decided I don't like it. So I pressed the "clear" button and unchecked the "Use lightmaps box" and changed the directional light to real time only. So i've got my real time shadows showing in the editor... but as soon as I hit play the terrain goes back to unlit. Anyone know what is going on?
[QUOTE=reevezy67;45878283]Why would you want to set the entity without owning it? [code] public class PlayerSerializer : BoltEntitySerializer<IPlayerState> { public override void Attached(IPlayerState state) { if (boltEntity.spawnedRemotely) return; //If client return. state.cust = new Cust() { str = "Hello World" }; } } [/code][/QUOTE] Custom properties need to be set to a new instance of your custom property class. You can't just set it for the owner because the proxy also needs an instance so it can call the custom read. Just try and get a custom property working and you'll quickly see what I mean.
Does anyone have bool's syncing correctly in Bolt? I'm trying to sync if someone is dead, it works to clients already ingame, but to any new player's joining, they appear alive. Here's my code. [code]using UnityEngine; using System.Collections; public class PlayerDeath : BoltEntityBehaviour<PlayerSerializer, IPlayerState> { public bool isAlive = true; public GameObject model; public override void Attached () { boltState.deadChanged += OnDeadChanged; } void OnDeadChanged () { model.renderer.enabled = boltState.dead; GetComponent<FPSWalker> ().enabled = boltState.dead; } void Update () { boltState.dead = isAlive; } public void Die () { isAlive = false; Invoke ("Respawn", 5); } void Respawn () { isAlive = true; } } [/code] The Die function is being called in a different script. I'm confused, as I thought this is all I had to do when using a Bolt State? [QUOTE=Skipcast;45880439]Not sure if related as i haven't worked with bolt, but shouldn't "boltState.dead = isAlive" be "boltState.dead = !isAlive"? In the update method.[/QUOTE] That's just my silly naming of variables, but that has nothing to do with the problem, as I said. It's working to clients already ingame, but if the function/variable changes, and a new player joins, it doesn't sync.
Not sure if related as i haven't worked with bolt, but shouldn't "boltState.dead = isAlive" be "boltState.dead = !isAlive"? In the update method.
[QUOTE=sarge997;45880413]Does anyone have bool's syncing correctly in Bolt? I'm trying to sync if someone is dead, it works to clients already ingame, but to any new player's joining, they appear alive. Here's my code. [code]using UnityEngine; using System.Collections; public class PlayerDeath : BoltEntityBehaviour<PlayerSerializer, IPlayerState> { public bool isAlive = true; public GameObject model; public override void Attached () { boltState.deadChanged += OnDeadChanged; } void OnDeadChanged () { model.renderer.enabled = boltState.dead; GetComponent<FPSWalker> ().enabled = boltState.dead; } void Update () { boltState.dead = isAlive; } public void Die () { isAlive = false; Invoke ("Respawn", 5); } void Respawn () { isAlive = true; } } [/code] The Die function is being called in a different script. I'm confused, as I thought this is all I had to do when using a Bolt State? That's just my silly naming of variables, but that has nothing to do with the problem, as I said. It's working to clients already ingame, but if the function/variable changes, and a new player joins, it doesn't sync.[/QUOTE] I've got a hunch that it IS syncing.... it's just not calling the is changed method.
Maybe the update is overwriting it. [code] using UnityEngine; using System.Collections; public class PlayerDeath : BoltEntityBehaviour<PlayerSerializer, IPlayerState> { public bool isAlive = true; public GameObject model; public override void Attached () { boltState.deadChanged += OnDeadChanged; } void OnDeadChanged () { model.renderer.enabled = boltState.dead; GetComponent<FPSWalker> ().enabled = boltState.dead; isAlive = boltState.dead; } public void Die () { isAlive = false; boltState.dead = false; Invoke ("Respawn", 5); } void Respawn () { isAlive = true; boltState.dead = true; } } [/code] [editline]4th September 2014[/editline] Oh, at no point do you set isAlive from boltState.dead? Is that the only thing out of sync or does OnDeadChanged not get called?
I fixed it! [code]using UnityEngine; using System.Collections; public class PlayerDeath : BoltEntityBehaviour<PlayerSerializer, IPlayerState> { private bool isDead = false; public GameObject model; public override void Attached () { boltState.deadChanged += OnDeadChanged; } void OnDeadChanged () { model.renderer.enabled = isDead; GetComponent<FPSWalker> ().enabled = isDead; isDead = boltState.dead; } public void Die () { if (boltEntity.hasControl) { boltState.dead = true; Invoke ("Respawn", 5); } } void Respawn () { if (boltEntity.hasControl) { boltState.dead = false; } } }[/code] You guys are the best! :smile:
Oh man, just got myself a new asset! Goodbye TNet, hello Bolt!
I have been wanting to get into unity again with Bolt (I do have it purchased). Though seeing how much better other people are, especially when people are just like: "Just started messing with unity today", and they have something that I can't get even close to... makes me feel disappointed and just stop trying. Maybe game programming just isn't my cup of tea.
[QUOTE=TH3_L33T;45881826]I have been wanting to get into unity again with Bolt (I do have it purchased). Though seeing how much better other people are, especially when people are just like: "Just started messing with unity today", and they have something that I can't get even close to... makes me feel disappointed and just stop trying. Maybe game programming just isn't my cup of tea.[/QUOTE] Hey, don't give up pal! Me, for instance, I only managed to get a hold of how unity works after trial and error, I have a bunch of old projects here. Literally thirty of them, I'm not even shitting you. I'm pretty sure you're capable of doing some pretty awesome stuff with it, you just need some practice! Besides, we're here to help you. :D
To be fair, almost 90% of the people who say "Just started messing with Unity today" showing off some great thing, have already had experience in game development/programming in general. Programming isn't a competition, it's about creating interesting and fun things, together.
Dude, you would not BELIEVE the noob mistakes I used to make. Particularly in the two games I released on Kongregate: Geo-Gun: I didn't know how to use UnityGUI, so the lobby doesn't, erm, scroll. Seriously, if there were a bunch of servers it would just spill right off the screen >.> NecroPixels: Even bigger mistake here. I added a click-to-respawn functionality, but, erm, forgot to make it only respawn your own character. So if multiple characters are dead and you click to respawn, it spawns clones of the other players which were dead, and before long you get absolute boatloads of player clones standing around. Whoops. The only reason I don't make those mistakes anymore is because I've been practicing Unity daily for years. Work hard enough and you'll get way better, promise.
I suck at creating shaders, could anyone help me figure out why this only works in the editor but not in standalone(windows)? It ends up all pink. It's not a problem with it not being included in the build as far as I know. Setting o.Albedo to IN.vert_color.rgb alone works, but I lose the whole point of the shader. Any help would be greatly appreciated. [CODE]Shader "Custom/Terrain/Ground/Woodland" { Properties { _Color ("Main Color", Color) = (1, 1, 1, 1) _SnowLevel ("Snow Level", Range(0, 0.5) ) = 0 _SnowWetness ("Wetness", Range(0, 0.5)) = 0.15 _SnowColor ("Snow Color", Color) = (1.0, 1.0, 1.0, 1.0) _SnowDirection ("Snow Direction", Vector) = (0, 1, 0) } SubShader { Tags { "RenderType"="Opaque" } LOD 150 CGPROGRAM #pragma surface surf Lambert vertex:vert fixed4 _Color; float _SnowLevel; float _SnowWetness; float4 _SnowColor; float4 _SnowDirection; struct Input { float3 vert_color; float3 worldNormal; INTERNAL_DATA }; void vert (inout appdata_full v, out Input o) { o.vert_color = v.color; } void surf (Input IN, inout SurfaceOutput o) { fixed4 c = _Color; half difference = dot(WorldNormalVector(IN, o.Normal), _SnowDirection.xyz) - lerp(1, -1, _SnowLevel); difference = saturate(difference / _SnowWetness); o.Albedo = difference * _SnowColor.rgb + (1 - difference) * IN.vert_color.rgb; o.Alpha = c.a; } ENDCG } }[/CODE]
oh, don't get me wrong. I will still keep trying. Just annoying when things don't work. If anyone wants, you can add me on steam always helpful to have some people to do some 'rubber duck' problem solving against.
[QUOTE=xXParanoidXx;45882179]I suck at creating shaders, could anyone help me figure out why this only works in the editor but not in standalone(windows)? It ends up all pink. It's not a problem with it not being included in the build as far as I know. Setting o.Albedo to IN.vert_color.rgb alone works, but I lose the whole point of the shader. Any help would be greatly appreciated. [CODE]Shader "Custom/Terrain/Ground/Woodland" { Properties { _Color ("Main Color", Color) = (1, 1, 1, 1) _SnowLevel ("Snow Level", Range(0, 0.5) ) = 0 _SnowWetness ("Wetness", Range(0, 0.5)) = 0.15 _SnowColor ("Snow Color", Color) = (1.0, 1.0, 1.0, 1.0) _SnowDirection ("Snow Direction", Vector) = (0, 1, 0) } SubShader { Tags { "RenderType"="Opaque" } LOD 150 CGPROGRAM #pragma surface surf Lambert vertex:vert fixed4 _Color; float _SnowLevel; float _SnowWetness; float4 _SnowColor; float4 _SnowDirection; struct Input { float3 vert_color; float3 worldNormal; INTERNAL_DATA }; void vert (inout appdata_full v, out Input o) { o.vert_color = v.color; } void surf (Input IN, inout SurfaceOutput o) { fixed4 c = _Color; half difference = dot(WorldNormalVector(IN, o.Normal), _SnowDirection.xyz) - lerp(1, -1, _SnowLevel); difference = saturate(difference / _SnowWetness); o.Albedo = difference * _SnowColor.rgb + (1 - difference) * IN.vert_color.rgb; o.Alpha = c.a; } ENDCG } }[/CODE][/QUOTE] If you read the docs, they have this line in the vert function: [code] UNITY_INITIALIZE_OUTPUT( Input, o ); [/code] So it would probably look like: [code] void vert( inout appdata_full v, out Input o ) { UNITY_INITIALIZE_OUTPUT( Input, o ); o.vert_color = v.color; } [/code] Try that.
That didn't work, thanks for trying though. I forced the build into opengl temporarily and the shader works there. Weird..
Sorry, you need to Log In to post a reply to this thread.