|
So I've gotten to the point with something in Unity that seems so stupid that I must be doing it wrong. My understanding for how to spawn GameObjects programmatically is that you set up a prefab, make it a public property in your script, and drag the prefab into that exposed property in the editor. With now about 30 different walls, floors, and room features, this is becoming unmaintainable. Not only do I have to add a new one each time it's added, but Unity constantly forgets the assignments and makes me reassign everything from scratch. Can I just create a GameObject from scratch in code, instead of instantiating a prefab, or at the very least pull it by name instead of a public property that's been assigned?
|
# ? Oct 17, 2013 02:42 |
|
|
# ? Jun 13, 2024 05:29 |
|
SlightlyMadman posted:So I've gotten to the point with something in Unity that seems so stupid that I must be doing it wrong. My understanding for how to spawn GameObjects programmatically is that you set up a prefab, make it a public property in your script, and drag the prefab into that exposed property in the editor. With now about 30 different walls, floors, and room features, this is becoming unmaintainable. Not only do I have to add a new one each time it's added, but Unity constantly forgets the assignments and makes me reassign everything from scratch.
|
# ? Oct 17, 2013 03:09 |
|
SupSuper posted:Yes you can create blank GameObjects just with "new GameObject(name)" and adding components yourself, or pull them by name from your Resources folder with "Resources.Load(name)".
|
# ? Oct 17, 2013 09:06 |
|
Zizi posted:Oh, yeah. The Physics system needs rigidbodies. I'm surprised anything worked at all without one. Collisions will 'work' to varying degrees. Just remember though... if it doesn't have a rigidbody and you move it the whole physx world needs to be rebuilt (super slow).
|
# ? Oct 17, 2013 09:12 |
|
roomforthetuna posted:Also perhaps worth mentioning is that you can have a public array of prefabs so that you don't have to keep loving with the code every time you want to drag in a new prefab. If you prefer code then SupSuper's way is better, but this is another way to make the prefab-dragging a bit less frustrating. Thanks! I replaced them all with Resource.Load and it all works great! This brings me to my next question: whenever I create a class that needs access to the prefabs, I have to pass them all in when I create the object. Now that I know I can load them up in code, I could theoretically load them up as needed, right? Is there a performance drawback to calling Resource.Load, or is it smart enough to keep previously loaded resources in memory and pass over the same reference? Maybe I should just make a static ResourceHandler class and lazy-load them all there in static properties, so I can just call ResourseHandler.WhateverPrefab as needed?
|
# ? Oct 17, 2013 13:57 |
|
SlightlyMadman posted:Thanks! I replaced them all with Resource.Load and it all works great! This brings me to my next question: whenever I create a class that needs access to the prefabs, I have to pass them all in when I create the object. Now that I know I can load them up in code, I could theoretically load them up as needed, right? Is there a performance drawback to calling Resource.Load, or is it smart enough to keep previously loaded resources in memory and pass over the same reference? Multiple calls to Resources.Load to the same resource should be fast, because it will keep the resource in memory - unless you told it to unload that resource or all resources. If you are on mobile it would be smart to manage this a bit so your memory usage doesn't balloon. Keep in mind Resources.Load is synchronous so it will temporarily trash performance if loading a large resource for the first time. There are different ways to mitigate that if you find it becomes a problem. xgalaxy fucked around with this message at 14:50 on Oct 17, 2013 |
# ? Oct 17, 2013 14:46 |
|
OneEightHundred posted:What fails to compile is things like indexes and quantities that expect unsigned numbers. While using signed ints in the case you mentioned may give you a more sensible number, what it doesn't do is give you one that's valid to pass to things that can't sanely process a negative number. Most things with a lower bound have an upper bound as well, so if you're using signed, not only do you have to check for the case where y>x, you also have to check for cases where y is negative and will exceed the upper bound. While I don't take much of a stand against signed/unsigned for this, the one thing I champion over and over is never treat your experience or currency as a native type. Just about every game I've ever been on that has done this has had crippling flaws with it. Instead of having: code:
code:
|
# ? Oct 17, 2013 14:56 |
|
2D Toolkit is half off today on the Unity asset store. I know 4.3 is going to add a ton of 2D features, but until that's released and polished a bit, this is the best 2D solution so far that I've used. https://www.assetstore.unity3d.com/#/content/908
|
# ? Oct 17, 2013 15:04 |
|
poemdexter posted:2D Toolkit is half off today on the Unity asset store. I know 4.3 is going to add a ton of 2D features, but until that's released and polished a bit, this is the best 2D solution so far that I've used. I can vouch for 2D Toolkit too, it's got some real slick dicing / texture packing features that work well. The workflow is a bit rough when you're used to something like Flash but it's the best that's out there now. e: I'm using it at this very moment too! In a legacy publish-to-Flash project.
|
# ? Oct 17, 2013 15:40 |
|
2D Toolkit also built in support for things like tilemaps, a feature not in Unity2D.
|
# ? Oct 17, 2013 16:30 |
|
xgalaxy posted:Multiple calls to Resources.Load to the same resource should be fast, because it will keep the resource in memory - unless you told it to unload that resource or all resources. If you are on mobile it would be smart to manage this a bit so your memory usage doesn't balloon. So what's the general rule for this? I've pooled all of my resources in Futile by creating what I know I'll need ahead of time and then increasing that pool dynamically but I guess with Resource.Load it's pretty much the same thing?
|
# ? Oct 17, 2013 18:33 |
|
Here's a dumb Unity question - I set up a bunch of variables I can edit at runtime on a prefab, which I adjust as needed then hand copy back into my code. How come some of my prefabs automatically pick up the changes to the source while others never do? Some instances make me remove and re-add the source script component before they update. I made both of these prefabs using the same steps today, I didn't do anything different that I know of, and I've seen this before but never figured out a solution. Is the answer "because Unity" or "because you need to set x"? e: Maybe it's the reverse? Maybe it only "keeps" when I accidentally do my editing on the original prefab in the library? superh fucked around with this message at 18:54 on Oct 17, 2013 |
# ? Oct 17, 2013 18:38 |
|
I mentioned we were doing this a few weeks ago, but we finally got around to doing a writeup on and releasing our remote debug console for Unity. Using a debug console on mobile devices is awful, so we wrote a slim webserver which runs on the target device and allows you to connect to it with a web browser and use the console from there. The blog post talking about the what/why is here: http://blog.proletariat.com/post/64309443617/the-cudlr-that-which-cuddles-at-midnight The github repo with the how is here: https://github.com/proletariatgames/CUDLR We'll have it up on the Asset Store for free whenever it gets approved for extra-laziness, but in the mean time, if you do any mobile development in Unity and don't like stabbing yourself in the eye, you should check it out. It doesn't work on PC/Mac/consoles yet, but that'll happen either when someone forks it and does it for us or whenever we get around to doing PC/Mac/console builds and have to.
|
# ? Oct 17, 2013 18:55 |
|
superh posted:Here's a dumb Unity question - - If you're adding/removing public vars, prefab instances in the editor will eventually pick up on it. At most they will figure it out once you try to run it and get a compiler error. - If you're changing the initialized value of public vars (eg. change "public int x = 5;" to "public int x = 3;"), prefab instances in the editor rarely pick up on it. This seems to be because as soon as they have a value it will stick, even if you left it at default (new prefab instances will use your new value though). Aside from manually resetting your instances, changing the var type or visibility in the code might force Unity to reset them, but I wouldn't rely on it, as "expecting your prefab instance to have a value and then finding out it has another" is a common headache. Basically since prefab instances can have their own unique values, there's no guarantee that modifying the original prefab in the library or code will properly spread to all existing prefab instances. My advice is don't go instantiating your prefabs all over until you have the defaults down, and tread carefully in changing prefab instances VS original prefab.
|
# ? Oct 17, 2013 19:28 |
|
Makes sense (in as much as "never trust it" can make sense!) and it's all good for me - my prefabs are instanced at runtime from the library so as long as the original is right the instances should be. The game I'm working on is a fighting game so I notice pretty quickly if all my attack timings are off when I rebuild. Thanks a lot!
|
# ? Oct 17, 2013 19:47 |
|
gently caress me, I just bought 2D toolkit 2 days ago for the full price Anyway, I pretty much fell in love with Unity3D/2D toolkit after I saw a friend mess around with it, so I'm starting to learn it right now, but I got some questions: 1) What the editor of choice, and are there any other good editors besides MonoDevelop? I'm pretty much hooked on Sublime for everyday development, but so far I haven't been able to find any good Unity/2D Toolkit code completion plugins for Sublime. 2) Any good articles on common workflows, setups, patterns, pitfalls, coding conventions etc? 3) What files and dirs do I need to track in version control, and which ones can I safely ignore?
|
# ? Oct 17, 2013 20:54 |
|
Bastard posted:gently caress me, I just bought 2D toolkit 2 days ago for the full price It's the law of the internet, a goon must purchase something at full price before it can be put on sale.
|
# ? Oct 17, 2013 20:57 |
|
poemdexter posted:2D Toolkit is half off today on the Unity asset store. I know 4.3 is going to add a ton of 2D features, but until that's released and polished a bit, this is the best 2D solution so far that I've used. I think this was posted earlier but I don't recall. Think 2DToolkit will be worth it once Unity2D is released?
|
# ? Oct 17, 2013 22:20 |
|
TJChap2840 posted:I think this was posted earlier but I don't recall. Yes. Reports are that thee's a bunch of useful stuff in Unity2D that'll be behind the paywall (like atlasing), and tk2D supports tilemaps really well, which Unity apparently won't do at all.
|
# ? Oct 17, 2013 22:45 |
|
TJChap2840 posted:I think this was posted earlier but I don't recall. Yep as mentioned above there will be features that will be pro only. You won't ever have to worry about that with 2DTK. Also the developer plans on taking advantage of all the stuff that they're implementing with Unity2D like the physics.
|
# ? Oct 17, 2013 22:53 |
|
Has anyone used DF-GUI? It seems to be pretty similar to NGUI but slightly cheaper.
|
# ? Oct 19, 2013 15:09 |
|
So once again I have a bit of a physics problem. I recently switched my movement to use CharacterController.Move() instead applying velocity to a gameObject. That fixed any problems of objects climbing over each other, but now my knockback is a bit problematic. I can apply knockback to the character controller, but they don't bounce off of objects like with normal collider physics. Turning off the character controller just makes the player that got knocked back go through any level objects. Can I have a character controller ACT like a normal box collider, or do I actively have to destroy the character controller, apply a collider, apply knockback, delete the collider and reapply a character controller? That sounds a little... workaround.
|
# ? Oct 19, 2013 18:58 |
|
Chunderstorm posted:So once again I have a bit of a physics problem. I recently switched my movement to use CharacterController.Move() instead applying velocity to a gameObject. That fixed any problems of objects climbing over each other, but now my knockback is a bit problematic. I can apply knockback to the character controller, but they don't bounce off of objects like with normal collider physics. Turning off the character controller just makes the player that got knocked back go through any level objects. Can I have a character controller ACT like a normal box collider, or do I actively have to destroy the character controller, apply a collider, apply knockback, delete the collider and reapply a character controller? That sounds a little... workaround. How did going from velocity against a rigidbody to CharacterController.Move() change objects climbing over each other? Did you try rigidbody.AddForce() before swapping to CharacterController? Are you using CharacterController + rigidbody? How are you applying the knockback? Is the player supposed to bounce off an object? Are you expecting the physics engine to do the bounce for you because Move() is constrained by collisions meaning you'll get a dead stop. Do you have your code somewhere because there seems to be a ton of missing info to diagnose. CharacterController vs. Rigidbody + Collider are pretty drastically different so you might have made the switch and missed something or have the expectation that they'd work the same.
|
# ? Oct 19, 2013 19:32 |
|
poemdexter posted:How did going from velocity against a rigidbody to CharacterController.Move() change objects climbing over each other? Did you try rigidbody.AddForce() before swapping to CharacterController? Are you using CharacterController + rigidbody? How are you applying the knockback? Is the player supposed to bounce off an object? Are you expecting the physics engine to do the bounce for you because Move() is constrained by collisions meaning you'll get a dead stop. Do you have your code somewhere because there seems to be a ton of missing info to diagnose. Sorry, I'll elaborate. Objects were climbing over each other when they were colliding, which the character controller objects handle natively with their step offset, so I switched to the character controller: code:
code:
code:
I hope that's enough info. Thanks for replying so fast. Chunderstorm fucked around with this message at 19:51 on Oct 19, 2013 |
# ? Oct 19, 2013 19:48 |
|
Chunderstorm posted:Which is what I'm using for my knockback script, which detects an opposing player's attack in OnTriggerEnter: (1) What is "it"? (2) When you tried OnTriggerEnter with CharacterController? (3) Wouldn't trigger the event? (4) Disable what? If I'm parsing correctly, it seems OnTriggerEnter might not be firing for CharacterController. Try replacing the OnTriggerEnter with OnControllerColliderHit. http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.OnControllerColliderHit.html
|
# ? Oct 19, 2013 20:25 |
|
poemdexter posted:(1) What is "it"? I think we're on two different pages here. As far as (1), The CharacterController.Move() function. When I use it as knockback, it moves the Character correctly, but when it a collider, it doesn't bounce off. Using Rigidbody.ApplyForce() WITHOUT a Character Controller does this, since I'm no longer actively moving the object. I want to mimic this kind of behavior with a character controller. Is there an easy way to do that, or am I better off going back to rigidbody+box collider, and finding a different way to compensate for objects "climbing" over each other? OnTriggerEnter() is working totally fine, I showed that bit of code because you asked how I was applying my knockback.
|
# ? Oct 19, 2013 20:36 |
|
Chunderstorm posted:I think we're on two different pages here. Can you describe the "objects climb over each other" situation? Is it player and mobs rolling over each other? Is it mobs rolling over mobs?
|
# ? Oct 19, 2013 21:31 |
|
poemdexter posted:Can you describe the "objects climb over each other" situation? Is it player and mobs rolling over each other? Is it mobs rolling over mobs? Players over each other, and over other objects with colliders. This is how they start out: Then I move the monster into the other warrior: I could just lock their vertical positions but I want them to be able to go up ramps.
|
# ? Oct 19, 2013 21:43 |
|
Chunderstorm posted:Players over each other, and over other objects with colliders. lock their vertical positions during OnCollisionStay or OnTriggerStay whichever you might need.
|
# ? Oct 19, 2013 21:46 |
|
Sunday Stupidity: Spend an embarrassing amount of time debugging a shader that is supposed to use a sphere as a cutaway for another object and learn that, in fact, the magnitude of [0.5, 0.0, 0.0, 1.0] is not 0.5. At least my goal of the weekend to better understand vertex/fragment shaders is achieved now.
|
# ? Oct 21, 2013 03:54 |
|
Is there a good 2D game engine available that is cross platform and not XNA? I don't want to build my own engine through SDL. Any language is fine, but C++ preferred. Really just prototyping something here but if it can be used for a full fledged game then all the better.
|
# ? Oct 22, 2013 23:38 |
|
Sylink posted:Is there a good 2D game engine available that is cross platform and not XNA? I don't want to build my own engine through SDL. Unity with 2D Toolkit using C# is the closest I've gotten to what you described. Check waaaaay up this page or the page before it for some more info.
|
# ? Oct 23, 2013 00:07 |
|
Looks interesting, has anyone ever messed with Angel 2D?
|
# ? Oct 23, 2013 01:07 |
|
Sylink posted:Is there a good 2D game engine available that is cross platform and not XNA? I don't want to build my own engine through SDL. https://github.com/GarageGames/Torque2D It's has its flaws and it is a huge code base. It uses TorqueScript - which is slow. But it wouldn't be terribly difficult to shoehorn lua as a replacement or ignore the scripting part of it altogether. There are probably simpler engines though. SDL/SFLM is a library - which you said you don't want. Torque is all the way at the other end of the spectrum. And XNA would be somewhere in the middle -as far as code size, flexibility, complexity, etc.
|
# ? Oct 23, 2013 02:03 |
|
Sylink posted:Is there a good 2D game engine available that is cross platform and not XNA? I don't want to build my own engine through SDL. Across what platforms? Cocos2d-x is probably the #1 for iOS/Android compat. All C++ other than platform specific initialization.
|
# ? Oct 23, 2013 03:04 |
|
Phones are nice, I really just wanted something OS neutral for the most part and not a product of Microsoft so that I don't get stuck on Windows on the off-chance I want to run it on something else. Torque looks cool and so does cocos, going to check these out. Thanks guys!
|
# ? Oct 23, 2013 04:00 |
|
Sylink posted:Phones are nice, I really just wanted something OS neutral for the most part and not a product of Microsoft so that I don't get stuck on Windows on the off-chance I want to run it on something else. Torque looks cool and so does cocos, going to check these out. Thanks guys! MonoGame is an open-source, cross-platform replacement for XNA, and is drat near drop-in compatible, from what I've read.
|
# ? Oct 23, 2013 18:54 |
|
^^^^ MonoGame is indeed very cool if you wanna go the C# route.Sylink posted:Is there a good 2D game engine available that is cross platform and not XNA? I don't want to build my own engine through SDL. If you don't care about language and you want it to run on anything, Java's got some pretty good 2D engines without a ton of cruft, like libgdx or slick2d (both built on lwjgl) C++ has a poo poo-ton of engines though if that's really what you're looking for, I wouldn't even know where to start. Take some time to google around and compare before you get married to anything. Torque, Ogre, Allegro, etc. Although when it comes to 2D you don't even need a huge engine anyways. Just some basic graphics libraries to get you going and you can write the rest yourself without much hassle, so things like SDL or SFML. After that you just need to write a sprite/entity object, some collision detection, and input, and you've got your own game engine. 2D's pretty simple compared to 3D. Then its your own and you can customize as necessary. For that matter you could just bind to openGL and go from there. If you're just prototyping then OTOH you may not want to take the time for that, but OTOH it'll mean you're freer to try out whatever you want, and you won't have to spend time learning an API and formatting things as the API expects. Zaphod42 fucked around with this message at 22:19 on Oct 23, 2013 |
# ? Oct 23, 2013 22:15 |
|
I'm trying to get NGUI and Futile to play nice together but I can't figure out how to setup the cameras correctly. What I tried doing was this: - Create a Futile layer at 10 - Create an NGUI layer at 11 - Have all of my NGUI's elements placed on the NGUI layer. - Set Futile's camera culling mask to the futile layer - Set Futile's camera clear flags to depth - Set NGUI's camera culling mask to the ngui layer - Set Futile's stage.layer to the futile layer. This sort of works. Both NGUI and Futile will render, but Futile stuff appears above NGUI stuff. Anyone gotten this to work?
|
# ? Oct 24, 2013 19:31 |
|
|
# ? Jun 13, 2024 05:29 |
|
Hmm. Okay I 'think' its working. I changed Futile camera clear flags to solid color instead (since it renders first it will need to clear the screen). I changed NGUI camera clear flags to depth I change Futile camera depth to 0 and NGUI camera depth to 1. Now NGUI is rendering in front of Futile
|
# ? Oct 24, 2013 19:37 |