#archived-code-advanced
1 messages · Page 43 of 1
Currently when i switch scenes render thread is taking a lot of time, i tried with async but lag is too much to cover and sometimes it starts interfering with the current scene as well. Is there any way to do it completely on different thread.
Most of you probably know that if we use using UnityEditor; outside of Editor folder (or outside #if UNITY_EDITOR) we will get a compilation error as soon as we try to start the build, because UnityEditor does not exist in builds.
Does anyone know of a method to force Editor to give us this error without starting the build? The reason I’m asking is because I want to add a unit test to check for this.
I solved it with this, but instead of the count, I just assign "chunkID"'s to them, to keep track of which chunk of points they're in. That way if the chunk ID's are ever different, I know instantly they don't connect. It's better than using the count cause you don't get the problem of "what if they have the same amount of nodes"
Do what on the other thread? Load the scene?
No, there is not. In fact, must Unity call cannot be done on a separate thread.
Are you sure you are doing the loading async correctly ?
Is there any Awake or Start that could take a long time in the new scene ?
Is there any reason why you need to start the loading before you have ended the current level ?
Did you try to reduce the size of your scene ?
I do not know anything about being able to validate such thing natively. That being said, a code script is nothing more than a file which means that you could always teat it as such.
Found this interesting: Chatgpt gave me this
This doesn't cover cases where the namespace is used directly, like UnityEditor.AssetDatabase.SaveAssets();
there is one problem with this approach. Let's say we have a class
#if UNITY_EDITOR
using UnityEngine;
public class Foo()
{
}
#endif
then in another class
public class Bar()
{
void DoStuff()
{
// This will cause the build to crash, even though Bar does not use UnityEditor
var Foo = new Foo()
}
}
Our test will not detect this
Interesting, thank you, but it still has the same problem I stated above
I almost feel like at this point we should just start the build process and see if it fails during the first stages, then cancel it
just add 'line.Contains("UnityEditor.")' to the assert cases?
Im sorry, im 100% sure you are correct and Im just being an idiot, but I dont see why 'Using UnityEngine' would cause a crash here?
I forgot to add the assumption that Foo class was in an Editor folder. I've edited my message to add IFDEF (which is effectively the same thing) to better illustrate my point
I think that is intended behaviour, encapsulation on a class level rather than a method level. So any class like bar that touches foo directly is burned by association. you could maybe try writing a editor script that brackets all the connections to foo with UNITY_EDITOR ifdefs# and then run that before any test or build?
or maybe just spits out which files have connections to Foo-like files and then add the ifdefs manually might be less work
realistically
You would need to first create a DSM (Dependencies Structure Matrix). There is some tool that can do that for you. I do not know if you can create it from code and then access it. https://en.wikipedia.org/wiki/Design_structure_matrix
wait wouldnt this work?
#ifndef YOUROWNBUILDDEFINE
#if UNITY_EDITOR
using UnityEngine;
public class Foo()
{
}
#endif
#endif
To be honest, you should implement good work practice and that would be much easier.
Hmm I was hoping to achieve the result without changing much code, our codebase is dozens of thousands of lines of code across dozens of classes so implementing this would be a substantial amount of work, raising the question "is it even worth it?"
You can probably trigger the compiler without the UNITY_EDITOR preprocessor define using AssemblyBuilder
true, we have a few new-joiner devs at the moment and they're not accustomed to our codebase just yet
Oh as we are on this topic, is it possible to exclude a complete folder from compilation (and just remove the one call into this folder with a define) without manually deleting it before building?
AsmDef files are probably the way
sounds interesting, I'm a bit worried about this part of doc though:
The AssemblyBuilder class compiles scripts that are outside the Assets folder into a managed assembly, with the same references and #define directives as scripts inside the Assets folder. This is useful for building assemblies of scripts you do not want placed in the Assets folder.
I'm building a little multiplayer thing with server + client in the same project and just dont want the user to be able to get their hands on the server stuff, thanks I'll try if I can do that with AsmDefs
At this point, you could just setup a Continuous Integration pipeline.
In fact, that is probably the solution that would be the best in my opinion.
Hey everyone, i hope u r great 😄 Do you know how i can convert a struct as a byte[] ? I try to save my data in Switch but unfortunately, i don't know how to do
Google would be your answer. It is pretty much a solved issue.
MessagePack should be able to do that
I don't think i need help like that, but thanks !
i'll take a look, thanks 😄
Could also serialize to JSON and get the bytes out of the string, but if you're looking for small files, MessagePack is the way
i think about that, but it's not the more optimize 
Optimized as in file size, or serialization performance?
everything
You usually can't have that
Data serialization is indeed a solved issue and there are plenty available solutions you can Google.
There are many solutions precisely because they each excel at different things, there isn't a golden solution that fits every use case.
Some of top of my head you can look into: JSON, XML, Protobuf, MessagePack, and Flatbuffers.
Or you can just invent your own (probably don't do that)
i wasn't thinkings theses things were used for that, thanks for the information
i will take a look at everything !
Depending on hwo complex your data is, manually packing it into a byte array is a good option as well
Unity has built in JsonUtility if you don't know, I would suggest write your code with clean separation so you can swap out to a different de/serialization solution later.
Gives you (probably) the best performance and smallest size
I feel like you are in the process of premature optimization.
But most places don't do that
Actually, i just want to save file in switch, but it only allows byte[] and have a lot of restriction
i never did theses kinds of things, and i'm lost with that ahah
You can just convert a json string to bytes pretty easily
i will try that, thank you 😄
Something like encoding.something.tobytes
Oh well that's pretty much what I said but got hit with the "not optimized enough" one
Weird lol
sorry
we do have it, the problem is we only know that this problem has occurred after PR has been merged and we launched the build.
With unit tests however we would be able to know that even before PR has been merged, since we run them for every PR
The first step of executing unit test in continuous development is to build the project.
Most CI environments can also run tasks on push
well, in our case unit tests passed successfully, but the build failed
Unit test should be run after the build.
In fact, buiding is part of the "unit testing"
They probably build in "editor mode" before running tests
Instead of building a release and testing
I think the easiest solution would be to write a script that runs pre build and temporarilly comments out all the in method code(but not names or signatures, inside all of the scripts in the editor folders
- Save a temp backup(copy file, add .orig or something to the original)
- Use something like below to find all of the cases where unityeditor is mentioned, comment those out.
- search line by line(in fields and function bodies specifically) and comment out anything that isnt a method signature or scope operators
- Save files.
- Build.
- Restore backups
Fairly certain you could do this from a single editor sript with an hour of work or so
Could you just not build in release ?
yeah probably, CI was developed by another dev so I don't know that much about it
haha ur right, I think I assumed the build needed to be in debug for whatever reason.
this might be feasible, though if it's worth so much effort is still a question 😄 Thank you anyway!
might assign this to one of our new devs
I think I might create an investigation ticket and copypaste your advice if you don't mind
some quite promising options here
chatgpt has limited knowledge of 2021 so he might not tell the truth
ChatGPT or any other AI should not be used to answer questions here, unless what it said can be verified it's truthy and working
(server rule #📖┃code-of-conduct)
Go for it!
I spent a lot of time doing stuff like this while integrating the Unity editor GUI to be used with our from scratch game engine in the second yer of school, Its always nice to find problems where I can put those hours baning my head against a wall to use.
I Imagine whether its worth it being entirely down to how how much time you lose to a failed build haha. on a big enough team....
more about "how often does this problem occur". So far it's been rare, but stable
If someone ends up doing this, some pitfalls:
- Check if there is some dirty flag you have to set so that the 'empty' files are actually fully recompiled at build, so you dont end up tearing your hair when it doesnt work even though it should
- I dont think this solution works if any of the editor scripts have function arguments or return types that specific to the Unityeditor namespace, but in that case the non-editor caller scripts would probably need to touch unityeditor aswell so maybe its a moot problem? Otherwise you could probably hide the dependency in a struct that you send in and out somehow
- make sure to restore backups even if the build or tests crash
are you saying
- i can't prevent my team from using UnityEditor assembly references in player code
- however, i, @raw goblet , can choose to not merge such code
- the way i want to do that is XYZ, which will tell me if
using UnityEditorappears in a script referenced by a player assembly
that's your goal?
i understand you have "unit tests" or hwatever, you're interested in tests because you right now have a checkbox in github actions or jenkins or circle ci or whatever, it's not that it has to be a test
is this describing what you want*?
personally i think this is a colossal waste of time. if you are responsible for doing a merge, you should try building the game before you click the merge button. that will very quickly show you if someone has referenced UnityEditor in a player build.
there are other users who have wanted to write linters for all sorts of misbehavior and it is such. a. waste. of. time.
your CI should build the game as part of its tests. this is soimething another user recommended
that is the way you test if UnityEditor is referenced
did you profile the editor or the player?
If something happens on EVERY PR it most likely should be automated. Making builds is a lengthy process, so I'd rather spare my team from wasting time on this and let CI machine do that.
however, i can choose not merge such code
Well yeah, I can notice this thing and tell to fix it, but I'm just a human, as fallible as anyone else 🙂
That's another reason to automate this thing
whether or not it's a waste of time depends on how long it takes to implement something versus how much time and effort it will save in the future.
If creating a unit test that I want takes 20 man-hours then we'll just ditch it. If it's 5 minutes then why not.
this might be one way to solve it, yes. We'll investigate.
i run a unity building service as part of a product i offer. i agree building the game is a chore lol
it's up to you. your time is valuable. don't author a linter.
it's not going to take 5 minutes. the 5 minute version is adding a step to build the game
which, imo, seems like it will catch a lot more issues than only editor assemblies being referenced from the player
it's unavoidable. eventually you'll want to know: before you merge something, does it build?
you're not gonna like this, but we already have linter set up 😄
And yeah, it will yell at you for leaving unnecessary using <namespace> , redundant empty lines, whitespaces, missing brackets etc
I was an individual contributor back when it was done and I was so pissed at first. But with time, I have to admit, I started liking it quite much. Cleaned up code is so nice to work with
it also checks for following some naming conventions and stuff
It actually has a benefit that we now can more easily move devs between projects within the company since they won't have to get used to new codestyle and naming conventions
okay well it sounds like you have no further unknowns you wish were known
yeah I wrote down my action items already, now just chilling
thank you btw
nah just casual match3 kind of thing, the ones where the target market is 40 year old american housewives, aka the most lucrative gamer demographic 😂 (not a joke). I prefer to play much different games in my spare time.
It has been fun to develop though, considering how big the codebase and the team is.
target market is 40 year old american housewives, aka the most lucrative gamer demographic
your bosses are still in the First Act of their journey too
what studio is it?
like they're almost at the end of the first act. at the end of the first act, your bosses decide to stop developing games altogether.
they might be like 5-6 years in
that's how long act I is
ya sure? we hit unicorn status not that long ago
really hard to say without knowing what it is
Yeah I think the company is about 5 years old
hmm that's an interesting point. I have definitely noticed a slowdown in the number of new projects, however there is also a large increase in numbers of employees so I guess there is growth
i am trying to find unknowns that you might want to be known
sorry I don't feel comfortable sharing the company name in case I have already shared something from NDA 😄
shared something from NDA
unicorn status
listen to yourself
what's wrong?
i don't know it's just funny
here's a good one: "NDA" stands for "Not Doing Anything"
ahaha yes as someone who has signed NDA I now just sit doing nothing
well there is nothing sensitive you've written here, and the name of the studio and the game are not confidential... it's up to you
i'm not sure you want to know what i could say
the 40 year old american housewives line appears almost verbatim (it omits housewives and says women) in a deck about game development mistakes
why would it be a mistake?
do you really want to know or are you going to tell me i'm wrong because "unicorn"
how can you tell the difference between
- your UA guy does something good
- a general change in the market?
here's another question: are you familiar with simpson's paradox?
so your bosses, the thing they care about is "person good" or "person bad," and also, at the end of Act I, the UA team changes. it doesn't shrink or grow, but the kind of person that runs it is very different.
at act II, the people that know what simpson's paradox is, leave**
@raw goblet so if you don't want to quit your job near the start of Act II, don't read what simpson's paradox is lol
@kindred remnant this might be one of those interesting conversations you were looking for
I'm not telling you you're wrong. Besides, I don't have that much perspective on the company as a whole, I'm just a dev. All I have is my personal experience with the company and it's been great
I'm trying to make a conclusion from what you wrote, is it "what looks like a good UA team might just be a good movement of the market and once market changes everything will crash"?
sort of. i'm sure you've been in an all hands meeting where there's a bunch of charts going "up and to the right" from your UA team
and you have some kind of intuition that these guys don't know anything, so how is it possible that they stumbled upon some kind of strategy? really they are taking credit for noise
it's not crash versus rocket ship or whatever
the "know anything" part is knowing what simpson's paradox is.
that's the real* issue with 40 year old housewives
did your UA people look at some dashboard, and that dashboard has a demographics tab, and it has a way to do a chart that segments at most two ways, and they choose age and gender because that's something they comprehend, and they compare a bunch of things with that chart, and see that the thing with "the most money" (or whatever) happens to have 40 year old women as the largest group?
yes
that's what actually happened
and now they've imparted this pseudoscience onto you @raw goblet
I've got no clue tbh 😂 All I saw was the "target demographic" label in one of the decs
is it actually TRUE that a match 3 game appeals to 40 year old women? YES!
i mean i think it appeals to everyone
and that what that chart is saying is simpson's paradox, followed by, you're just discovering who more-slightly-frequently clicks on ads in facebook, and is numerous enough in facebook to matter (or whatever)
this is all Act II stuff
people who know simpson's paradox don't stick around for Act II!
I've just read about simpsons paradox but tbh I'm struggling to understand what do you imply with it in the context of gamedev
that i can cut up your data in many ways, and actually give you opposite opinions about whether or not a certain demographic is "the most lucrative"
one cut makes a group look the "most lucrative" and then cutting it again suddenly makes it look like the least "lucrative"
even in a way that would make sense to braindead business people
it's to refute the idea that you should be writing games for some seemingly underserved demographic like 40 year old women. that sounds so unorthodox - some of the people who leave at the start of Act II will know that, but pretty much everyone who leaves at Act III will know that
lots of steps on this journey
hardly any of the same people from Act I will be around for Act III... not even your bosses
Anyway I’m not a psychic
I see your point, and tbh I'm not sure I know enough about our company to give an opinion on whether or not something is sus.
I only have anecdotal evidence from my own life and surrounding. I've got plenty of friends working in big studios for AAA projects. I see how they work with super complex projects, do overtime constantly and they don't get paid that much. On the other hand, in my company the games are far less complex (== easier to work with), the pay is higher and in my 2 years working here I did not have to work a single minute overtime.
So, from my humble point of view, whoever is sitting in the UI/Marketing are doing a good job to make us all fed 🙂
What do you think transition between Act 1 and 2 would look like?
This is such an Act I thing to say!!!
My god it’s like you’re straight of of Culver City central casting
I’m just teasing but seriously without knowing like, a concrete studio
I’m not a psychic
well since you're describing Act 1 and Act 2 as somewhat concrete things you do have some concept
what does the general case look like?
A lot of people who know stuff leave
It’s like all the knowledge evaporates
And they keep it to themselves
And some of them happen to be nepo babies and go do their own thing and fail, and those guys don’t know anything
That’s like the B plot
This is sort of true at any media company
Like it’s happening at Netflix right now - can you believe they’ve been in Act I all this time?
so loss of talent and expertise is the reason
Yeah but it doesn’t look like that
It looks on the outside like cranky people leave
got it, thank you, I'll be on a lookout for that 🙂
I've got more from this chat then I came looking for indeed 😂
Also all those AAA game devs are paid much bigger bonuses than the mobile games people
I mean of course if it was as simple as you say
In your Culver City central casting featured extra line
seems not to be the case judging by their complaining
It’s not so black and white
true
Maybe they don’t know
ok I have no clue what Culver City is, sounds like some kind of an american reference and I'm very very far from there
Lol
okay i workedshopped this a bit and, the actual start of act II is there's a new boss
like one of the old bosses, maybe THE old boss, has been effectively replaced by seemingly a professional
and whether or not you stick around for act II is, do you think he's the villain? if so, you're gone. if you think the people who are leaving are the villains, you're in for the ride
like if you're still in act i, probably a few of your bosses are some kind of very lucky fuck ups
hard to say
maybe one if them is a nepo baby even. i don't know if that plays a big role in your community, but it does in Los Angeles
also since your bosses might change all the time, you'll know this is the Act II boss when you stop hearing things to the effect of, "do the successful thing"
@raw goblet like right now your bosses, most of the time, will say, "do whatever is going to be more successful"
they may say stuff like "it doesn't matter as much where the ship is going, it's more important* that everyone is rowing in the same direction"
you're going to stop hearing things like that at the end of Act I
you'll stop hearing "there are unlimited ideas, you prioritize them and try each one and test them, and keep the ones that work well" <-this is from the director of engineering at twitter, circa 2017,* which JUST went into act II!!
like isn't that funny? twitter just began Act II
it's a media company!
my favourite part was when you asked Dive if he really wanted to know - and then immediately told him anyway
never change, doctor
uhm no? tbh I'm not even sure what is exactly it is that they are saying, I'm a few organizational levels below so I don't get to hear them often except for like public announcements
but I get the feeling that they give quite high degree of autonomy to important people, and they realize that talent is the most important thing for the company
When I change the saving system a bit it rejects the .json.
Is there a plugin or ready script that parses the old json to the new json (what it can parse, others are initialized with 0)?
i’m not really sure what useful answer you’re expecting. what are you changing? what do you mean the json is rejected? if the old and new are both jsons, what are you trying to do?
Like I have struct in structs for my save files. When I change there something the old savefile doesnt work anymore. I think I gonna need a Json-patcher of some kind.
Something that coverts it to xml or so, adds everything it can to the new xml file and coverts it back. Something like that
lol
i think it comes out of people's mouths in various forms. but the essence is that when you ask for an opinion, they tend to say stuff like "do whatever makes the most money" or "whatever has the better numbers" or something that is not really an opinion at all
opinionated people don't pour resources into match 3 games (an important part of Act I)
those people don't make it. if you ask your boss "is this game fun" and he doesn't give a straight yes or no answer, he's not going to make it
like if he says "it doesn't matter if the game is fun so long as it makes money"
that's what i am talking about
or "it doesn't matter if the code is written well so long as it's delivered on time" or "it has to work"
"(because things delivered quickly will make more money)"
you ask for an opinion about whether or not something is engineered well, and someone like me will give you one. your bosses might not!
when i was very early in my journey i used to say "it doesn't matter" a lot about whether or not code was well written, so long as "it works"
you know i was once the villain
If I bitshift a max value uint << 8 are all the 1's that are shifted out just deleted/ignored and we basically get 0's on the right?
Thanks yeah I already tested it, just got lazy on the end bit of the work day 
found this thing here, havent tested. https://github.com/wbish/jsondiffpatch.net
Could work with
Newtonsoft.Json from git url
when was this & what position were you in?
good luck 🙂
when i had to write a lot of software very quickly because a nepo baby said so
and i said something like "as long as it works" to a subordinate and i feel like i set him back a lot. in retrospect, if the product is going to fail anyway - most games fail or zero people play - you might as well write it well
makes sense
and it can be fun and zero people play, which is why i also ask if the game is fun
it takes a long time and not much respect for money to make a fun game
what do you do nowadays?
most of my day to day experience comes from building games, almost all "branded" games, or supporting other small teams that do, via an instant games delivery platform i develop and relationships with advertisers.
if i didn't have this technology i would probably try to make a game for apple arcade
my one full time colleague was a modder of one of my games
not an easy feat at all
but yeah cool, ty for sharing, can’t say i’m not jealous - feels like the work would have lots of satisfying moments
at least for me, being Just Another Web Dev ™️
err, well unless you have a map of the fields, it would come out the same?
so I'm working on some code to generate an isometric castle, and rn its patterened in a builder pattern to make the castle and it uses method chaining to return the object between each generation method pass/call.
Currently i'm on the MakeRooms method but I'm not sure if I should use random walks thru a block of tiles, or if I should use binary space partitioning
I'm thinking BSP as it seems like a cleaner way to divide the space, and then I just drop doors on the partitions, well inbetween them really
cuz rn I just have a block of usable space in the middle of an outer ring wall and corridor, with walls and floors separated out onto their own tile maps.
and a list of the tiles positions
For something like a castle BSP makes more sense imo
Looks cleaner and already fits into a rectangle
yeah thats what I was thinking, the random walks might just lead to a bunch of dead space or like.. "caves" or something
Seems like a good idea to me depending what is your objective/scope. You might struggle more with uniformity, props placement and you may find yourself with odd room sometimes, but at the end you would have something different than most other game in the same vein.
Using unity editor window, I make changes to references in my scene objects it all works but when i change the scene and come back it is gone, do i need to write specific code to serialize it? Cheers
SerializedObject.Update() and SerializedObject.ApplyModifiedProperties() to the object you're modifying should help.
SerializedObject.Update() -- Call this before any lines of code that display the values of the object
SerializedObject.ApplyModifiedProperties() -- Call this after changing the values of the object, possibly at the very end of the method call for OnGUI if it's all in the OnGUI method.
If you need to create a serialized object, the object you're serializing must be a class that inherits from UnityEngine.Object - which would be done by doing
SerializedObject serialized = new SerializedObject(objectYouWantToModify);
let us know how you get on with this, would be interested to see
if I extend RawImage and add some values, do I have to write a custom editor for them to show up? I already tried [SerializeField]
A'ight y'all I need a genius to help me please. I've been stuck on this mf problem forever
Since nobody answers me when I type it out
here's a gif
this needs a solution cause i've been stuck on it for 12 days
Quick question, does the Grip R value changes after you moved Test_Gun (I am not a genius, but I am still trying to help 😅 )
let's find out
No they don't
at least not the local values
idk how to check the world values
but the world position of the target moves with the gun itself
but the arms don't
Maybe, you need to rewrite something yourself so the arm follows the other object
is there a way to do that without making it jittery and lagging behind?
If you write code that works on every frame yes
I got a problem like that at some point, but it had nothing to do with 3D animations
how would I set the left arm's target to the position of the left grip?
the code I'm using doesn'twork
i did iktarg.localPosition = lgrip.localPosition
iktarg.transform.position = lgrip.transform.position
neither of those work
the arm does some weird stuff
and it's jittery
I am really confused as to why the arm can move around in the video then 😕
Can you send a video?
It looks like it doesn't follow the right transform(position)...
But it seems like it would work
That's really weird how it looks like
I don't think I help more than that sorry
no idea why i'm running into these issues and apparently it's impossible to fix
Are you sure as to what the transform actually is?
Because the code seem to work
I really feel like it's an editor thing.
that's the object that it's supposed to move to i'm 100% certain
and the target it at that specific position
but the arm isn't
(edit) message here : #archived-networking message
You should definitely not be doing RPCs in Update. But also #archived-networking
That's what I though, and also sorry, I didn't see that channel.
I may not able to help you directly, but I most say that if you are stuck on this issue for more than 12 days you may want to try something else.
Instead of solving your actual issue, you could try to replicate some example that are supposed to work. By doing so, you might find was is wrong with your current setup. Personally, I have used Final IK and it is definitely not easier to setup and I had to take a step back multiple time to try to understand the asset.
There is a lot of documentation online. Here are some that could be useful:
https://m-ansley.medium.com/setting-up-an-ik-weapon-system-in-unity-1-f354ba13ff52
https://www.youtube.com/watch?v=fB0P0C_3sPU
https://docs.unity3d.com/Packages/com.unity.animation.rigging@1.1/manual/constraints/TwoBoneIKConstraint.html
https://medium.com/nerd-for-tech/tip-of-the-day-ik-101-in-unity-3f79c42ae0ce
https://docs.unity3d.com/Manual/InverseKinematics.html
https://www.youtube.com/watch?v=acMK93A-FSY
Although I have already tried changing how I did things to find a better solution but the end result is always the same. However, this by far has been the only and best response I have received in any of the Unity support servers I'm in so I thank you very much for the reply. Those links have definitely helped I'm going to see what else I can do
is final ik worth getting it being 90 bucks and all?
As a company yes. As an individual, definitely not.
why's that 😂
It is a really powerful tool, but every powerful tool is not necessary the easiest to use. In other words, you are going to be able to do more thing, but you won't do them because you won't have the time to do them.
If you are in a company setup, you have more leeway for such extravagant thing.
Hello, I need quaternion help. I have this code:
Quaternion dif = Quaternion.Inverse(t.lastRot) * t.transform.rotation;
if (dif != Quaternion.identity)
{
float mag = t.points[i].position.magnitude;
t.points[i] = new PointsList.Point((dif * t.points[i].position.normalized) * mag, t.points[i].rotation);
}
Which i am using to update some points around an object. The Point you see me creating is just a struct holding a Vector3 and a Quaternion, and points is just an array of these.
When I rotate my object 360 degrees, my points rotate around the object twice. When I rotate my object 180 degrees, my points rotate around the object once. Therefore I've concluded I need to somehow "divide" the difference I'm getting by two. I tried doing Quaternion.Slerp(Quaternion.identity, dif, 0.5f) but to no avail (it looks like that rotates it 1.5 times per rotation instead of twice. How do I get it to rotate around the object 1 for 1?
is your goal simply to rotate some points with the gameObject? because if so you can do that a lot simpler
What way? I'm using quaternions because I'm trying to get more comfortable using them.
transform.TransformPoint
I don't understand how that would be used to rotate the point around the object, sorry. Can you explain?
not around the object, it converts from local to world space, so it essentially rotates with the object
I thought you wanted to rotate some points with the gameobject not seperatelly around them..
My question now do you want when you rotate your gameObject, that the points rotate with it? or do you want to rotate the points seperatelly from the object with some specified angles or something idk..
yes I do, I didn't realize that would do that. However, I would still like to recreate that behavior with quaternions as I would like to use quaternions more often so I'm comfortable using them, so when I do need to use them I have an idea of what to do.
When I rotate the gameObject my points should rotate with it. What I'm doing right now works, except that they rotate exactly twice as fast as the game object.
to my knowledge you would actually just need to do: Vector3 p = transform.rotation * somepoint;
hmm, is there another way? I forgot to mention the reason I'm doing it this way with the difference is because it's inside the OnSceneGUI() method, so if I do it like that it constantly rotates the point around it, since it changes the point that would be somepoint, so on the next call it rotates it again.
not if you don't update somepoint but instead update a different point like p and use that instead
so I'd have to store the original points as well as the new points?
that depends you would update the new points every event call anyway so you wouldn't really store the new point but I suppose it depends
but what you could also do is multiply some point with quaternion.identity and then multiply it again with transform.rotation
hmm, I'll try that.
Looking for a second opinion here. I'm working with a team on a game (slated for mobile and PC) that has a ton of skills (moves that characters execute). So far there are 350. At first I thought to use scriptable objects for the skills and their effects (buffs and debuffs), but they're too complex and too unalike, in what they actually do for SO's. So I opted to go with setting them up as classes...and the characters are SO's that have an array of Skills and each Skill has an array of Buffs and an array of Debuffs. It looks like this...
public class Costume : ScriptableObject
{
public Skill[] Skills;
}
[Serializable]
public class Skill
{
public string name;
public string description;
public SOGem requiredGem;
public int requiredGemAmount;
public int damage;
public Buff[] BuffsGiven;
public Debuff[] DebuffsGiven;
}
[Serializable]
public class Buff
{
public Skill skill;
public BuffType buffType;
[Range(0.0f, 1.0f)] public float chance;
public int duration;
public int turnsLeft;
public int amount;
public int stackLimit;
}
[Serializable]
public class Debuff
{
public Skill skill;
public DebuffType debuffType;
[Range(0.0f, 1.0f)] public float chance;
public int duration;
public int turnsLeft;
public int amount;
public int stackLimit;
}
Problem is the more I comb through these skills and what they do, they more complex and specific they're getting. Forcing me to have to add more fields to the classes, and more if checks in the game's logic. I'm thinking it might be better to just make each skill it's own class, and write specific logic inside that skill for what it does when used. Looking for insight because as I said, we currently have over 350 skills, and more will be added.
I think for specialized behavior for skills you'll have no choice but to make separate classes or have everything in one super class. Correct me if I'm wrong anyone, but I just can't think of a way to have different specific and complex behavior be generalized to a single class.
I say writing the logic that handled for each skill, and putting that in an "action" class is a good way to handle this. Which would be using whats known as the command pattern.
yeah with an ability system you basically have to design an entity component system from the ground up
and at a certain point ECS can be difficult to maintain with a large enough code base
you sure you need 350 skills? maybe you can condense them to much less.
If that's the design of their game, that's the design of their game. Personally I would probably set up some sort of system with events or delegates that I can then just invoke to run whatever code I want, and have a base set of variables modifiable on the character. I have no idea about the design of your game, but if there's bullets for example if a skill replaces bullets it could simply replace the delegate that is usually invoked when a bullet is created.
this might be possible, if you look at the sample code, buff and debuff are essentially the same class and differ by a single field and by name
so you could redesign some of the skills to remove redudancy and use more inheritance as a way to reduce complexity
cuz buff and debuff could both become affect or effect or whatever, which could have a either positive or negative (1 or -1) field
I'm just the programmer. I've talked to the designer quite a few times already about trying to get these effects to be as reusable as possible, but I think we've come to a head in that regard.
ah so fair, if you are programming but don't have control over the design you might have issues. so much of coding is either making smart design choices or living with someone elses less then smart choices.
So the issue isn't with the buff and debuff themselves. The issue is with when they're applied, there's a lot of specifics to check for. How many turns they last. Can they stack. How many times they can stack. If you're capped on stacks, that means you can't use the skill again. If you have a certain buff, you can't gain energy towards certain other skills.
It's extremely robust.
so the issue is really with the conditional check logic?
like you almost need a flag system and a conditonal check parser/handler
like if flag X Y and Z are present then do behaviour A, but if X isn't then do B type of stuff?
hrmm, that kind of reminds me of bitwise operators and how Unity uses them with enums. Maybe that could be of use?
Like this:
currentEnumVal = enum.valAll;
if(currentEnumVal & enum.val1 == enum.val1)
// runs
of course with 350 skills that would get pretty complicated
YUP! 😣 That's why I thought making each skill its own class would be simpler. More work, but simpler.
I would probably use a flag system that reduces the amount of possible checks I have to do, or atleast attempts to simplify them
(it doesn't have to be used with enums, it could be used off anything technically)
Well actually it would be making the CHARACTER its own class, that holds the skills and logic for them.
There are far less characters than there are skills.
yeah, thats basically an entity component system
you have entities, ie characters
with skills ie components
and they mesh together, each its own class, to handle the logic
could you create scriptable objects that contain a a predicate or something used for like a search result on a list? Then you could create a few different scriptable objects for different needs and use those?
Then you could search through idk the list off buffs/debuffs applied and if that predicate returns true for being able to be applied, apply it?
you almost need like a...
uh
truth table
like you write all the abilities into the columns, and all the abilities into the rows
and write a 1 or 0 if it can activate for the other ability
tho that doesn't necessarily map out multi conditional checks beyond 2 at once
That's exactly why the logic is getting out of hand and slowly becoming unreadable code.
cuz you gotta look at the big picture and see where you can simplify
opinions on this Doc?
yep
ye
this is a difficult problem tho, thats why none of the answers feel like a perfect fit
I think either your system will have to be very large or very complex tbh.
cuz there is no easy answer, and the problem itself is thus hard.
i would create the table dynamically btw
oh shiet eh, you could create an n-dimensional array or something..
Well the reason we strayed away from scriptable objects is because the values of the data in the buffs is so wildly different. While we have 350 skills...there could very well be 10,000 buffs because of variations. Sure the buffs might have the same effect, but the amount of turns they last are different. The chance of it sticking is different. Etc.
create the conditions based on a for that loop the skill tree
part of checking if a buff is applied is if the timer is at a certain stage?
Buffs are stored in a List on the player class. So we just check the list. And we can ascertain further info (turns remaining for example), but looking at the element in the List.
yes but why would the time remaining matter when checking if a buff can be applied?
maybe I did not convey what I meant good enough?
Not a scriptable object for each buff
a scriptable object that contains a predicate to search the list with.
Because some buffs can be stacked, but only up to a certain amount. So you'd have to see how many stacks can be applied, and compare it to how many stacks the player currently has.
yes, a predicate in a scriptable object would work with that
count how many buffs in the list of the specified type, and if it's less than the max let it be applied
use a table with fixed number of max elements then when the buff appear fill the condition with true or false
use an index or something like that
to match the condition
you can use a table or a list too if the list is filled like a 2d array you can access it such as it is a 2d array
So like have a method on the character class that receives a buff, then take a predicate from somewhere, perhaps that buff, and check the list based on that predicate. If that predicate is true, then the buff can be added.
Okay. I see where both of you are going.
for having buffs stop other buffs from being added, you could create a field in the buff and bitwise that with the current buff.
like this maybe?:
compareBuffExclusion = 1;
thisBuffExclusion = 5
if(thisBuffExclusion & compareBuffExclusion == compareBuffExclusion)
// can't add
Which would give you a very large amount of flexibility.
so 1 would exclude every odd number, but no even number. Meanwhile 7 would exclude 15 and 31 and 63 and so on. And 0 would exclude nothing, meaning it's never blocked. And 2 would exclude every even number. Make sense?
That's just a solution for buff/debuff type, not the other situations
did you make it work
gonna try soon
doesn't work, this is what happens:
By looking at your code, I already see multiple thing that could be "generalise". I currently work with a system that hold a large variety of Skills. What we did is we divided the code in multiple module that are organise in a workflow. We then customise each part of the workflow independently. For the skill that are the most unique, we have specific class/module for them. In fact, most skill start as "unique" and we then refactor them to be more generalise when it is necessary/useful.
Something like:
public abstract class Visual
public class MultipleTarget : Visual
public class LineTarget : Visual
public abstract class Condition
class Range : Condition
class TargetType : Condition
public abstract class Effect
class ManaCost : Effect
class Damage : Effect
class Buff/Debuff : Effect
public class Skill
private Tooltip tooltip
private Visual[] visuals
private Condition[] conditions
private Effects[] effects
public class ReallySpecificSkillThatCanNotOnlyBeExpressWithTheRegularWorkflow : Skill```
Anyone know if it's possible to embed a Roslyn static code analyzer in Unity?
To rotate a point around an other you can use Transform.RotateAround or simply use a localPosition and rotate the parent.
If you are not able to use this function because you do not use directly a transform you need to
First, translate the point such as the coordinate of the point is express by the second one.
Second, you apply the rotation to your point.
Third, you re-translate your point.
Vector3 a;
Vector3 b;
Quaternion r;
Vector3 delta = b - a;
Vector3 rotatedPointInFunctionOfA = R * delta;
Vector3 result = rotatedPointInFunctionOfA + a;
The documentation provides some information on how to use Roslyn code analyzer in Unity environment:
https://docs.unity3d.com/Manual/roslyn-analyzers.html
This is for analyzers and source generators, I want to perform static source analysis from within Unity itself
To be exact, Inside my Unity project I have some certain methods I need to track usages for (everywhere the method is called, I need to know the arguments).
So I created a separate .NET 6 application that use: Microsoft.Build.Locator & Microsoft.CodeAnalysis.Workspaces.MSBuild.
I launch that application from within Unity, with arguments for the Unity solution file, from within the application I load the Unity solution, perform my analysis, and send the data back to Unity through a NamedPipe.
Now instead of performing the analysis externally in a separate process, I'm wondering if I can do that analysis right from within Unity, basically move my .NET 6 application code right into Unity.
I tried to do just that, but the libraries need for static analysis are giving me trouble, specifically MSBuildLocator & MSBuildWorkspace; they keep giving me type loading errors.
interesting.. not sure, looks like its reseting to its indity rotation and then snaping back to the transforms rotation
I figured it out. Quaternion.Slerp to 0.5 was working. I was just using Trasform.TransformPoint in another part of the script, for position, so it was rotating it twice.
lol
Are you sure you really need static analysis ? Can you just use the "Find All Reference" function of Visual Studio Code or Reflection directly from C# ?
If you are doing this to keep your Code clean I strongly suggest to use light tooling/linter and focus on better practice.
So on the topic of a more unique ability system, I'm walking into a roadblock with mine currently as I'm trying to figure out ways to make some abilities that are beyond a simple fireball or spawning a pool of lava. Currently, I've my ability class split into different subclasses: projectiles (chain, fork, homing capabilities), area effect (size of area, incremental damage), and direct/instant damage ability (just apply effects and debuffs).
It all works out pretty well, and I can create a large amount of abilities with SOs this way, but now it gets to the point where I want to make something like a meteor spell that creates pools of lava when it falls from the sky, or perhaps an area effects where my pools of lava spew out fireballs nearby. There's this mixed logic going on and I'm feeling like I can probably achieve it doing the ecs way, but if anyone has a better way setting this up or any information to create a better ability architecture class I would appreciate it.
Can anyone here help me to create a CJK font asset so that player in China , Japan and Korea can play my game please? I'm using a main font with 4 fallback Chinese fonts and I still don't get all characters/glyphs to show ( random white squares in some otherwise translated text) I would be very appreciative.
Not sure what ecs has to do with it, but you could create a class for "compound abilities" or something, that can chain or parallel execute other abilities.
I do have some functionality for chain execution, but even then, it's similar logic with a few differences written to each of these sub classes. I've a few ideas to how I may want to rewrite this. One, ditch the abstraction and just make a super class, but this would allow the possibility for creation of abilities which would fail to work if not careful. Another idea would be keep the abstraction as I have and go a little deeper into the hierarchy, creating classes for abilities which share more similarities.
Can you provide a specific example of a problem with my suggestion?
There's just so many small problems I can think of like, what dictates when the ability is finished? How should I handle the GO destruction if I am combining abilities and such.
Probably the main ability. If it's chain ability, then it should control the underlying chained abilities.
Here's an idea for an ability. A simple projectile which can collide, and when it does then we destroy the GO. But let's say I want to add like a trail effect, which leaves like poison behind. How would we go about creating a class to handle this specific combination logic?
Not sure what GOs have to do with anything though. We're speaking about abilities execution logic. If there is any go instantiation(particle effects) and destruction involved, that should be handled by the ability that needs these GOs.
Perhaps a chain a ability that executes a projectile ability first, then a "area of effect over time" ability.
The second ability in the chain could have access to the info of the first ability for context. It could retrieve the start and end points to create the area from it.
Yeah, easy enough, but this we get to the question. If I have these sub classes which dictates which is the primary functionality of these abilities (projectiles will always have that specific logic in the update), then what do you think would be the best way to combine both of these logics if I were to make a ability that starts as a projectile with area effects, and an area effect that shoots projectiles
If you understand what I mean
Because I find myself rewritting similar logic for both of these classes
Because how it really is, the sub classes are the conditions on how the ability behaves primarily
Projectile sub class has access to tags such as chain, fork, home, ect
The area of effect ability could have an optional action on tick(or on certain timer) that it could execute. You could hook another ability as that action into it.
I'm not sure what kind of logic you're rewriting. I didn't see your code. That's why I was asking about specific cases where you have problems.
Ultimately, you'll have to hard code something. An algorithm, logic. There's no ultimate generic solution that would magically fit all your cases.
Yeah, the logic is looking is becoming entwined with the other derived classes. Since you see if you do area spell to projectile chain, then you have to factor that transition and write specific logic for that.
So I'm trying to figure out if just keeping it as a super class would make more sense.
That's probably the issue. Even if you do need to hardcode it, you should avoid dependencies on other classes. Make interfaces if you need to retrieve certain info instead.
Or use some kind of context object that you pass between the abilities.
A large reason why the classes are divided as well is because there is logic specific on that ability type that is casted, such that it can be forward from the caster, or spawn at the location of the mouse.
If it's "spawn at a location", that doesn't sound like a projectile anymore
Unless, you mean that it then proceeds to fly towards another point
In this case, it would be solved easily if the projectile had a start and end point properties. This way it wouldn't matter for the ability where it is executed from. It only acts upon the data that it is given.
Oh, I've logic for fireballs spawning at a location which then disperse in a direction I give it. Just some extra fluff.
Yeah, in this case what I said above.
Probably most complicated thing I've worked on so far. Just not many good examples out there to get an idea how people are doing theirs.
The idea is to inspect your implementation and find points that you can make more generic/abstract and eliminate dependencies on specific implementation.
But then you want to make something unique and you go "ehhhh".
You just find a way to fit that something into the current model or extend your model to be able to fit that specific case in a generic way.
I think overall writing double logic if I need to when chaining abilities is the right idea though. I think I would need to implement some defaults because otherwise the code may become a little too discreet and ill stuck on it forever.
What do you mean by double logic? Can you provide an example?
Similar projectile logic but with minor differences to compensate such as where the first ability is and such.
Why do you need double logic for that?
There's only one logic for spawning a projectile:
SpawnAt(startingPoint);
//...
Update()
{
MoveTowards(targetPoint);
}
I don't see why you'd need a double logic for that
Right right, I think I may have an idea now, let me see where I get with that
Overall, what I have right now is pretty nice for something simple, I just want to make a sweet meteor skill, heh
Very simple. Area of effect ability that executes a fireball ability on tick.
For the starting points of the fireballs it provides a random position within it's area for example. For the target position, either one target point or a something in proportion with the starting position or just random position around a target point.
It's more that I want the meteor to land, then deal a pool of damage. You can cheese like an area damage ability by just using vfx and making the meteor itself not included in the ability, but rather a delay before the damage.
Think of a shower of meteors maybe, and each projectile that hits does damage and spawns a pool of lava.
Well, then it's just
areaOfEffectA on tick or parallel
- projectileA
projectileA on hit
- areaOfEffectB
Abilities that nest other abilities within them.
The one that is actualy being executed is areaOfEffectA which is the meteor shower ability.
Yeah, projectile to area is ideal. It looks like I'll have to expand out how I'm doing the targeting logic a bit more, but other than that I think I've got what's here for that to work. If I have more questions ill post my code later when I expand on it a bit more ;)
ty tho
Okay, so I have a central static class that handles all the events shooting around the place. The problem is... I have a lot of events. Is there a way I can make this less... verbose... and tedious, since C# doesn't have macros (rust user alert)
can I one-line define a delegate or something
I realize since a lot of delegates are void with no parameters I can reuse some delegates, but not for all of them
Can't see shit on that screenshot. Upload it to a paste site.
I used central system before and just moved to system where script handles all of its stuff. Central system had benefits on small projects but larger, it was shit. Also you can write 2 lines in one, if thats what youre asking
nah it's just a demonstration of how long it is
oh, so I can define a delegate and an event in one?
Yeah
how so
It's hard to recommend anything without seeing specific examples of what you have.
oh, okay
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
could I use an... Action?...
Yes, you could use an action instead of defining a delegate for each event
Also, I wouldn't group all the events in one class like that. Some could be moved to QuestManager, WeatherManager, CommandsManager, etc...
Encapsulation and single responsibility principles can keep your code cleaner.
And you should not use central system i think. You get lost here so easily and just move quest delegates to quest namespace and script
Yeah ^
yeah fair enough
would subclasses be Acceptable
Also yeah I like the actions idea...
Like Metro.Quests.onQuestComplete += ...
In my own experience, its okay when you move to subclasses but after few weeks, its same shit again
How would subclasses be different from distinct classes though
Before that, ask yourself what's the purpose of the subclass in the first place?
I don't see any reason do have subclasses here.
fair point. however, I am neurotic
It would be in terms of "using" namespace you need and specially in term of organizing. If you need to see event for quest, you go to quest folder
I mean its suggestion. Honestly use subclasses and then if its shit again, move them to controllers
I made the centralized system to avoid referring to classes specifically, even if they are static methods
Subclasses are for extending and/or overriding certain functionality. I don't see how it can help with completely different events like what you have.
not inherited classes, like classes within the classes.
Well, C# is an object oriented language. You can't and shouldn't have everything global or packed into one class.
I get that it's what you're used to from Rust, but that's something you'll need to change your thinking about.
It's like using a fridge to store your clothes. Sure you can do it, but it's not intended for that.
Also with the action syntax and now that I've learned that functions can be defined with a fat arrow I can make the code Much shorter and more readable
Any sane person would have questions as to why you keep your clothes in the fridge. The same applies to your code in C# context.
my brain just kind of needs it this way, unfortunately? I dont have a solid reason. But I'll do a compromise. I will do the subclasses, but I will have Metro be a partial class, and then I will split up each subclass into its own file so it's easy to look for stuff without scrolling for a million years.
Still not sure what subclasses have to do anything with it but whatever.🤷♂️
yeah sorry
I'm using this to generate boilerplate code for my network serializer,
I need to retrieve all type usages that get serialized so I can generate code for them on AOT platforms.
I'd love to use reflection directly from within C#, but I don't think it can find usages of a certain method.
I'm not sure how advanced this is but I've been trying to make a save system that saves the exact state of the scene for hours, probably harder than just saving values. However I want the saving to be exactly the same similar to the style of the 3d fallout games
I actually talked to someone who worked on SKyrim, systems development. I asked him how the save game system worked, and he told me, quote, "If brute force doesn't work, you're not using enough." But I'm working on a similar system
He also added that he wished the guys who designed that system had "used ring/circle buffers" so do with that what you will.
My current solution Works but it kinda sucks and is inefficient, but here's how it works:
- I have an interface that marks a class as a "Save data blob"
- All the classes I want to save data for, I give a subclass with this interface. The subclass contains all the stuff I want to save; position, combat state, etc.
- A central save game routine invokes a message that all objects that want to be saved are subscribed to, which asks them to pack and send back that interfaced class
-All of this is serialized and written to disk.
When I load the game, I
-Unpack all of the data
-Send the data blob to the appropriate object
-Use reflection to determine the type, to make sure it's the correct save data blob
-If it is, unpack and apply to the object.
However, if I were not totally incompetent, I would write a custom binary serializer that forewent the reflection and type checking and all that but that's above my pay grade.
When designing these save game blobs, or whatever approach you plan to do, make sure you think about what Actually needs to be saved
like a sword on the ground should store its position, rotation, velocity, item ID, etc. A ragdoll would store all its bone positions so it's still laying there when you load the scene
Chances are you don't care how a ragdoll lays on the ground though
(unless it's a main character maybe)
that's true, but Creation Engine games do that so I was using that as an example
I still have yet to figure out how I will go about persistence of dead enemies in my project, but I'll probably do something similar to Bioshock where after a time the enemies vanish and become a lockbox with their loot in it
Another tip is if you have a Lot of stuff like I do, determine if the object has changed at all from its default state. A book in a dungeon you've never visited isnt goign to have changed since you started the game, so no point in saving its state]
otherwise your save file could get real big real quick
update to this: It's very late and I'm going to bed, but for debugging purposes I'm using YamlDotNet for my save files for now, and it has trouble deserializing abstract classes, which is why I do a bunch of reflecting and serializing and deserializing, but this looks like a promising solution I will have to look into later: https://gist.github.com/atruskie/bfb7e9ee3df954a29cbc17bdf12405f9
now that I think about it, I kind of came up with something a bit like this, but less... professional.
been a while since i wrote it.
This is for my MOBA game. I made a finite state machine for my animations and logic. I have a PlayerInputController that send an event with an order (attack, move, cast) into StateMachineManager. StateMachineManager changes the state. It also has logic for changing the state according to the order. So, If an order was an attack it would do a move state until the range of an attack is reached. My problem is that usual behaviour is that a unit can be in one state at a time. However, some spells and attacks allow to be in multiple states (move and attack, move and cast etc). How can I approach implementation of this feature? I use Animancer, so I have access to animation through code.
Two separate enums, one being for movement, the other is for actions perhaps?
Otherwise just extend your statemachine with attack and move and cast and move.
Thanks a lot, ill give it my best.
is it possible to setup automatic Syntax Transformation with Roslyn in Unity ? I got Source Generation working, but by its design it cannot modify existing definitions.
I want to be able to find all instances of a particular syntax node and replace it with another.
Now i suspect because what I want to do hasnt been done; its probably not possible.... but for context,
I want to be able to replace all null-coalescing statements with an if statement at compile time.
Yeah, by design that can't be done, but you can try utilizing partial classes and methods to work around it
Not sure about your specific work case tho
for my specific case it wouldn't be possible with just partials. I need to actually change the node itself within the tree as it compiles
or well i suppose after it compiles
I was suggested IL weaving but i really dont want to touch IL for obvious reasons
it would be nice if i oculd just slap on a Syntax Transformation like https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/get-started/syntax-transformation
You can also make a seperate .NET executable that analyzes the entire Unity solution, do the modifications and overwrites the Unity solution, but it seems like you want to keep the original null-coalescing statements in the original code?
I'm guessing you're trying to circumvent the Unity object null comparison issue ?
yeah ideally
eeeexactly
which i think it might not actually be possible; as it probably would've been done already
Good luck with that, lol, that whole comparison thing is a lost cause, might as well bite the bullet and keep writing code like it's 2017
yeah its entirely microsoft's fault for not allowing the overload
which i can understand their reasoning
but like... surely Unity could "hack" it in their compiler pipeline... but i guess that isnt really a place you want hacks
Doesn't C# by default use the Object.Equals for the null-coalescing operator?
Oh!
Oh well, maybe with future updates
i guess in regular C# development you would have this issues with Disposables too (?. wont act on if it is disposed)
I would say it’s Unity’s fault for curving nulls for a different purpose, rest of the C# ecosystem work just fine and overriding equality is frowned upon.
Null means null, “this object no longer exists on the native side” should be a separate property not piggyback off of null.
having to check if every object is "actually destroyed and actually not in the scene anymore" is annoying enough with the overloading
can you imagine if they didnt?
if (collider != null && collider.ReallyDoesActuallyExistInTheScene)
If "this object no longer exists on the native side" was a separate property; the null-coalescing operator still wouldn't work
also objects could exist but reference the assets not a scene object too 
to be fair, object references in Unity are messy to begin with lol
They wouldn’t work like how you want it to but it would be consistent with rest of the C# world.
🔥 we shall line the streets in riot and demand Unity 2
it shall be C# first, with redesigned conventions
properties shall be PascalCase
It will be data oriented
The editor will be multi-threaded
Serialization will support all the types
and it will be glorious
we will all weep
it will have a multiplayer solution built in
and only 1 UI framework
one can dream can't they
Unity objects are stubs to communicate with the actual C++ objects on the native side, “null means this stub is null” and “the other side hanged up the phone” should be a separate property.
if they do this i would just implement equals overload myself 
its just too useful.
the main issue i see is Unity trying to use C# as a scripting language
it's just... not...
no matter what C# 9 introduces
Unity wasn’t designed to be C# first and carried a lot of baggage from back when it had to also support fake JS and Python.
by scripting i mean they use it to "script" gameplay and actions. They design it not to really be a framework or a engine, but rather just glue between your items
well actually, it was more closely resembling Microsoft JScript
and TBH did anyone actually use Boo?
Unity JScript was nice tho; it was missed.
Fake JS, lol, don't remind me 😩
But in the wider C# ecosystem, it’s universally agreed upon that you shouldn’t override equality to be inconsistent, not only it affects things like null checks, it affects pattern matching, collections, and lots of other features in .NET.
I mean joke's on whoever used unity js instead of C# :p word was already out that js is not a good programming language
to be fair, unity been chilling in .NET FX 2.0 for like... up until the last 5 years
got a lot of catching up to do
this statement is probably the best reason alone to why they discontinued it....
it was not like js so saying js is a not a good programming language has no baring

the naming was horrible, everyone stealing from eachother
Java > JavaScript > Microsoft JScript -> Unity JScript (or whatever they called it... I like to call it UnityScript).

It would be amazing to have Unity 2.0 and rid of all these mistakes but at this point it’s probably never going to happen and we kind of just have to deal with it.
The fact that Unity has to have analyzer rules specifically telling people not to use some C# features like ?. and ??= is just sad.
what I would love from Unity is some way to maintain and extend the standard C# learning curve
it already kinda alters it by having the update loop, but it eventually grows messy with all the methods the MonoBehaviour contains
type this. in your IDE and see what pops up lol.. beginners won't mind but once you've had a taste of a raw .NET app dev you'll get salty
Assembly/Namespace management, all this stuff aren't enforced or even recommended in Unity's workflow
intelisense is great
Woohoo magic strings and methods (tbf imo that’s least of Unity’s offends)
i wish the latest unity didnt break the default configuration for VS
ugh i can recite how to restore intelisense by memory now
this leads to a huge Unity assembly that will eventually take a lot of time to load
Edit -> Preferences -> External Tools -> change the dropdown to Visual Studio, hit regenerate, restart unity
instead of a lot of standalone assemblies whose references you have to manage
I’m looking forward to Unity moving to .NET Core and keeping up with it so we aren’t permanently 2 year behind, that would be very nice QoL 😄
What library are you using that requires you to do that ? I have not experienced such concern and I have work with different Networking solution.
honestly it's never gonna be an issue.. there'll always be 'hacks' that change the compiler to the newest version
ngl, the IL2CPP is pretty fucking neat.
big brain move by unity to write that.
I was using alexzzz's C#7.2 compiler for Unity since Unity 2017, and it only became available natively on Unity 2019
AOT is pain; so many headaches when porting my game lol
TOO MANY TRAMPOLINES
still dont know what it means
I mean yes you can always hack things together yourself but having official support is better.
but my favourite error
IL2CPP is amazing yeah.

virus
?
joking about the bot not allowing your link to pass lol
It's my own Network Serializer.
Have you ever used MessagePack? They have a Generator in the form of a separate executable, it's used to create serialization code ahead of time to help support IL2CPPs AOT requirement
Hella buggy tho
oh yeah, gotta protect the chat from those homer simpson memes 
idk, i havn't ever ran into any bugs
other than the trampolines running out or something
i am working with mostly standard .NET stuff tho
Could you use a .NET executable that analyse the unity solution and the dump temp files (modified code the null operator replaced) that is going to be use in the build ?
I ran into this one yesterday, cost me about 4 hours of debugging to figure out
https://forum.unity.com/threads/il2cpp-does-not-generate-constructor-for-generic-classes-that-have-struct-as-parameter.997274/
sure, but how do i tell unity to use the temp files instead of the files in the project?
oh i have ran into code stripping issues to.. that took exceedingly long to debug
it aint very smart with that
Absolutely, 99% of my problems with it are code stripping issues, and it not generating the right generic variants

I haven't had any issue with IL2Cpp, but I heard they recently changed something regarding generics and broke code.
lmao the issue looks so specific 😂
It very much is, couldn't even find the Forum post until I had basically figured out the entire problem.
At least there is a simple solution to this.
Most of these IL2CPP problems are easy to fix, just difficult to figure out to begin with
That could require to move your original code in a different assembly that won't be use in the actual build. You can then add the modified code in the assembly you want to be build
No, I never used MessagePack. That being said, I used Photon, Netcode For GameObject and Mirror which did not have this issue.
It is not that messy in my point of view. Assembly is a pretty well integrated feature. When I say move, it is actually just to create an Assembly definition file. https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html
Photon is very limited serialization wise. Network for GameObjects (terrible name btw) and Mirror do IL weaving, a good solution, but not something I'm willing to do at the moment.
Oh well, guess I'll just stick with the external application approach.
Thank you for your help.
do you have a screenshot of your game?
also there isn't a point to write all this automation for video game serialization. you'll transfer closer to 10-20 distinct different types, which is easy to maintain by hand
so it's kind of pointless when in 30s i can write a file that instantiates those 20 types in a Start that il2cpp seems to be missing
if you're trying to transfer generic lists via the network, well you have other issues with representation. why reinvent protobufs
Why do something in 30 seconds, when you can spend 2 daya automating it 🤷♂️
you will look at your List<?> usage and see it will have like three derivations
lol
it is telling you there is a flaw in your approach, not that the decision is between automation or not
anyway do you have a screenshot? just wondering
I can give you source access if you send me your email
Screenshots are kind of hard because it's a big project
It's not really a game, just a networking solution
ah
That's why I'm trying to make it as generic as possible
Can anyone share with me how they structure their IK system when creating an FPS system? These tutorials on YouTube all show for third person and it’s not necessarily the same thing
It’s not animation.
If I wanted to know how to animate the IK I’d ask in animation
I want to learn how to program it
IK is inherently part of animation. Unless you're writing a custom IK system yourself
Look into the FABRIC and CCD algorithms
I want to learn the programming side
First/third person doesn't really matter too much
Since Unity’s animation rigging package is kinda wonky when it comes to the structure
I thought so but when I set it up like they do for TPS
You just need a chain of Transforms and an effector
it doesn’t act the way I need to
And the arms kinda go wack
So it doesn’t need bones to work?
TBH you might just be setting it up incorrectly
Nah man unless every single YouTube video is doing it wrong
The chain of Transforms are the bones
Oh
Bones are represented in unity as individual GameObjects with transforms
That's what the skinned mesh uses to deform its vertices
I get that but the issue is that the only way I can get the arms to move when the parent of their targets move is by actually putting the entire shoulder down inside the gun model with the targets
But as you can imagine when you shoot or aim everytbing moves and not just the hands going backwards
I’ve tried using the multi-parent, and transform but no matter what it’s dead set on being difficult
I tried setting the position of the targets to the grip positions but it didn’t work well
But it worked better programmatically than it did with just the constraints
Not sure I follow this 🤔
Doesn't seem correct
Where did my gif go from yesterday 1 sec
In that gif
The targets for the hands are in the gun models
Model*
You move the targets directly the arms respond accordingly
You move the gun model that is the parent of the targets
Only the gun works
Any idea how to implement mvvm architecture with unity?? Are there documents on it?
I am currently trying to render multiple layers with different frame rates with HDRP. Has anybody experience with this? It feels like every way is leading to a dead end.
I kind of got it to work with two layers via a render texture and a custom pass volume but this solution seems to break apart with more than one layer
Compositor seems like it would be the goto solution here but the compositor does not allow me to manipulate the cameras in a way to effect their framerate
And when using textures (render textures) they have to exist as assets which leaves me unable to scale them to screen size at runtime.
what is your goal?
what is the effect or purpose of this
UI Toolkit give you binding capacity. I'm still using the hold UI System and I have yet to test the new solution (UI Toolkit). If I remember correctly, the solution is not production ready for realtime UI.
You can also develop your own widget and add binding capacities.
Also, MVVM might not be the best pattern to be use in video game development.
https://docs.unity3d.com/Manual/UIE-Binding.html
https://docs.unity3d.com/2020.1/Documentation/Manual/UIE-Binding.html
I am building an animated desktop wallpaper. The background is not changing often but uses a lot of performance. So I want the front which needs to change more often to render independent of the background
The wallpaper reacts to spotify changes so most of the stuff only needs to update for a few frames when the song changes
And why you use Unity for that ?
okay based on your message history it sounds like you've been at this for a while
the solution depends on how you are drawing to the desktop
what is the command line for starting the unity application that you use?
I am currently using Wallpaper Engine to render the background. But that is not the problem for now. Atm I am just trying to make it work standalone and in the editor
okay
this is kind of a moot point then because then it's up to wallpaper engine to draw as frequently as it wants
you can call Camera.Render() at any frequency
everything else follows
Yeah I do. That works great for one camera. And I even got it to kind of work for 2. It somehow breaks down with three. The problem comes down to compositing
the rest of your approach doesn't make sense
it's not significant how many cameras you have
I can render 3 render textures at different framerates but I cannot merge them
it depends on how you are drawing to the desktop 😦
you would have to know more about how wallpaper engine works
But rendering the 3D background takes a lot of time. If I only render it once and than just update the foreground rendertexture and batch them it is a lot more performant than rendering everything every frame.
i know
anyway it sounds like there is a lot for you to figure out
you should explore the meaning of clear flags
I know how clear flags work. Thats why I use mutliple render textures. Otherwise the foreground would overwrite the previously rendered background
Why you cant merge them ? It seem like something pretty easy. Shader/Stencil buffer.
when rendering with multiple cameras all drawing to the backbuffer, they do so directly. this is a limitation of your approach. render textures do not need to be assets
you shouldn't be interacting with a stencil buffer or anyhting like that
Why not ?
you can request a "correctly" sized render texture using RTHandles
from the core rendering package
you can also take a look inside the hdrp package to learn more about how rendertextures are allocated and how they deal with resizing the screen
in custom passes using rthandles happens automatically
Yeah, right we are working with foreground and background
Thats the problem for me right now. Finding the best place to merge and present them
I am currently doing that with a CustomPassVolume
That would be a shader. At least, in my opinion.
But that does not work quite as expected
Yeah obviously. But the shader needs to get references to the render textures and it needs to render to a fullscreen quad
you should not be authoring a shader to achieve this
if you are doing that, you are going to have bugs
Explain
if you are manually calculating the render texture sizes, that is the wrong approach - however it does seem unavoidable. like i said it depends how Wallpaper Engine presents to the screen
the problem is it sounds like you don't know
or you haven't told me yet
so it's very hard to be helpful
does your application work without trying to modify the framerate change?
i feel like you've written a lot of code, a big cathedral, for something that is way simpler than you thought :/
Wallpaper engine just grabs the render result from Unity and it looks exactly like it is displayed in its standalone window
this isn't the kind of technical answer i was looking for
it's okay if you don't know
do you have multiple cameras rendering correctly at default frame rates right now?
Isnt a RenderTexture just a Texture ? Like you can pass the reference in the shader.
but wallpaper engine is not the problem here. it might be able to limit the overall framerate but it will never be able to render different lalyers at different framerates
okay well
Yes it is. But they cannot be resized at runtime. The need to be recreated. So I cannot use Render Texture Assets. They have to be created and assigned in code
Which makes it problematic to use with compositor for example. As the compositor expects a RTAsset
do what you need to do. i suggest looking at this package: https://github.com/alelievr/HDRP-UI-Camera-Stacking
you shouldn't use the compositor
render textures can of course be resized at runtime
you don't need render texture assets
or whatever you're talking about
you don't need shaders. you shouldn't author a shader
Thanks I know this package and I am actually using it. Although it interferes with the other layer stuff atm
If you look at the package you just posted the render texture gets released, resized and recreated
it is recreated
okay well i think you can figure this all out, sorry i can't be more helpful
I tried doing that with an existing RTAsset. It looses the reference to the asset. It is not the same RT anymore
you should try to make your code work very simply in the beginning, without modifying framerates or authoring a custom pass. you probably want to revert in git to this stage of your visualization
you don't really need ui camera stacking
i am showing it as an example of something else
but it sounds like you have written a lot of code, and there's a lot of inertia
I didnt actually 😅 It is a lot more about trial and error what works in the editor
you can simply disable cameras and call Render on them at the right time. use a target texture "of the correct size" (lots of ways to achieve this). the RenderTexture object, when you call Destroy and Create, does not change, only the underlying native texture pointer does. but that's not your concern
Thats most of the code I use to render at custom frameworks atm:
private void OnEnable()
{
this.camera = GetComponent<Camera>();
this.camera.enabled = false;
//this.camera.forceIntoRenderTexture = true;
this.renderTexture = new RenderTexture(1, 1, 0, this.graphicsFormat, 1);
}
void Update()
{
bool forceUpdate = UpdateRenderTexture();
if (!this.Render && !this.firstFrame && !forceUpdate) return;
this.firstFrame = false;
this.elapsedTime += Time.deltaTime;
if (this.elapsedTime >= 1f / this.TargetFramerate || forceUpdate)
{
this.camera.Render();
this.elapsedTime = 0f;
}
}
okay well, it goes without saying you need the right size as a first step
but i think you probably experimented with that
you also should not be doing this in an update
it should be in a LateUpdate. ideally, you would do this using unitask in LastPostLateUpdate
The RT size is correct. Its basically a copy paste from the UICamera package
LateUpdate is a good point
you have to do this all in one script too
since you need to carefully control the order the cameras are rendered in
I remember seeing something similar in a recent Unity video. I do not know if it can be useful for you. https://www.youtube.com/watch?v=LrAOkMRlvjo
buuuuut to mix it you should extend the default draw custom pass instead. because you still need a reference to the backbuffer, and in the right order
anyway i gotta go
this is... pointless to be honest
Also,
before you waste your time anymore on what you think is an optimization, try setting Application.targetFramerate = 1, and see if this has any meaningful improvement on the metrics you are measuring
inside wallpaper engine itself
It absolutely has I only set it to 30 and my GPU went from 60 to 30%
i'm saying in wallpaper engine
gpu utilization doesn't mean what you think it means
i don't know what sort of subjective metrics you are after either
if you don't want a dynamic experience, don't use unity
well I will figure it out. thanks for tying to help
Thats intersting as I was sure that I read elsewhere in the docs that resizing is not possible 🤔 And the UICamera package is also releasing and recreating it.
To be honest, I do not think Unity is the correct Engine for what you are trying to achieve as you gonna deal with a lot of overhead. I would agree with doctorpangloss that if you do not really required Unity functionality, you should try to find out an other engine that has less overhead. You could even try to come up with your own and it should be pretty easy as you do not seem to have a lot of functionality that you require.
That being said, you can definitely use Unity if you just want to poke around.
Well atm I do not know any better engine or technology to render dynamic realtime 3d objects with post process effects as a wallpaper 🤔 Maybe URP would have been the better choice though...
Hello everyone.
I am having issues adding the following script for my multiplayer "Pique Pegue" game in Unity using the Mirror asset. The script is meant to check for collisions between players and change their respective "Player" and "Caught" classes, where "Player" is the "not caught" and "Caught" is the "caught one".
The error is that nothing happens after I attach the script to the character, even though I have added a Box Collider and made it a trigger by checking the "Is Trigger" option. What could be the issue and how to fix this error?
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using Mirror;
public class PiquePegueSystem : NetworkBehaviour
{
public GameObject canvas;
private string _playerTagInocent = "Player";
private string _playerTagSus = "Caught";
void Update(){
if(gameObject.tag == _playerTagSus){
canvas.gameObject.SetActive(true);
} else {
canvas.gameObject.SetActive(false);
}
}
private void OnTriggerEnter(Collider _col)
{
if (_col.gameObject.tag == _playerTagInocent && !isLocalPlayer && gameObject.tag == _playerTagSus)
{
gameObject.tag = _playerTagInocent;
}
if(_col.gameObject.tag == _playerTagSus && !isLocalPlayer && gameObject.tag == _playerTagInocent)
{
gameObject.tag = _playerTagSus;
}
}
}
This looks more like a question for the #💻┃code-beginner channel to me. But I would recommend you to either use a debugger or put debug logs into your OnTriggerEnter method to see if it gets triggered at all and how far it gets.
No problem.
I can fix this error now.
I'm trying to get a better grasp of the Playables API. I'm wondering how to set the starting length of a playable when creating it so that when it appears in Timeline it will have a default length (clip length).
The SetDuration extension method doesn't have any effect.
Why do u think mvvm might not be best and what u think cld be a better architecture for game dev
Overriding the duration of PlayableAsset gets the desired result, it looks like.
The start time of the clip is another story. My custom playable seems to have an arbitrary start time on the timeline..
I'm not sure about what is CLD, but I do not think that MVVM is the best approach for game development because the flow information is mostly from the game to the UI and that the game usually does not have a clean structure that can be easily bind which give the ViewModel component an extensive and not optimal task. Finally, MVVM requires the usage of data-binding which can be annoying to deal with even more when you work with complex data structure like you usually find in games.
MVVM, in my opinion, is better suited for application that requires intensive input from user and that have pretty simple structure. Something like a Survey.
Cld was could 🤣 but thanks for input, I have similar views just trying to see wht cld do well for games but answers all patterns hv drawbacks
Keep it simple. That is what you should do. Usually, you start simple, and then you complexify when the needs come.
If you are a solo developer, I would even suggest you to keep it dirty unless you really need to refactor because you are not able to get the functionality you want.
Yea, I just trying implement different patterns and see on a dummy projects
UI Toolkit is definitely something you should experiment if you have not.
Is there a good way to search for Mesh assets via script? I have an item spawn system that receives item data from a server. I kinda want to instantiate those items dynamically without having to attach 100 [SerializedField] properties that represent all my meshes in the asset directory
Use Resources folder or addressables?
I just found AssetDatabase.FindAssets that works fine so far
However - anyone has an idea what type the select asset is in the screenshot? It's an .fbx file and it contains a Material and a Mesh. But what is the name of the asset log itself here?
AssetDatabase.FindAssets only works in Editor.
Oh - shat alright thanks for the hint 😭
'log' here would be a game object.
If you want to retrieve the nested assets then you can use the AssetDatabase.LoadAllAssetsAtPath method
https://docs.unity3d.com/ScriptReference/AssetDatabase.LoadAllAssetsAtPath.html
Yeah but I need it in the game and not only editor as @dusty wigeon mentioned
@pale pier, I was looking around for my own research and found this piece of documentation that maybe could be useful for you. It kinda look like what you are trying to do.
https://docs.unity3d.com/Manual/ScriptingRestrictions.html
When the compiler encounters the explicit call to OnMessage with a T of AnyEnum, it generates the proper code for the runtime to execute. The method UsedOnlyForAOTCodeGeneration does not need to be called; it just needs to exist for the compiler to recognize it.
Question: If I have a class that starts to exceed 800 lines of code, should I start splitting it into partial classes
or, rather, make it partial and split it over files
No you should separate the class because it would have more than one responsibility
I guess I need to refine my definition of what a Responsibility Is, because this particular class is an NPC in the game, and I've considered that to be a single, if large, responsibility. And this class is not a monobehaviour
You could separate the NPC behaviours into separated classes for example, while using your current class as facade
I've Sort of done that with a few things... but you mean like, separating out pathfinding, and AI, and scene presence, into separate classes, and then having the NPC class be a bundle of the other classes?
Yeah sure, that's composition
And you can reuse those classes for player if it has shared behaviour
I’ve been doing housekeeping the past few days and I think that an issue I’ve realized I have is that when I designed this system I created a large inheritance hierarchy but now I realize I should have been using interfaces and composition but man restructuring the Everything will be such a pain
God help me
Curse past me for not knowing what an interface was
But I suppose it will be worth it for scalability and maintainability
800 lines of code is not that bad though.
And I guess if I ever port everything to DOTS it will be a lot more copy and paste
That is a whole paradigm you change. It won't help you to have cleaner code. Except maybe for readability.
And, what is your scope/vision.
Maybe, refactoring should not be something you should do.
The thing is though is that my system for simulating everything actually works better with a component-y system, since it was Originally designed with DOTS in mind
Okay. So my project is an open world RPG codebase (because I am insane) and to solve the problem of persistence of world outside of a scene, everything is actually a set of classes kept in a large dictionary, and all of the gameobjects are merely puppets being controlled by the classss inside the dictionary. However, because of the variety of tracked objects, there is a complex inheritance chart that requires a lot of reflection and casting and a mess of code to process
It's seem so complex for no apparent reason. Why is standard OOP not enough ?
It’s kinda dumb but it’s the best I could come up with without being able to use DOTS. And yes I already tried using a hybrid system, it wasted 3 months.
What do you mean
Why are you not using more plain approach/standard (Object Orientated Programming) then using Reflection and Dictionary to represent classes.
Because I need to be able to access them by an ID, but then I need to check what kinds of entities they are
Did you divide your class, (Character, Object, Whatever that is being persist) and their actual representation in the save ?
solve the problem of persistence of world outside of a scene
When you are talking about persistence outside of a scene, you are talking about saving the state of the game right ? Otherwise, you can just use DontDestroyOnLoad or additive scene.
No, I mean like. If an NPC walks through a door, leaving the scene and destroying the GameObject, the player should be able to follow them through the door, loading into the next scene and seeing the NPC there
If the player puts down an item in one room, and walks over to another, the player should be able to return to the first room and find the object still on the ground
well you need to represent that persistence in the background somehow
like the NPC still exists in game but their gameobject/any 3d or 2d model/texture is destroyed until they re-enter some radius around the player where the world is loaded?
Idk that kinda stuff is pretty complicated. you have to be already handling stuff like map chunking and loading and the like
but otherwise you are reallly just looking at extending whatever AI you are using, to function in the background, ergo the world that is not currently being rendered
you could also do some sort of lazy system where you save the position of the NPC, and then, depending upon various factors, you run some update code when you get closer to the NPC. like say you save position, and time since last encounter, and use that to determine what the NPC is doing the next time the player enters the area, but you dont call the update until you are nearby. Just an example tho.
I have designed all of these systems
but yes tyou are correct
I did all of this already it's just a bit of a reflection mess
so fair haha
you know your codes become spaghetti when its harder to navigate than the london underground
(see: the london underground transit map xD)
tho honestly I'm working on a binary space partinioning algo, for procedural castle generation in isometric, and its starting to feel like spaghetti
I was able to refactor the castle code into a builder pattern
but its meant writing then rewriting everything, atleast so far lol
even then, it feels a bit unruly already
I guess we'll see
today was the day I learned that if you call Graphics.Blit on a shader that doesn't have a _MainTex variable (yknow, like 90% of shaders) it just has undefined behavior!
So, we are talking about saves, differed update and lod/culling group.
Save: When you leave the door, you save the state of the room. When you return you load the state of the room.
LOD/Culling Group: When the object is too far you deactivate it, when it is in range you reactivate it.
There is no need for big framework or usage of Dictionary/Reflection. If you prefer to do it your way, I have nothing against it. I still prefer to tell you that, from my perspective, it seem that you are over engineering things.
Depends upon your goals I suppose, but I get what you're saying in principle
I have already been able to set pixels of Texture2D due to hours of research and errors (WOW). Now I need to be able to get position of pixels in a 3D unity Space by clicking an object via. raycast. Anyone have ideas or unity doc links?
Thanks :D. I've been stumpped for a long while.
This is the silly code I tried: Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo)) {
print(texture.GetPixelBilinear(hitInfo.point.normalized.x, hitInfo.point.normalized.y, 1));
}
Yeah that makes sense, but going through a door loads a different scene. Like press E to enter someone’s house. And the physical spaces of the different “rooms” don’t always like up; it’s not merely a rendering issue. I will keep this crowds thing in mind though
Hello there! I am currently finding a way to convert a Unity AudioClip asset to a Wave file (Runtime)
This is the code I am currently using, however it doesn't work with Audioclip that loaded from (by UnityWebRequest) a 32 bits WAV file
protected override async UniTask WriteSerializedAssetAsync(AudioClip asset, FileStream stream)
{
await UniTask.SwitchToMainThread();
var data = new float[asset.samples * asset.channels];
asset.GetData(data, 0);
var intData = new short[data.Length];
var bytesData = new byte[data.Length * 2];
var rescaleFactor = 32767;
for (var i = 0; i < data.Length; i++)
{
intData[i] = (short)(data[i] * rescaleFactor);
var byteArr = BitConverter.GetBytes(intData[i]);
byteArr.CopyTo(bytesData, i * 2);
}
await stream.WriteAsync(bytesData, 0, bytesData.Length);
var hz = asset.frequency;
var channels = asset.channels;
stream.Seek(0, SeekOrigin.Begin);
var riff = System.Text.Encoding.UTF8.GetBytes("RIFF");
stream.Write(riff, 0, 4);
var chunkSize = BitConverter.GetBytes(stream.Length - 8);
stream.Write(chunkSize, 0, 4);
var wave = System.Text.Encoding.UTF8.GetBytes("WAVE");
stream.Write(wave, 0, 4);
var fmt = System.Text.Encoding.UTF8.GetBytes("fmt ");
stream.Write(fmt, 0, 4);
var subChunk1 = BitConverter.GetBytes(16);
stream.Write(subChunk1, 0, 4);
const ushort one = 1;
var audioFormat = BitConverter.GetBytes(one);
stream.Write(audioFormat, 0, 2);
var numChannels = BitConverter.GetBytes(channels);
stream.Write(numChannels, 0, 2);
var sampleRate = BitConverter.GetBytes(hz);
stream.Write(sampleRate, 0, 4);
var byteRate = BitConverter.GetBytes(hz * channels * 2);
stream.Write(byteRate, 0, 4);
var blockAlign = (ushort)(channels * 2);
stream.Write(BitConverter.GetBytes(blockAlign), 0, 2);
ushort bps = 16;
var bitsPerSample = BitConverter.GetBytes(bps);
stream.Write(bitsPerSample, 0, 2);
var datastring = System.Text.Encoding.UTF8.GetBytes("data");
stream.Write(datastring, 0, 4);
var subChunk2 = BitConverter.GetBytes(data.Length * channels * 2);
stream.Write(subChunk2, 0, 4);
}
I was working on a playable behavior. In ProcessFrame I was using FrameInfo.evaluationType to determine if timeline was playing or not (it seemed to work in OnBehaviourPlay and OnBehaviourPause). Unfortunately in ProcessFrame it reports the evaluation type differently.
Can anyone tell me a way to know if the frame the behaviour events are executing because of user scrubbing vs the timeline playing?
Do not map the timeline directly with the real duration/time. I'm not sure you want to wait 40,000 years to play your whole animation. Anyway, I'm pretty sure timeline is mapped to 0 seconds as the start.
The first chart/model that is shown should be at the position 0. At least, if you do not have an introduction. You then position the rest in respect of the time you want them to be present. Not in function of the real time they have been around in history.
At the same time you are showing your chart/model, you can then show a label specifying the time it has been around.
Yo, I've been looking around the CullingGroup API and just under it had documentation on Dynamic resolution. I think you might be interested in this. https://docs.unity3d.com/Manual/DynamicResolution.html
Is there a way to use reflection or something else to signal what class has deactived a GameObject? I have been tasked with finding a bug in a rather large code base and I am having no luck just by following the flow
Add a script with OnDisable on the GameObject.
Then use the callstack.
Thanks I have also seen the dynamic resolution feature. It is really interesting to safe performance. although in this case its is quite the opposite of what I would like to do. I would like to reduce the framerate and keep the resolution. A pixelated desktop background does not look that great 😬
It might work or not, I do not remember.
I managed to get different fps per render layer working btw. Both via compositor and via custom effect volume. And it drastically decreases GPU load. Overhead is still to high though. Oh and resizing Render Texture Assets actually worked without loosing their reference. I guess it was a different problem breaking my reference when I first tried.
Yeah, like I said, you might want to find an other engine/construct your own. Unity is not made for this.
Maybe I will move the project to URP if HDRP overhead gets to problematic. But I still dont really see an alternative to use here.
I could use WebGL but that would require me to do a lot of stuff from scratch that Unity already does
You can use OpenGL/C++ natively... The amount of people that made tutorial on how to create your engine is insane.
Thank you for your help, this does indeed fix one of my issues
you might have to flush the stream. you can also use BinaryWriter to make life easier
it doesn't look like there's anything wrong with yoru code
also i don't think WAV format uses UTF8 strings
@trail cloak you can also try reading your WAVE file for validation using https://github.com/kaitai-io/kaitai_struct_formats/blob/96427681634ba5d5d7bce1c3e442e2ef3af2953f/media/wav.ksy
it's too bad kaitai struct doesn't support writing
Is there a way to use the color swatches in the editor in the code ? I tried to put the color preset library in a scriptable object but it is not accessible through script. Or maybe there's a better way to use the same colors in code as well as in editor that I am not aware of.
Hey guys I'm building my own controller,instead of relying on a character controller component, using the new unity input system. I got collisions working correctly(afaik) including the "wall slide", but now I need help with something. In the video below you can see the collisions working but I want to make it so when I get to the stairs(near the end of the video) instead of colliding it goes up the stairs.
Does anyone know a way to accomplish this ?
uhm I see but I'm not using a rigidbody, do raycasts can you get a contact point from a capsule cast ?
which I'm not supposed to change in any way, it is supposed to work
what do you mean by this?
based on your code it looks like you are a unity general / unity beginner
your Neighbours implementation is wrong in a computer science sense. it will give incorrect answers at borders
causing an infinite loop in the graph
without the AStar class it's impossible to know why it gives null or what that means
have you looked at kinematic character controller? it is free
Are you sure you are adding correctly the Neighbours ?
Oh, and your EstimatedCostFunction is wrong. The heuristic must always be lower or equal to the real cost.
it's better to test with estimatedcostfunction 0 for now
and try to get things to work
it's okay i think it's in alright shape
Euclidean Distance would be a valid heuristic, might not be the best though.
for what it's worth you don't necessarily need a valid heuristic, it just guarantees you will find an optimal path - without one you will still find a path and that may be good enough depending on what it's used for
You will always find the shortest path / most optimal path no matter what
The heuristic is there to help find it quickly
No. You won't find the shortest path no matter what. You need a valid heuristic for that.
without a valid heuristic you run the risk of ignoring the best path, and finding an alternative that is longer and exiting first
your heuristic just can't return an overestimate of the distance
if it never does that
it's good
it's not really important, just a little intrigue/curiosity - for some games a "good enough" path might even be preferrable
this is the definition of a valid heuristic which was not respected with the Manhattan distance in the given problem.
I've just heard about it, could check it out. Im doing it for the learning experience and because character controllers restrict physics etc
i see. there are a lot of gotchyas
I don't really know if this is code related, but basically I'm trying to connect a sword to my player's hand using a FixedJoint2D and I want to align the sword's rotation with my player's hand, but when I rotate the sword it rotates back to the original rotation it was in when the game started, as in if I start the game when the sword is at a 45 degree angle, when I pick it up it's going to rotate back to a 45 degree angle. It's pretty hard to explain what's going on but I have no clue what's causing it or how to fix it.
Here's what I tried:
Setting the sword's rotation to align with the hand every frame - it just keeps trying to rotate back to its original position and ends up spinning uncontrollably.
Using a HingeJoint2D - same issue as FixedJoint2D
Attaching the FixedJoint2D component to the sword rather than the hand - still trying to rotate back to its original position
And probably some other stuff I don't remember, I've been at this for hours. Does anyone know how I could fix this?
basically I'm trying to connect a sword to my player's hand using a FixedJoint2D
why?
what is the effect you are trying to achieve?
I'm making an active ragdoll game so I want to connect it with a joint
okay
it should be pretty straightforward to use the constraints
it sounds like you want to emulate a hand holding a sword, in 2d... and then, like what exactly do you want it to do? try to go back to a position when it is knocked out of place?
that's not really a hinge (freely rotate about a point)
it is a relative joint ("Use this joint to keep two objects offset from each other, at a position and angle you decide.")
i think you can achieve this used a fixed joint
so it's not clear whyt you are updating the sword's rotation
is this helpful?
i don't think you need scripting to achieve this
you can use a relative or a fixed joint
I'm gonna try using a relative joint now, wasn't aware of it so i'll see if it works. After doing a little testing I learned that the fixed joint tries to rotate back to its original rotation when the component was first enabled which is why I wasn't able to get the rotation to align with the hand
"Fixed Joint 2D cannot modify the relative linear and angular offsets in real time. Relative Joint 2D can." but i don't think you need to
Relative joint worked perfectly, thanks
Has anyone had success getting NodaTime into a project?
I'm getting some weird errors about the Unsafe class.
alternately any other recommendations for date math libraries that "just work (tm)" with unity?
Hey guys, doing string manip for an app,
I was curious if anyone here knows how to detect if a certain word was modified, and if so, then remove that entire word (or the remains of that word) from the string?
For example, let's say the string is: "The quick brown fox jumped". And let's say we marked the word brown.
In code, we have access to all marked words.
let's say, the user now modified the 'brown' and made it 'bron'. Then the app should remove that word entire, and text should be "The quick fox jumped"
Are there many C# implementations? If so, are they compatible with Unity? Or does it have to be the default implementation loaded onto VS
it's not for a game, it's for an app where the writing can have marked special autofilled words
is this for unity?
Yeah.
hmm
This doesn't work for the case where, if the user, instead of turning "brown" into "bron", they just add a space to make it "bro wn".
Now comparing old string and new string are different sizes so you can't only delete the next word after the incorrect index match.
I actually already found a solution, and implemented it.
what do you mean
The only downside is that with this method I cannot add duplicates of the marked word.
it "has to be" the "default"
do you have a screenshot of your unity editor handy?
so i can better understand what your goal is
try googling "nodatime github unity"
Think the "@mention" functionality in apps.
The idea is the player can type a few letters of a friend. For ex: I will type @doctorpang and the app will auto-fill that to your full name to replace that string to then be doctorpangloss.
Now, if the user in any way corrupts that text, then the app should remove the whole word.
Think Facebook.
I have a solution working, but the only downside of it is that I can't attach a mention of a user more than once per user (aka, no duplicates).
Discord does.
And Facebook does, too. And my app is a similar one that has traditional posts/threads/replies, etc, so it should have that feature as well, it's in the feature spec list.
I am not talking purely from auto-fill.
On Discord or Facebook, when you type "@", it opens up a mini menu with users that you can click to add to your message. I have that.
I am on PC (Desktop application), and it seems to be doing that.
Tag me and remove the s in my name.
You tagged a real user.
That just happened to be a real user,
secondly, your message looks messed up due to the hashtag and weird text at the end.
Thirdly, what you did was on phone(?)
I cannot delete a single letter on Desktop application. It deletes the whole mention.
This is actually poor from Discord.
Firstly, it looks malformed because the hashtag and remaining text looks weird.
Secondly, you did not mean to tag Fau, but it did, so this is poor design on Discord (phone).
I just verified this is also not possible on Discord web version.
Yeah, I have something working so far.
Where, I use the inputField's OnTextChange callback, and I call my function from that event.
And with this, I get the final string after every single key press.
After a keypress, I just check if any of the marked words do not exist in the new string, if so, use the string from last frame and just remove the marked word that's missing from new string.
Only issue with this is that I can't use duplicates of the same word. So I can't use like the same name 2 or more times.
I see, thanks
If List.Except works for strings, I suppose you can call that
I doubt it would give you specific details of where the except comes from, though. It will just return the characters that are not in the original string.
My guess, iterate both strings, find the changed characters, and then do whatever you want
Hey 👋 I'm trying to get the ResourceLocations of all assets with a label in Addressables. When the play mode script is set to "Use Asset Database" it works correctly, when it is set to "Use Existing Build"(I have a fresh addressables build), it returns an empty list. Does anyone have an idea of why this is acting weirdly?
Get float uniformscale always returns 0, while I can see uniformscale has a value of 2 in the material, how can I get the current value of the material? Do i first need to get the uniform scale of the material, then set that in the property block and then continue further after that?
Hi! Any ideas how to include UnityEngine.dll as a reference in a .Net Class Library? I grabbed the DLL from the Editor installation path, and added it in my project but I'm unable to use Vectors/Mathf and stuff like that that Unity provides
It's showing up in my references
Found the answer: UnityEngine doesn't contain that, it's in UnityEngine.CoreModule.dll
the gameobject "SunShroom" is running a animation clip which changes the sprite of its children, or alteast, it should change, but it doesnt, why does it happen?
the animation clip is legacy and not running trough animator
the sprite field doesnt even light up in its children
is it just not possible to do so?
ngl it seems the animations just cant change the sprite property
I found a bug!
Create a script with [ExecuteAlways] and you will see that OnEnable is called twice when entering playmode.
It should be called only once.
Unity version: 2021 lts (2021.3.12f1 to be precise)
Are you sure it's being called on the same instance of the script?
yes
I have only one object in scene
it's fast to test it out
It doesn't happen to you?
It does indeed
You could report it, but I wouldn't be surprised if it ends up being labeled as "By Design - Won't fix"
I works a lot with listeners added onEnable and removed onDisable. the double call would be terrible to me until i test on editor:
like that:
protected virtual void OnEnable()
{
lightProperty.onChanged += OnLightPropertyChange;
}
protected virtual void OnDisable()
{
lightProperty.onChanged -= OnLightPropertyChange;
}
but it's strange because the method is called only once (correctly) but i expect to be attached twice
I don't know what to think
