#archived-code-general
1 messages · Page 277 of 1
i have nothing to add but ditto
Is there something fundamentally wrong with using filename+line as global key?
Hm. Haven't tried if you have two files with the same name and start it in the same line of code. No clue what C# does about that.
filename might include the path.
it doesn't seem very portable, generally code-gen tends to break things unexpectedly
just generally speaking, you should not rate-limit input. you should rate limit the RESPONSE
this is not true at all
The fact that this happens:
var foo = RateLimiter.Instance;
var bar = RateLimiter.Instance;
foo == bar; // false
RateLimiter GetRateLimiter() => RateLimiter.Instance;
var foo = GetRateLimiter();
var bar = GetRateLimiter();
foo == bar; // true
Is extremely counter intuitive and error prone.
How can this happen? It's a singleton.
i don’t see when you’d really want to rate limit input, as opposed to the thing it activates
a few hours ago, he was talking specifically about a spawner, and spawning too much by spamming input
so at least in this case, spawner should have a cooldown
if you have a congested server, your only option is to reject requests, otherwise your queue keeps growing
Eh I misread your code, but change "RateLimiter.Instance" to "RateLimiter.GetKey()" and you get the exact same problem.
oh, for a server you mean
i thought we were talking more about input as in player input
That's by design. The rate limiter is specific for every line of code.
A very counter intuitive design.
i was so confused by all the file discussion, mb
same problem, but ofc situational.
There's no sane people looking at this behavior and think, yep that's completely fine.
var foo = RateLimiter.GetKey();
var bar = RateLimiter.GetKey();
foo == bar; // false
string GetKey() => RateLimiter.GetKey();
var foo = GetKey();
var bar = GetKey();
foo == bar; // true
On the contrary. It avoid the mistake that you use the same ratelimiter by accident in two different locations.
for servers you really have to gate input, for both congestion and DDOS-like scenarios. Not exactly DDOS, but you know what I mean
say if you have a 200 Hz input poll rate (because you are making a golf game) and you may be stalling your handler... you might want to use a dynamic limiter on top of the hard-coded polling frequency
You can now paste this if (!RateLimiter.Instance.passRateCheck(RateLimiter.GetKey(), 1f)) return; anywhere in your code and it will ensure that you pass this barrier only if the rate has not been exceeded.
Maybe I should call it /barrier/ instead of rate limiter.
true, but its not a perfect world and sometimes you gotta help where you can
anyway, not the point of this disco
I still don't know how you would implement this any different without requiring more code on the side of calling the limiter. Most solutions I found require you to define separate variables or have the problem of deferred calls.
It's explicit, I can look at the code and know exactly which ones are being shared limited because they have the same ID. I can't look at a piece of code in isolation to know with your approach.
this (old) thread has a good discussion on fundamental rate limiting implementations in OO languages
I need a component/class that throttles execution of some method to maximum M calls in N seconds (or ms or nanos, does not matter).
In other words I need to make sure that my method is executed no...
when I meant gating the response, I am assuming we’re talking about a game where we poll input once per frame. And not filtering to effectively reduce resolution beyond that. I think we’re talking around each other lol
Basically I want to use it in cases like this where I don't want the player to get strange flickering or behaviour when sitting on the Esc key.
It would be cleaner if you have it return a token or something you can use
What you are using it for is irrelevant to the implementation.
All these require managing additional variables and instances. It's not a one-liner where you can simply say: "make sure you only pass here at a rate of 3Hz".
here is no managing of instances, this isn't c++
if you don't use objects in C# you are just making it harder for yourself. the language is not really working well if you do C-style API design
you're not required to do all out OOP, but you need to accept that there are objects.
I agree, but my concern is with the top item listed here: https://stackoverflow.com/questions/1407113/throttling-method-calls-to-m-requests-in-n-seconds that you uave to manage "throttle" for every such barrier separately. So if I want need 10 rate limiters in the same functionality, I would need to define 10 rate throttlers. Where in my approach you have only 1 line of code to manage.
In my approach, this object is managed implicitly in the dictionary. They key idea is to use filename+line as unique identifier.
but you pay for that with having a singleton and coupling all your users to a single instance.
Ok. This is the first good point. I don't think it supports concurrency very well.
if you ever have to change the rate limiter of some of the users, you'll have to validate those changes against all other usages and if you use a different implementation you are fragmenting your code in a hard to trace way.
where a "separate instance" implementation would not create any expectations that any other system uses the same implementation or needs to be validated.
Ideally I would like a more streaming approach, so I can add traffic shapers on subscriber notification events.
anyway, i don't think your approach is fundamentally bad, its just not something you typically see in C# and it wont survive review in a team project.
So basically key presses become action events, they go into a queue, and then I use filters&shapers on these queues.
but I'm worried that this causes too much compute overhead.
you're looking at a message queue and not a rate limiter anymore
This behavior is so counter intuitive, like that's just not how C# (or most other programming languages) works.
well, if you look at C long enough, you can see some mysterious things
I agree. Ideally, I would love a #DEFINE statement for it and just call it " BARRIER(3) " so you pass this at a rate of 3Hz.
because when I used rigidbody last time the movement was super slippery and the player had very little control. There was too much acceleration.
You were doing AddForce, and perhaps using GetAxis?
Also, did you apply any physics materials?
yes I was
I don't think so
Ok, yeah, that is the most "slippery" way to use rigidbodies
With AddForce, you especially want to use GetAxisRaw
GetAxis uses smoothing
I'm using the "new" input system now
Is using AddForce also a cause of the slippery control?
It can for sure
Setting Velocity or using MovePosition is less susceptible fo that
Add force is basically how objects move in real life. If you push some object, it will keep on moving until friction stops it entirely.
Shouldn't be relevant which input system yoy use btw
Edit: oh, other than the getaxis thing. Sorry
Does the new input system use values 1, 0, and -1 for vectors?
or would I need to make them normalized
There is a lot of complexity, ao I'm not positive. I think it is 1 and 0 (and -1) only though
Alright, I'll work on movement with rigidbodies I guess.
does anyone know how to fix the error when trying to reference a volume?
in the screenshot it doesnt show my mouse cursor, but i am trying to drag the volume component into the volume reference.
any idea how to fix sticking to wall with a rigidbody character
it depends on the input
if you do WASD input, i believe you get vectors like (1,1)
if you use a left stick, I don’t recall if you can get (1,1)
Reduce friction or disallow pushing into the wall midair
Make a new Physics Material, set friction low or even zero, slap it on the player.
Hello! So, I'm a bit of stuck. I need to determine which data structure to use to improve the (taking 95% according to profiler) worst performance aspect of my game, which is: finding the closest target which has a certain flag in its DamageableModule enabled.
Game is 2D, side view. The world is possibly infinite(auto-generated in the needed direction).
I've looked into spatial hashing stuff, researched quadtrees a bit, but cannot grasp if it's what I need or not.
Currently you can play up to 80-120 concurrent enemies when it's starts to heavily lag.
My current approach(lagging one) is the simplest one, which is, well, to brute BoxCastAll and then filtering the results(in Update). I've added a layer mask, but that did not help much. I understand that I can possibly change layers instead of searching by flags, but that will break things since I have multiple flags enabled, but you can only have 1 physics layer set.
Can we add runtime navlink using navmesh agent?
For example adding start and end point
120 enemies is not very many overall. You might want to provide more context/code to see if you're making a silly performance mistake. Maybe you shouldn't be using physics at all, and just go through the list each frame to find the min distance. That's linear time
Pretty sure the physics engine when you are using BoxCastAll is eating a ton of the time. For reference in my project I have ~4000 1D ranges, and querying overlap using a simple brute force search completes in 0.2 ms. I changed to using grids and that drops it to 0.01 ms.
You can probably create a new object that has a NavMeshLink and then bake your navmesh surfaces
But yeah 120 is tiny number for CPU you probably don’t even need any of the advanced data structures.
For starters you can try BoxCastNonAlloc https://docs.unity3d.com/ScriptReference/Physics.BoxCastNonAlloc.html instead of BoxCastAll
So you reuse an array instead of allocating a new one every time
What did the profiler say though? What exactly is causing performance issues?
Quad/Octree is an option here, but Physics spatial partitioning is already pretty efficient
Wait. May I ask for a difference between BoxCastAll and what I've just found, OverlapBoxAll? I'm extremely sure that the latter is better. And probably the non alloc versions of these two are even better...
Anyways, ~600ms every frame with this code.
public static bool TryGetClosestAttackable(
Transform startRaycastPoint, float distance, Vector2 boxCastSize, Traits searchedTraits,
out DamageableModule attackable, LayerMask layerMask, Vector2 direction, bool checkOppositeSide)
{
attackable = null;
List<RaycastHit2D> hits = Physics2D.BoxCastAll(startRaycastPoint.position, boxCastSize,
0f, direction * 1, distance, layerMask).ToList();
if(checkOppositeSide)
hits.AddRange(Physics2D.BoxCastAll(startRaycastPoint.position, boxCastSize,
0f, direction * -1, distance, layerMask).ToList());
bool foundAttackable = false;
float minDistance = Mathf.Infinity;
foreach (RaycastHit2D hit in hits)
{
if (hit.collider == null) continue;
if (hit.collider.attachedRigidbody.TryGetComponent(out DamageableModule damageable) == false) continue;
if (FlagExtensions.HasAnyFlag(damageable.BattleTraits, searchedTraits) == false) continue;
float checkedDistance = Vector2.Distance(damageable.transform.position, startRaycastPoint.position);
if (checkedDistance < minDistance)
{
minDistance = checkedDistance;
attackable = damageable;
}
foundAttackable = true;
}
return foundAttackable;
}
Casting means the physics query "moves"
It will have a start point and direction, and capture all colliders along that path
Overlap just "places" the shape where you say.
In simple terms
Yes, should have mentioned that this part I get about the 2, sorry.
I don't get which one performs better
might be! the target is web though.
One optimization is make sure the components that you're grabbing is part of a GO with limited amount of components
I would assume overlap is slightly cheaper, but both are very cheap
a better optimization is only be grabbing stuff from a layer that has those components but that's usually a little harder to manage
rather speaking, filter through layers than doing the comparisons through getcomponent
posted the code 🙂
Yeah I would use Overlap instead of Cast if you don't need to cast. I just assumed you had a reason to cast
Have you tried deep profiling? Nothing of that code seems 600ms bad to me 🤔
OverlapNonAlloc would be faster, buut not 3 orders of magnitude faster
Also, cast will ignore any colliders that are initially overlapping with the cast shape
nonalloc for sure though since you'd run more into gc problems first honestly
Not making lists and adding them to each other would be faster
But also not 3 orders of magnitude 😄
you can just check distance first, then raycast
or use ontriggerenter instead of checking distance
Yeah this allocates possibly 2 arrays (2x BoxCastAll) and 2 lists (2x ToList), so NonAlloc would be a great improvement
that's actually not that bad of an idea, just iterate through active enemies and compare distances. I'd profile that idea
Any chance that this is called 50 times a frame?
Okay, first things first, I profiled wrong 😅
It's about 60ms from what I can see. Second thing, it turns out, it might not be boxcast, rather this:
Which looks like this.
public static bool HasAnyFlag<T>(T flags, T flagsToCheck) where T : struct, Enum
{
var flagsValue = Convert.ToInt64(flags);
var flagToCheckValue = Convert.ToInt64(flagsToCheck);
return (flagsValue & flagToCheckValue) != 0;
}
Share the TryGetClosestAttackable method
this
I was going to make a similiar extension for flag checking, but was concerned about using Convert
Can you expand the Convert.ToInt64 and GC.Alloc hierarchies?
I feel like it's converting a string or something similar
why not just make all enums long?
is there a reason to convert (oh, I see that you do want that generic constraint which is a pain)
it's gonna be boxing and unboxing which is expensive
I think you could do something like cs (flags & flagsToCheck) == flags?
I'm pretty terrible with flags/bit operations but wouldn't that work?
If their sum is the same, then nothing changed
[Flags]
public enum Traits
{
None = 0,
Enemy = 1 << 1,
Player = 1 << 2,
NPC = 1 << 3,
Props = 1 << 4,
HasAttacker = 1 << 5,
//the list goes on...
}
should be able to use the Flags attribute and HasFlags
It only has HasFlag
Not sure if that works if you want to check if it has any of the provided flag
I feel like it's the conversion to int64 that is the problem. It doesn't make sense in the context too, as enum is an int32 by default
yes
I cant imagine it's because of the bitwise operation since that's the idea of using them instead of doing a bunch of comparisons, but then again I don't know too much about c# in this regards.
agreed, it's gotta be the Convert
Just cast the enum to int instead
That's not possible sadly
Making extensions for enums flags is more painful than one would imagine
If the type is Enum and not an actual declared enum type, that is
yeah, I do that a bit, but 32 bit enum is usually plentiful
void HasAnyTrait(Traits traits, Traits traitsToCheck)
{
return (traits & traitsToCheck) != 0;
}```
Something like that should work. But then you can't use it as an extension method as you need to know the type (Traits here).
breaking them down a bit more and doing an additional operation is fine
that will definitely work, but against the purpose of having this as an extension and reusing it
Yeah I feel that. Making those extensions was too demoralizing for me so I just stopped trying lol
I use flags for performance, and having to use Convert kinda defeats the purpose
but performance is more important, of course. Will check if converting to int32 is better. if not, then this is the way.
I don't think you can get the highest value of an enum easily
highest enum value? eh?
void HasAnyTrait<TEnum>(TEnum traits, TEnum traitsToCheck)
where TEnum : INumber<Enum>
{
return (traits & traitsToCheck) != 0;
}
Can't you just do something like this? Enums are inherited from numeric types, right?
I guess Unity doesn't support INumber yet
Sorry I mean when it comes to the extension method it would have been nice to have the method know the highest value by default
I hate having to make the same extension methods for every new flags enum type I make
But I don't think you can do this easily, you can add a generic constraint to struct and/or Enum (but Enum probably also doesn't exist in Unity), but this probably doesn't allow for something like this
You could check what HasFlag does, but I believe it's a big wall of code
Enum exists but you can't really do much with it without Converting it into an int
Apparently HasFlag does this
yeah I don't use hasflag
I remember someone linking a whole blog about that a while ago
Oh, well that's a lot less than I thought
But still really bad
So, casting to an integer yourself is not possible?
There's no boxing involved as far as I know so that's should not be that bad?
Can't cast from Enum to int, if that's what you mean
Yeah but the thing is that the enum type is known here. It's a Packet
But if you make an extension method, your type must be Enum
Oh okay
FYI this is what HasFlag decompiles into for me
I can't find GetRawData, I kind of hoped it might give a good solution
That class has partial files all over the source code, and none have this method
Right, the problem is generic constraint of type enum here, but that does that specify the bits and to do these bitwise operations we'd have to convert them equally. I do use these for enums which I aren't checking every single frame, but otherwise I just do a dictionary lookup table for enum types and delegates.
I could probably ditch the lookup and just specify it directly, but similarly I do these large distance/component checks
I see there's a nice discussion going, but I'll add this: your profiler indicates you are hitting 2500 items in your typical boxcast. If 120 of them are the enemies you're after, then over 95% of the time you're doing useless work in the best case where you always hit all 120 enemies. You might consider moving them to a different layer, or if that's too much breakage maybe it's time to keep them in a list and iterate over that once instead of finding them via boxcast
it's actually just about 125 on average... it just happens 20 times
A thing to note about deep profiling is that if you have loads of calls inside a function, that would impact the function's "self" time, because some amount of time is spent to measure the things inside.
Which is why deep profiling is good to get an idea about what's happening where, but the measurements do get somewhat off and should be compared to non-deep with Profiler.WhateverTheMethodWas or using Stopwatch
This absolutely helped, thank you. I dont really get how things are going to be added over time as its only looking for objects in the Start() method
Or am I missing something?
Nah it's removing/adding in update as well (you can see with those Add and RemoveAt methods).
The only thing its doing is moving things between the lists. I have to make so that new game objects are checked for all the time
The new gameobject can notify this script about that it was created. This script can then add that new object to either list
But how do I do that efficiently? Because I have to add it to the script on multiple objects as there can be multiple objects with this script in the scene.
The only solution I had was a for loop but it just gave me more problems 😂
Are you familiar with events?
Dont know... what is it??
not sure if its the right thread but i have this problem where the textmeshprougui components disappear when a object with textmeshpro is spawned in the 2d space, on android devices
tried searching only but the threads seem to be open ended
tried having different materials for both the objects and it didnt work
Probably not really coding related. Take a screenshot of the object.
yea couldnt find a thread for textmeshpro specifically :p, so went with general
one min
fyi #📲┃ui-ux
okay ty
For future reference, if you don't know where to ask, ask in #💻┃unity-talk
okay 😄
@tribal coral I'll try to give an example...
So you have a class (ListenerClass) that wants to know when an object of type ObjectClass is created.
In some class (I'll call it EventClass), create an event that ListenerClass can subscribe to:cs public static event System.Action<ObjectClass> ObjectAddedEvent; // This could also be in ObjectClass - up to you really
And a method that raises the event (called when you want everyone to know about it):cs public static void ObjectAdded(ObjectClass obj) => ObjectAddedEvent?.Invoke(obj);
Now ListenerClass can have a function that has ObjectClass as parameter.cs void ObjectWasAdded(ObjectClass obj) { ... }
Because its parameters match, you can have it subscribe to the event:cs EventClass.ObjectAddedEvent += ObjectWasAdded;
And finally to "raise" the event, the newly created ObjectClass instance can call EventClass.ObjectAdded:cs EventClass.ObjectAdded(this);
Oof that got confusing. I tried my best
To put it simply: When an ObjectClass ìs created, it raises the event in EventClass. ListenerClass which is listening to (subscribed to) that event will invoke its method ObjectWasAdded and receive the new ObjectClass instance as a parameter
Yeah, in the middle of writing it I was like "damn this is hard to make look simple" lol
But events are pretty useful once you get the hang of it
Probably best to explain events in general before tossing the observer pattern at them 😛
Yea it seems so
Thanks
I did toss the Events docs to them 🤷♂️
But yeah make sure to read on events in general first
Basically events are a way to say "something happened, whoever's interested, do what you want with it".
@hexed pecan it doesnt let me do this
EventClass.ObjectAddedEvent += ObjectWasAdded;
That or im not getting it lol
What's the error? Do your parameters match the parameters in the event?
I dont really know what im doing... 😅
I made a event like this:
public static event System.Action<GameObject> AddObjectEvent;
Is that right??
Because I cant seem to access it from the other script
Looks ok. What is the error though?
There is no error with that line. I just dont know how i should do this step
EventClass.ObjectAddedEvent += ObjectWasAdded;
Well you ofc need to use the class/method names in your project, not my example names
This should be done in the class that wants to get notified when an object is added
So the first part should be in the object that is being spawned?
Wdym with first part?
@hexed pecan (thought you might find this interesting.. maybe?)
sad, but that infamous tool says that with enums the closest thing to do flag checks is to do this:
public static bool HasAnyFlag<T>(T flags, T flagsToCheck) where T : struct, Enum
{
return ((int)(object)flags & (int)(object)flagsToCheck) != 0;
}
which helps! but still allocates. and there are no easy ways to fix this due to C# limitations.
This: public static event System.Action<ObjectClass> ObjectAddedEvent; // This could also be in ObjectClass - up to you really
And this: public static void ObjectAdded(ObjectClass obj) => ObjectAddedEvent?.Invoke(obj);
Hello, I was wondering where can I go to ask for some help with a unity project
Oh yeah, that's an option. But casting to object will cause boxing, which will allocate memory (as you noticed)
I think it still defeats the purpose of using flags in the first place
yep! though seems that less than using Convert 🙂
Good to know
Those can be anywhere, really
Maybe in some manager script, or maybe just in the object's class itself
Most of the channels are help channels, pick the best one id:browse
The this I need to know how to do is this: EventClass.ObjectAddedEvent += ObjectWasAdded;
maybe I can use something like BitArray and work with it instead?
flags for inspector and OnValidate convert them to this BitArray thing
What is the EventClass?
EventClass is just the class that has these ^
You can decide where they go
So GameObject in my case?
Well, no, you can't modify the GameObject class
Don't these objects have any common script on them?
Like an enemy script, or whatever these are?
No they have not
Would be easier if they would. But you can work with GameObjects too. Just need to raise the event from whatever class is spawning them
The script is checking how many of a type of structure is close by a structure
Can you explain what you mean with "class that is spawning them"??
How are the structure objects created?
That script is the one I mean with 'the class that is spawning them'
The point is, someone needs to raise the event when a structure is created
Cant I just use the Start() method in the object that is being created??
I olny want to know what I should write here: EventClass.ObjectAddedEvent += ObjectWasAdded;
What EventClass should I put there?
Yes, this is why I was asking if the objects have a common script in them
They have not
What class did you put ObjectAddedEvent into?
It is static so you don't call it with an instance, you call it with the class name
where is the unity bug reporter if I my unity crashes on launch...
Is the only way to report unity bug really just via the editor?...
Does that happen with a new empty project or some specific project?
some specific problem, I can reproduce it and I know what is causing it, but the bug seems to be in a unmanaged unity engine code
Stack overflow in unmanaged: IP: 0x7f5bf6a79e5a, fault addr: 0x7ffe88431f78
Stack overflow: IP: 0x7f5bf69819e5, fault addr: 0x7ffe88429fe8
Is there a stack trace?
it's happening probabily on the script recompilation stage
Yeah, the log itsel has 20k lines
I spliced it to exclude repetitions
Does it include your code?
Can you share some of the stack trace?
In those 200k lines
you can submit a report via the Hub
Yeah, just tell me if there is some info I should share in the Editor.log
Not the editor log. The stack trace of the error...
for example there is SessionId, "Serial number assigned to: ..."
yeah, but the editor log contains the stack trace
Is that the last thing in the log?
ok, here is the log:
The stacktrace includes some references to my code, yes
Hub bug reporter seems to relate to Hub only bugs from what I've read though. Doesn't it?
What's in this script on line 17?
me.tooster.sdf/Editor/Controllers/SDF/SdfCombineController.cs:17
could be, never used it
!bug
🪲 To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.
📝 If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click ‘Report a problem on this page’!
💡If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.
For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting
Apparently there's an exe you can launch from the unity directory
// me.tooster.sdf/Editor/Controllers/SDF/SdfCombineController.cs:17:
public override SdfData sdfData => Combinators.binaryCombine(
MergeData,
GetComponentsInChildren<SdfPrimitiveController>().Select(p => p.sdfData).ToArray()
);
private SdfData MergeData(SdfData d1, SdfData d2) => mode switch
{
Mode.SIMPLE_UNION => Combinators.CombineWithSimpleUnion(d1, d2),
Mode.INTERSECTION => Combinators.CombineWithSimpleIntersect(d1, d2),
Mode.SMOOTH_UNION => new SdfData
{
evaluationExpression = vd => AST.Hlsl.Extensions.FunctionCall("sdf::operators::unionSmooth",
d1.evaluationExpression(vd),
d2.evaluationExpression(vd),
(LiteralExpression)blendPower
),
},
_ => throw new ArgumentOutOfRangeException(),
};
wait a moment, I think I'll open the github repo to public to allow for easier browsing.
It kinda looks like an infinite recursion to me
I hope there is an alternative to .exe for linux...
could be, possibly masked behind some weirder error
You do know that GetComponentsInChildren returns the object itself too, do you?
but why would it crash the editor?
yup, I missed that
You can easily crash almost any program. It's not a matter of "why", it's a matter of creativity
indeed, and that was exactly it
anyone know how to solve this?
every single unity game I have
crashes
I do not know why
Debug it🤷♂️

what is just pretty wild to me is that unity simply crashes and fails to startup instead of catching this error and aborting compilation task...
You'll need to contact the developers of the games that crash. We can only help with your own unity project, not released games
its all unity games
Now I'm stuck in sime kind of lifeloop, but I think I will manage that, thanks for help btw
and its only unity games
I had similar cryptic stack overflow case once and completely forgot about it
It's not during compilation. It's during execution. And there are some errors that just can't be caught.
It doesn't matter. Without access to the project and/or source code there's not much we can do.
do you have any idea of who can fix this?
The developers of the game
I said
Or at least, they should have a better idea.
all unity games
Yeah, but it also depends on the kind of architecture, I assume if compilation was done in a separate process, it could have been avoided? Not sure how Unity's invoking compilation stage etc.
And I said contact the developers.
Contact all the developers of all the games that you played.
And unity will tell you to contact the developers of the games.😅
welp thanks for nothing
The error is not thrown at compilation. And it's not so simple as to just put stuff in a different thread or process.
You're welcome.
could be some kind of microsoft lib error
dunno, .Net framework 4.5 or something
If you really want to dive into debugging the issue, you could try building a unity project and debugging the crash.
what system are you on?
Then you can contact unity and report a bug report if it happens.
Or provide more details in the discord for people to help figure it out.
Things you could check could also include
- similar threads in the web (https://steamcommunity.com/discussions/forum/7/2254560552302022403/?l=schinese&ctp=3)
- do you have any system updates pending
- are your drivers up to date (and are games using GPU if yu have any)
- did you install the game (if under windows) to a "correct" directory (some windows directories on more recent systems have some hidden implicit "write permission" restrictions — For example Documents/ directory. You may not exactly know if you have installed to one of those if you don't check where data is installed. I remember once encountering it by installing software to a desktop directory, while desktop directory itself was a kind of "protected" dir)
There's no point. It could be anything. Just because we're programmers, doesn't mean we can magically solve an issue from looking at a screenshot of a crash log without access to the project, source code or even debug symbols.
It's like your phone being broken and you go to the company that builds microchips for your phone and ask them to help you while providing a photo of your broken phone.
This is not even a coding question, why are you expecting help in here?
We can help with code, not debugging some game that crashes for you that's not yours
Oh they already left, good riddance
is there any way i can get element scale relative to the world, not localScale?
for example:
- Element 1 - scale 0.5
- element 2 - scale 1.5
- element 3 - scale 0.5
and i want to get scale of element 3
which will be 0.375
just having forgetful knowledge but if I were to find a prompt of wanting a button to be held in order to make an if statement active how do I phrase it as
instead of "canbepressed"
that works amazing thanks
now bolts dont have random sizes
Unity2D is their a way to layer your colliders from 2 objects that are overlapping
So the raycast from a mouse can pick one over the other
You'd use an OverlaPoint to detect a 2d collider at the pointer position. I'm not sure if there's a variant that returns all the overlapping colliders. You'll need to check the docs for that.
appreciate it i've been tweaking some settings but it all seems to work thanks!
I think i need a better method to control multiple UI menus, layered on top of each other. Right now, I use an enum for the UI state, and use that enum to target specific gameobjects to turn them on or off.
But this system sucks when you nest menus, because any “parent” menus need special cases to stay on.
Any recommendations for how to handle in a simple way?
I’m contemplating making a tree data structure, but idk if there is a simpler way
might be a werid question, but i was wondering if i can make a line break in the comment that is showing when hovering
yes. i forget the syntax tho
ill try google it
look under xml, i think it’s called paragraph or something
yeah. xml docstrings have features, and are really good.
HTML is XML BTW
you can trick VS and use para aswell
yeah i forgot
can you have a private set let you set the value from inspector ?
i have a var that will not change at runtime, but I want to set it using a compoennt in the scene
yes
Serialize the backing field
[field: SerializeField] public int myValue {get; private set;}
if it's an auto-property then [field: SerializeField]
yeah. or serialize the backing field like caesar said
[SerializeField] private int _myValue;
public int MyValue {get => _myValue; set { _myValue = value; }}
field: makes an attribute target the relevant field
in this case, you defined an auto property, so field: makes the attribute target the automatically made backing field for it
this works for other attributes as well
👍
for reference: [field: SerializeField] private int _myValue;
is the same as
[SerializeField] private int _myValue;
as it is already a field
hello, how can i drag a gameobject from one scene to a field in the inspector of an object from another scene please ?
You can't
your options are listed here: https://unity.huh.how/references/cross-scene-references
thanks
can i just have a button that modify the value on one scene, and the text from the other scene just display the variable ?
it's what im trying to do with the cross scene drag and drop
You should have a DDOL object that exists in both scenes and store the value there
i use playerprefs to store the value
Then what do you need the gameobject for?
i have a button that increment the value on scene1 and a text that displays the value on scene2. i had a script that needed to link the displaying text to the button
That's still a job for a DDOL manager that handles all that
i've never done that before :) i'll give it a try
can i have a ddol object that store different variables ? and btw i'd like these variable to stay between sessions
The only thing different about DDOL is that the object isn't destroyed when a scene unloads
so the stored variables stay between sessions ?
no
so if i want them to stay should i use a DDOL anyway ?
That has nothing to do with persisting the values. You'd use playerprefs for that just like you've done so far
but it doesn't work
i want a button to increment playerpref value and a text to display that value
Yes, and for that you make the DDOL controller object
i'm struggling lol
What did you do?
Linking the button with the text and storing the value between sessions are two different problems with two different solutions. Don't try to find one solution that would solve both of them at the same time, that doesn't exist. Solve them separately.
i'm trying my best x)
I made two scripts. One checking for already placed object which is on the reciever and one which checks for nearby structures when its built which sits on the sender. The sender then calculates the distance and sends over information adding to the counter if its close by.
I made it over complicated at first but then I understood what I had to do
can one single DDOL do the job or not
or should i create one for every link i'll make
Yes, one is enough
How do you get a code box when pasting from vs??
is there a good tool already for managing nested menus?
Specifically:
- Child menu => all parent menus stay enabled in background, but not interactive.
- Inputs work like a simple FSM, that let you navigate to certain menus from others.
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Thanks
@hexed pecan thank you for your help even though I didnt end up using it. I will probably use it sometimes in the future though
i've always liked the "pushdown" version of game state machines for this (https://gameprogrammingpatterns.com/state.html#pushdown-automata) you can push new states on top of old ones and the transitions between them can handle turning on/off interactivity and stuff like that
hi! i'm new here. sorry if this is the wrong channel, but i'm curious if somebody could help me with clamping and inverting a quaternion? I've tried Quaternion.Inverse() and tried converting to euler angles and clamping the appropriate axis and recombining the axis, but neither seem to work. I'm happy to include footage if it helps explain my issue!
I should clarify that I'm using the IMU of two Joycons as prototype VR controllers. That's what the initial Quaternion rotation is sourced from. 🙂
i guess i’m looking for something like an FSM, where I can define what is allowed to go to what, and what can be displayed
this is such a common problem, i feel like there have got to be tools for this already
like a no code way to define your states? or what do you imagine it looking like?
you know how animator animations have a little graph of what states can go to what other states? like that
clamping a quaternion doesn’t make sense imo. you would clamp euler angles used to make a quaternion
That's what I said above 🙂
converting a quaternion to euler angles isn’t quite a perfect transition. so quaternion => euler => clamp => quaternion will have problems
case RotationType.TESTROT:
var testInput = playerHand.localRotation.eulerAngles;
testInput = new Vector3 (Mathf.Clamp(testInput.x, 45, 115), 0, 0);
pivotPoint.transform.localRotation = playerHand.localRotation.normalized;
pivotRb.MoveRotation(Quaternion.Euler(testInput));
break;
oh, i see! so really this is going to be trickier since i'm starting with a quaternion regardless?
I've been reading into quaternions over the past two days in hopes that something would click, but ultimately it just seems like quaternions are very inaccessible.
and not really designed to be tweaked?
think of a quaternion like a rotation operator. you do not try to dig into the guts of an operator
ofc!
you apply operators to operators etc to get what you want
i have a custom system with attributes and codegen that i use for that on personal projects haha, it's kind of an elaborate solution but it means all my transitions are defined by little methods like this:
[TransitionRule(RuleTransitionKind.Pop, Condition = nameof(Cancelled))]
internal void CancelTransition() {
this.Cancelled = false;
}
i was hoping that i could take the local rotation of the lever and multiply it by a localized IMU quaternion to basically send it in one direction when motioned
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.
after jumping multiple times
i see. I have a dictionary to do something like that, but it’s awkward haha
and that much works, but i'm not able to lock the lever's rigidbody axises since it isn't a physics-driven function, it's hard-setting the rotation.
Yeah no need to understand the inner workings of quaternions, you just multiply them with other quaternions to combine rotations, or multiply with vectors to rotate vectors.
And learn how to utilize all the Quaternion methods (FromToRotation, Inverse, LookRotation...)
With that, I built my own quaternions with only one axis.
but then everything is inverted, even if i use Quaternion.Inverse()
i would apply the quaternion to a vector, manipulate the vector to be “clamped”, then generate a new quaternion based on the manipulated vector
i can share mine if you like but the codegen part requires odin (it works without it, it's just slower because it uses reflection)
it’s ok. my system is already like that, and I want to move away to a smarter one lol
as in different architecture
i guess ultimately, i'm wondering why the quaternion will not invert, using Quaternion.Inverse() as it should be doing
i'm doing both
well just focus on one at a time
because vert and horz rotations are inverted
i almost had the whole thing done but got stuck flipping the rotations
so i went back to the start and ended up here now
apply quaternion to vector, represent vector in spherical coordinates, modify vector, then generate new quaternion based on the operation to go from old to new vector
i think since angles are modular and wrap, i should just add rotation rather than entirely replace it right? that's my understanding
the zombie just walks through the colliders, any way around this?
i would recommend using the AI agent and generating a navmesh tbh
You want some sort of pathfinding
maybe because they are triggers?
Well, that too
ye ig
But having non-trigger colliders doesn't automatically make them avoid obstacles
good point
@swift falcon Please don't crosspost. Stick to a channel.
houw could I go about doing so?
I don't think the builtin NavMesh works with 2D so you might need something else
you need some sort of way to express the mathematical operation that you actually want… as a quaternion
quaternion methods can handle turning different representations into a quaternion
but you need to be able to do the math to articulate wtf you actually want
This sounds silly, but I don't know what I actually WANT mathematically. I'm ultimately a designer and just trying to get this working since it's the last feature I need to implement for my prototype.
I just know how I want it to behave
I have the player's hand, which i'm currently feeding a transform to the lever via interface
@swift falcon Search for unity 2d pathfinding
and i want the lever end/handle to track to the player's hand, by rotating the lever's pivot
editing won’t ping @swift falcon
as well as that, i want it to be clamped A) to one axis and B) to a range between two angles
alright will do, ty
then i would do this
you can represent a restiction in angles as clamping a specific angle in a spherical coordinate system
Unity vectors are in cartesian coordinates, so these equations will let you convert to spherical coordinates: https://en.m.wikipedia.org/wiki/List_of_common_coordinate_transformations#To_spherical_coordinates
This is a list of some of the most commonly used coordinate transformations.
idk if unity has a tool to do that, but if you have the equations already, you just need to type that shit in
doesn’t matter how complex the math is, if you are just copying
https://en.m.wikipedia.org/wiki/Spherical_coordinates This article should explain how to interpret the variables
In mathematics, a spherical coordinate system is a coordinate system for three-dimensional space where the position of a given point in space is specified by three numbers, (r, θ, φ): the radial distance of the radial line r connecting the point to the fixed point of origin (which is located on a fixed polar axis, or zenith direction axis, or ...
terrible to solve, but not to copy paste
i'll be right back, but thanks very much for your help. i'll take another shot at clamping things and if it doesn't work i'll come back crying 🙂
fyi, you only need theta and phi. These are the zenith and azimuthal angles. Clamp those, then convert back to cartesian.
theta = Mathf.Atan(Mathf.Sqrt(vec.x * vec.x + vec.y * vec.y)/vec.z);
rho = vec.magnitude;
//clamp phi and theta.
//Come back
x = rho * Mathf.Sin(theta) * Mathf.Cos(phi);
y = rho * Mathf.Sin(theta) * Mathf.Cos(phi);
z = rho * Mathf.Cos(theta);```
then Quaternion.FromToRotation from your input vec to the new xyz
isn't division on FixedUpdate poor optimization?
would Mathf.Atan(vec.y*-vec.x) be better?
No, not really
That would be a microoptimization
oh okay, thank you for clarifying!
back in uni, they told us to consider optimization but never how much we should optimize 🤦♀️
division used to be bad in the N64 era, where division would take 4-6x longer than multiplication. Now not so much
if you want the logic, you will need to do the math. only worry for optimization if it is actually not good enough, and you are doing a specific thing a lot
1000 divisions per fixed update isn’t going to do shit
okay great, thanks so much
the only caveat there is checking you aren’t dividing by zero
oh i heard about that actually being really bad computationally lmfao
Well, it is not possible. It will cause an error
yeah, you need to check first. 100 zero division errors being thrown will basically destroy your performance, and also make the game literally not work
i guess it was older computers - like pre-GUI computers - that had that issue
throwing an error effectively slams the breaks on the program, meaning the whole part where you assign the rotation does not happen
Older computers also could not divide by 0
Division by 0 is undefined mathematically
that's when a script is disabled, right?
i would just preprocess x and z to make sure their absolute value is no less than some tiny number
dividing by 10^-6 would send this algorithm way off course anyway
actually, the trig functions can probably handle weird shit, so maybe
note ATan probably gives output in radians
Hi, I am making long notes for a rythm game and I want to have the note destroy after it passes though I am left unsure on how to make it work
(programming tends to punish people who slept through high school math)
Really depends on how your game works now
How do you destroy short notes?
How do you DETECT notes?
i definitely didn't sleep thru high school math, but its been a loooong time since high school for me
(game dev does, programming - not so much)
we had a guy a few months ago making a football game. slept through high school math. he could not do basic algebra, so his football game effectively died.
oh that poor soul
it’s not something you need every day. but it is something that comes up enough to be necessary
I know a lot of people with poor math skills who do great as app / BE devs.... but in game dev math comes A LOT more often, yeah
you destroy short notes with just an arrow key and it's detected through a specific position that the notes go through, the closer to the center the higher the points given
what I need is a way for the game to be demanding to keep holding the button
so... you measure time between down and up of the key and compare with some tolerance to note length
yeah that's what I am doing now, just need to set the if statement correctly so it can deactivate after the duration
or you compare the down with the start and the up with the end of the note
Game Development does not necessary mean Game Programming which was primarily the confusion here.
ah, fair, fair 👍
It was like: As a designer, you need good math but as a programmer not that much.
that is somewhat true though, isn't it?
game designers also need more math than programmers 😄
Not at all ?
ah, you mean designers as in people who do visuals, UI, UX? yeah, they probably don't need much math
Game Designer as people that design the system or the level. Such as what X enemies will do or how the game will progress
those things do need some math-ing though, no? for balance reasons and to understand scaling of things and what to expect (which not every game needs, I guess, but from what I hear they do use math not too rarely)
anyway 🙂 yeah, I was talking about non-game programming vs game programming specifically
case RotationType.TESTROT:
Quaternion q = new Quaternion
(-playerHand.rotation.x,
-playerHand.rotation.y,
playerHand.rotation.z,
playerHand.rotation.w);
pivotRb.rotation = Quaternion.Euler(q.eulerAngles);
Debug.Log("Hand rot:" + playerHand.rotation.eulerAngles);
Debug.Log("Lever rot:" + pivotRb.rotation.eulerAngles);
break;
okay so same situation, i am unable to reverse the axis of the quaternion without throwing off the entire rotation and causing it to change orientations.
does anybody have any recommendations?
besides that, it works just fine
oh, no no, if you do new Quaternion(x,y,z,w) you can't ask questions about rotation, that's the rule
again, clamping will be easy with the way it's setup
it's rude to ask a quaternion its age
exactly
really though, i am so confused, i'm not sure what to do with this
if i use eulerangles, i assume that the orientation will always be the transform.up of the world
but that doesn't seem to be the case?
i understand that it's 180 degrees around the center point so it goes from 90 to -90
what's the objective? how should the object behave?
it should follow the player's hand, but the rotations are all reversed
to give the illusion that the player is physically grabbing and pulling the lever (the hands in=game are controlled with two joycon controllers)
ah, okay... and the thing can only be rotated in one axis?
it will be only rotated on one axis, but the axis all get switched around whenever i invert an axis to correct their rotations
so if i invert the Y axis, suddenly Z and X are swapped
which is making setting the quaternions up very confusing, especially since you can't visualize them in editor
so you need the player's hand position relative to the center of rotation... project it on a plane with a normal that's the axis of rotation... and then... multiply the current rotation with a FromTo rotation between the current direction of the thingy and the projected direction you calculated 🤔
that sounds a bit more complex than I'd like... 🤔 but should work, I think
you'll position the handle so that it points at transform.right from the object that you're rotating, and the axis of rotation will be transform.forward... and then it's just
var targetDir = Vector3.ProjectOnPlane(playerHand.position - transform.position, transform.forward);
var rotation = Quaternion.FromToRotation(transform.right, targetDir);
transform.rotation *= rotation;
where transform is the object that you're rotating with its position being the center of that rotat-y thing
@pearl bay
hope that helps 😅
Isn't this just basic "look at" or am I missing something..?
I tried look at, it didn't work!
I guess direction could be done with look at
but it needs to ONLY rotate on one axis and be clamped, so lookat can't be used to pivot it
This might be a bit of a strange question, but is there any way I can bisect a navmesh along a line like this and calculate the area of the two halves?
Ok, I would calculate the angle along that axis with Vector3.SignedAngle
And then clamp and apply that on that one axis only
signed means it can be a negative or positive value, right?
Many ways of doing it. I just noticed the real mathy stuff before and thought that it's over complicating it
Yes and it lets you define the axis you want to calc the angle on
oh amazing, thank you!!
i'll try that now
is the axis argument normalized?
like (0,0,1) being Z?
it asks for a Vector3 but ofc that doesn't make sense
Axis length doesn't matter
But yeah 0, 0, 1 would be Z. Make sure it is relative to the lever tho
var angle = Vector3.SignedAngle(playerHand.rotation.eulerAngles, pivotRb.rotation.eulerAngles, pivotRb.transform.forward);
Oh, no
oh no
Like var you mean?
That's up to you. I personally use var a lot. Depends on how clear it is from the right-hand side
...It returns a float 😆
So yeah maybe be explicit about it
sorry i'm just between this chat and working so i'm not thinking, i meant float sorry ;p
Np
🤦♂️
yes, that was pretty much a LookAt aligning right instead of forward...
and now when we put it like that... just do transform.right = handPosition - transform.position 😄
and make sure the hold-y part goes to the right of the object... or if forward or up just set forward or up 🙂
I thought that too, but it needs to rotate on one axis only if i understand correctly
This would make it rotate on potentially all axes
right, so do the ProjectOnPlane thing
okay so when grabbing the lever, i need to consider changing the transform direction, and then clamp it as i am doing?
that would give you a direction that's on the proper plane so that it only rotates around one axis
how is subtracting one position from another (which isn't normalized) be okay to set to a normalize value like a direction?
does it normalize it automatically?
in this case specifically it does, yes
why is that?
but you need this to be on one axis ```
var targetDir = Vector3.ProjectOnPlane(playerHand.position - transform.position, transform.forward);
transform.right = targetDir;
sorry for all the questions!
because Unity implemented the setter of forward/right/up to normalize the value you give it 🙂
i see, thanks
hotloading between all of these little tweaks to the script is trying my patience. please pray for me.
I don't speak English, I'm translating with Google so it might be a little out of context.
I'm having a problem with the lives system. I'm following a tutorial on YouTube. Everything is OK in parts, I put the lives correctly, when he loses 5 lives he dies, but he is not appearing visually. When I lose life I was supposed to change the sprites for the empty heart, but it only changes when I lose 5. Please help me.
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class sistemadevidas : MonoBehaviour
{
public int vida;
public int vidamaxima;
public Image[] coracao;
public Sprite cheio;
public Sprite vazio;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (vida <= 0)
{
HealthLogic();
DeadState();
}
}
void HealthLogic()
{
if (vida > vidamaxima)
{
vida = vidamaxima;
}
for (int i = 0; i < coracao.Length; i++)
{
if (i < vida)
{
coracao[i].sprite = cheio;
}
else
{
coracao[i].sprite = vazio;
}
if (i < vidamaxima)
{
coracao[i].enabled = true;
}
else
{
coracao[i].enabled = false;
}
}
}
void DeadState()
{
if (vida <= 0)
{
GetComponent<movimentoplayer>().enabled = false;
Destroy(gameObject, 0.1f);
}
}
}
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
if (vida <= 0)
{
HealthLogic();
DeadState();
}
you only execute HealthLogic when lives are <=0
so, like in real life, right? 😄 you only care about your health when you're between dead and very dead 😅
Wow, I didn't even see that there was that hahahahaha, being a beginner is tough. thank you friend.
it worked here 
no pasa nada

I have an annoying problem where I want to save some replay data when I exit play mode* (or when exiting the game for that matter), but since the order of OnDestroy calls is seemingly random, I don't always have this data available anymore.. is there a workaround for this?
Can Someone Help me?
using UnityEngine;
public class SpaceBackground : MonoBehaviour
{
public bool rotateAstronaut = true;
public GameObject astronaut;
private float rotationSpeed = 50f;
public bool moveBackground = false;
public GameObject background;
private Vector3 backgroundSpeed = new Vector3(50f, 0f, 0f);
void Update()
{
if (rotateAstronaut && astronaut != null)
{
astronaut.transform.Rotate(Vector3.up, rotationSpeed * Time.deltaTime);
}
if (moveBackground && background != null)
{
background.transform.position += backgroundSpeed * Time.deltaTime;
}
}
}
I want that the Background is looping
do not cross post
lets say that my player got a backpack
the backpack can :
- be on the back of the player (attached with the player movements)
- placed on the ground (fixed to the ground)
for now i found two possibilities :
(1)
- changing parent to Player/None when the player drops/pickups the backpack
(2)
- the backpack is never parented to the Player (its parent is the scene root), instead we have a Update that sets the position of the backpack if the Player has it on its back
what would be the best solution ?
there is also Parent Constraint
I start with parenting, then do something else if something makes parenting problematic.
i didnt know about that, seems what i need
ill test it and see
Fen is right, parenting is probably the best option if possible
can be problematical if both player and backpack have rigidbodies
they will have
just tested parent constraint and seems to have all the features i need, ty again
I’m thinking of a system to stage collision callbacks. I currently have ObjCollsion : Monobehaviour, which has OnCollisionEnter/Stay/Exit2D, and it then invokes Action<ObjColData>, which is a simplified struct of collision data. ObjCollision.onCollisionStay is that action which all of my classes subscribe to for triggering collision callback logic.
Right now, I am thinking about effectively sorting logic so it can go off after collision callbacks in a sorted way. eg contact state checks go first, then reference frames, then pushing/pulling, then death detection logic, then death execution. This way each function can rely on a certain set of assumptions of what is ready or not.
I do currently have a class that can invoke a certain function after all collision callbacks are done. I am thinking about making enum PostColCallbackStage with values for the above stages. And I’d like something like:
ObjCollision.onCollisionEnter += MyFunction, but to actually call it at a given stage.
Recommendations?
Questions:
- Why not just use OnCollisionEnter/Exit wherever you need to and using script execution order and the like?
- Is ObjCollision global, or one per RB?
Also, OnCollisionStay is kinda sad performance-wise
You could just expose many different events and subscribe to the one of your interest.
script execution order does not impact collision callbacks
one per rb
(Although I personally dislike using conventions as a way to prevent logical errors)
And what's the problem with the collision callbacks order?
You want to handle collision checks and have an updated "collision state" and only then do all the processing of said state? (after ALL collisions are detected?)
in this case, it should be a relatively rough staging process. So i can avoid cases where I can’t use up-to-date info because i do not know if it is ready yet
it’s not a perfect solution, obvs. But it’s kind if awkward for something that fills up contact state to occurr before or after something that causes death.
Depending random order
you can’t really order them
As for this part, you can do like Burrito said, or you can have an Add/RemoveHandler methods with an action and the enum value and internally subscribe to the proper event... which is pretty much the same, but organized differently 😄
So apparently Unity doesn't allow animation events to be used that contain a bool parameter?
Why?
Might be worth looking at how unity is doing stuff in the new physics package https://docs.unity3d.com/Packages/com.unity.physics@1.2/manual/collision-queries.html
I'm looking forward to being able to just do some direct queries about the things i care about instead of having to awkawrdly hook into individual object callbacks
You can take a page out of dependency management in various systems.
A subscriber can declare that "call me after A, B, and C have finished, and I'm going to do D and E." The event can take information of all subscribers and produce a deterministic call order that satisfies everyone.
By design, I guess. As an alternative you can accept an int and convert it with something like this:
public void EventHandler(int v)
{
bool b = v != 0;
}
Pass 0 for false, anything else for true.
This avoids a need to declare a convention of "stage 1 does A, stage 2 is only called after stage 1 so you can now safely assume all works of A has been finished, etc" because that kind of system is extremely fragile and requires you to go into the event emitter and read its code (or have it properly documented) to know the order.
Yea thats the workaround, but it still feels weird. I hate arbitrary restrictions like this
Especially when other kinds of events (like UnityEvent) allow methods with a bool parameter
i’m a bit confused by this
Lots of systems do things like that (having an arbitrary number to indicate order) and you know how they all end up, systems like script execution order, z-index in CSS, etc. The amount of codebases that have completely irrational z-index in CSS is hilarious, because someone comes along and be like "A used to be the top most thing so it has a z-index of 9999, but now I have a new thing B that I want to be top most even above A, guess I'll make the new thing to have a z-index of 99999" and eventually every time someone wants to modify z-index they have to search the entire codebase to see what values there are.
so like an enum flag that describes all dependencies of prior work that must be done?
Also found out that animation events cannot contain more than one parameter. Super lame.
What Burrito says is a super cool system... but also seems like extra high effort. (I'm a big fan of KISS, so I feel that whenever things get complex, it's a good time to take a step back and think of simpler solutions and whether something is needed 😅 )
Sure, the representation of dependencies could be enum or could be something else, it doesn't really matter. As long as each subscriber clearly describes intents (before you call me, make sure all modifications to player position has been completed, and I'm going to modify player health) then the event emitter can be like, okay I'm going to put you after all event subscribers that modify player position, but before all other event subscribers that need player health to be finished modifying.
how would I implement this, tho?
unity's ecs lets you put things in 'groups' to simplify this from having to manage each individual dependency
Yeah this is only something you would do when you have a complex system that have subscribers interconnected with each other and needs the system to scale. For simpler situations, a hardcoded execution order is completely fine.
i would start there since that's pretty simple -- are your systems simple enough that you can assign each a group and then order those groups? cause then you don't need to do any programatic dependency resolution
That's basically the magic execution order approach yes, which will work for most simple systems.
kind of, it has much more explicit intent than assigning random numbers
much more readable/understandable when you come back to it later
what's not understandable about 153?
I wouldn't say so, you can give meaning to "random numbers" by using enum, const int, whatever, so instead of .Subscribe(9999, OnFinalize) you would write .Subscribe(Stage.LateUpdate, OnFinalize)
That doesn't stop it from still being a random number under the hood, because ultimately if you need a new stage, you have no choice to but go into the definition of those numbers and change things around.
Any ideas on how to make an animation event hold multiple params?
ok sure, but it's still a huge improvement compared to something like a z-index where those 'definitions' don't exist and are arbitrarily defined in-place throughout the code instead of in a single place where you can easily go look at that
i was still planning on using enums at the start. magic numbers are hardcore garbo
well, you'll space them out so that most of the time you wouldn't need to change others, just insert in the right place... but all in all if you do something else, you'll probably still need to change things around when you need a new stage, because some old stuff will now need to be after it, and it will need to be after some things, so you'll need to know what all things are to put it there
yeah, enums exist because giving names to magic numbers has a lot of value
but that runs into the convention problem burrito was talking about
yeah, i mean if you have the time and budget to build and maintain a system to handle all of this, by all means go for it
i just would argue that most games people are working on here need not be, and should not be written in a way that is that complex
i’m not exactly sure how I plan to very quickly sort these dependencies if they aren’t like a non-flag enum based order
you don't have to sort them quickly, you can cache the depenency map
Yeah for z-index abuse, if you use any modern CSS you'd get to properly put all your magic numbers somewhere together, which solves at least the "anytime I want to change something let me search the entire codebase for all z-index values first" problem, but ultimately these types of systems still rely on "using convention to prevent logical errors" which sometimes is good enough, sometimes it's not. Entirely depends on your need.
iirc there's a pretty in-depth gdc talk about how they did this on destiny
this one maybe? https://www.youtube.com/watch?v=v2Q_zHG3vqg
In this 2015 GDC Talk, Bungie's Barry Genova explains how Bungie turned almost every part of Destiny's engine into a a job graph, with only limited use of thread-based pre-emption. This talk should prove useful to programmers working on demanding game engines of their own.
GDC talks cover a range of developmental topics including game design, ...
@chilly surge with a system like you describe, is it gonna be better? you'll need to know all things you can depend on... and when a new thing comes, some of the old ones may need to start depenging on it, which will be super annoying to setup, no?
any of these automatic job systems need to do similar stuff so that's a good place to look for implementation ideas if that's what you want to see
same with ECS frameworks which tend to order systems
ultimately you probably do have to understand how everything fits together to make the game work, but a system like that lets you consider each piece and what 'inputs/outputs' it has in isolation, which is nice
The thing is, the subscriber knows what itself depends on. I know I'm going to need A, B, C to finish before I want to run, and I know I'm doing D and E. I do not need to know what other subscribers are doing. All modification to myself can stay local, if I suddenly no longer need C to finish before I run but instead need F, I modify my own code and that's it.
In a system with numbers representing execution order, if I need to change -C +F, I need to go into the definition of these execution order numbers and see which one would work, and if there isn't one that would work, I need to add a new number, which can potentially affect other subscribers.
If you are inserting yourself into middle of the execution, you also need to check "okay will any subscriber executing after me get affected by what I do?"
that is fair
that is the common issue
i think I might do it with the basic enum, and later I can change the underlying implementation to a flag enum to check dependencies. Mostly because OnCollisionStay is going to get me some giant lists.
and I cannot envision what burrito is saying being done in one pass.
you need multiple passes to figure out the order
It's never a bad time to mention that OnCollisionStay is sad performance-wise 😛
i know
if I could have avoided it, i would have
i have no choice in my case
and it hurts
I recently recoded part of Oculus VR SDK to kill OnTriggerStay and improve performance... it was eating TONS of time, even after we tried to be smart with layers 😦
Btw if at compile time you know all of your subscribers and their dependencies (so no dynamically created subscribers with dynamic dependencies), then you can solve the execution order at compile time and generate the magical execution order numbers, so there's no runtime cost of solving dependencies.
my custom physics engine is already kind of caveman-like, as every object calls .Cast like 10 times per fixed frame
that is smart. idk how to do that in a way that net saves me time
ah... custom physics engine... okay, in that case you know best 👍
yeah, unfortunately, I still need unity to calculate contacts, because its methods don’t work to parse collisions with multiple contacts of different normals/points
otherwise, my collision callback system would be custom as well, and much smarter
It probably won't, things are all about tradeoffs, you are trading some upfront development time for correctness. If a simple magic execution order can work for your scale, definitely do consider it.
yeah. it’s one of those things where it would take me at least 2 days to figure out how to do and implement, when magic number enums will probably get me there
2 days is extremely optimistic
i do not expect a big web of nonsensical crap dependencies for my game. the core things that need ordering are contact state generation, general callbacks, logic that triggers death, followed by actual death
and none of these should be allowed to depend on something below it in that order, or I have a bigger problem
how I can change the alpha value of an image
make a reference to the component , turn it down on the color prop
and what is the prop of the alpha channel? of the color
dot a
so image.color.a
yea
thanks
but its prop you cannot directly modify it
make a copy and apply it back
var col = image.color;
col.a = 0;
image.color = col```
@hard viper @little meadow thank you very much for your help!
case RotationType.TESTROT:
Vector3 targetDir = Vector3.ProjectOnPlane(playerHand.position - pivotRb.transform.position, directionRef.forward);
pivotRb.transform.up = targetDir;
Vector3 clampedDir = new Vector3
(Mathf.Clamp(targetDir.x, minAngle, maxAngle),
targetDir.y, targetDir.z);
pivotRb.rotation = Quaternion.Euler(clampedDir);
bool approxValue = Math.Abs((pivotRb.rotation.z * 360 ) - successAngle) < 0.1F;
if (approxValue)
{
Debug.Log("Success!");
puzzleSuccess = true;
}
break;
this was my code in the end
okey. The possible values are from 0 to 1?
for Color yes
all values are 0-1
Color32 only is 0-255
i hope this isn't too much to ask, but could i get a code review on this now that it's done? i'm just hoping to learn from more skilled programmers
i feel like maybe some of it could have been refactored into their own functions
and the switch usage could have been used to toggle between axis instead of boilerplating a variation of the same code three times.
thoughts?
Are you really familiar with quaternions? This stuck out to me pivotRb.rotation.z * 360
You could just use pivotRb.eulerAngles.z and Mathf.DeltaAngle to get the diference
But if you know what youre doing then do it your way
i was just multiplying by 360 to get a non-modular rotation to compare against
i was using Debug.Log to get the quaternion value and noticed it was going from 1 to -1, but wasn't sure if it could go past that with this implementation (since euler just does -180 to 180 and wraps)
eulerAngles is the same as multiplying by 360?
using euler was doing a weird snapping thing at the 180 degree points around the lever's rotation and just did not look great at all like that, very easy for the player to potentially break
dimensional analysis shows that this code will break
targetDir has units of meters. You are clamping one of its coordinates with an angle in degrees. This won’t work
for starters, if you want this approach, then you’d need to normalize the vector to bring it to dimensionless distance.
then you’d need to do math to convert the angle to a distance on the unit circle to clamp it properly
right now, you are asking the computer effectively to give the closest value to 15 meters between 45 and 110 degrees, which doesn’t make any sense.
What is the proper way of getting image ui components that are children of something. I am figured I could use GetComponentsInChildren<Image>(); but I just get an error saying that Image needs to derive from monobehaviour, component, or is an interface. Can someone show me the right way of doing this?
you've got the UIElements namespace instead of UnityEngine.UI
are you using a custom Class called Image ?
ah yes prob namespace issue
wrong class imported
The ideal way is inspector serialization.
What would be a simple way to handle item recipes/combos?
Say instead of a grid like minecraft its just stacking items on top of eachother for simplicity.
So for example if you place item A, then B you get item C. And if you place item A, item B, then C you get item F
Does the "crafter" have multiple layers? ie, 9 layers, and {A}-{B}-{ }-{ }-{ }-{ }-{ }-{ }-{ } is valid but so is { }-{ }-{A}-{ }-{ }-{B}-{ }-{ }-{ } ?
(and do A & B need to be in the correct order, or any order)
make a Recipe class, e.g.
public class Recipe {
List<Item> ingredients;
List<Item> outputs;
}``` and use the anagram detection algorithm to make sure your inventory contains all the ingredients.
If they don't need to be ordered, then I'd create a way to serialize them and compare that serialized value against a list of known recipes.
For example, let's say you have a unique letter for every item.. you'd make a ToString method like this:
public override string ToString()
{
StringBuilder sb = new();
foreach (Item item in Items.OrderBy(x => x.ItemCharacter)
{
sb.AppendChar(item.ItemCharacter);
}
return sb.ToString();
}
yeah basically combine PB and my code, then you can just do if (craftingTableIngredients.ToString() == recipe.ToString()) // give the player the outputs
I kind of want them to be ordered though just to add a little bit more complexity between just combining out of order and the grid crafting system.
my approach still works, unless they have to be in specific slots
This would only work for if the recipe didn’t need to be ordered correct since it’s using anagram
Yes if you need a specific ordering it's easier you can just use SequenceEquals on the lists
I see so recipe 1 would be ABC and you’d need to place items A, B, then to create ABC then reference that.
I’ll look that up, never used SequenceEquals
How can I make a NavMeshAgent move away from the destination?
give it a destination that is away from the position you want it to move away from
that's pretty vague. There are a lot of places that are "away" from the destination. Perhaps give it a different destination?
An example: say I want to make an NPC take a backstep away from the player. Is there an easy way of simply inverting their movement to have them transform away instead of toward the target?
One thing you can do is look at the path the Agent has generated and take the first corner in the path. Then just calculate a vector in the opposite direction as that point
but there's no guarantee that direction is somewhere valid
it might put you right into a wall for example
Hmm I see
Okay follow-up question, what if I wanted to do this dynamically? Say the player is moving, and the NPC is purposefully running away from the player, changing its direction as the players position transforms. What should I do then?
were we not talking dynamically before??
I'm just moreso emphasizing the idea of the target's position changing and how to account for that
I don't see how it changes anything
you do the calculation again periodically
or every fixedupdate
Would that be expensive?
¯_(ツ)_/¯
expensive is a relative term.
Worry about optimization after you get shit working
Are you just trying to create distance between characters?
Casting along navmesh in the opposite direction of the character you are trying to move away from might do.
oh god duh i totally missed that
i think in my head i was thinking "yes, the target angle", completely missing that it's direction.... even though it's called 'targetDir' 🤦♀️
case RotationType.TESTROT: // Up-down test rotation
Vector3 targetDir = Vector3.ProjectOnPlane(playerHand.position - pivotRb.transform.position, directionRef.forward);
pivotRb.transform.up = targetDir; // Project on a plane and set the up transform to the result
Vector3 clampedRot = new Vector3
(Mathf.Clamp(pivotRb.rotation.x, minAngle, maxAngle),
pivotRb.rotation.y, pivotRb.rotation.z);
pivotRb.rotation = Quaternion.Euler(clampedRot);
bool approxValue = Math.Abs((pivotRb.rotation.z * 360 ) - successAngle) < 0.1F;
if (approxValue)
{
Debug.Log("Success!");
puzzleSuccess = true;
}
break;
hopefully this makes more sense! if you set the up transform of a game object in a script and then set its rotation, it doesn't reset the rotation does it?
You're reading directly from a quaternion https://unity.huh.how/quaternions/members
and treating it as a euler rotation
pivotRb.rotation.eulerAngles is what you would need to use
i was having issues with the way euler rotations wrap, since through the center is -180 to 180
it was causing the object to snap to the other side and behave incorrectly
Well what you're doing now makes absolutely no sense
i figured, i feel a little lost. i thought i understood, but honestly quaternions are very confusing as a non-programmer
case RotationType.TESTROT: // Up-down test rotation
Vector3 targetDir = Vector3.ProjectOnPlane(playerHand.position - pivotRb.transform.position, directionRef.forward);
pivotRb.transform.up = targetDir; // Project on a plane and set the up transform to the result
Vector3 clampedRot = new Vector3
(Mathf.Clamp(pivotRb.rotation.eulerAngles.x, minAngle, maxAngle),
pivotRb.rotation.eulerAngles.y, pivotRb.rotation.eulerAngles.z);
pivotRb.rotation = Quaternion.Euler(clampedRot);
bool approxValue = Math.Abs((pivotRb.rotation.eulerAngles.z) - successAngle) < 0.1F;
if (approxValue)
{
Debug.Log("Success!");
puzzleSuccess = true;
}
break;
this should be better right? 😄
i might change the tolerance to a variable on the success angle check and make it larger tho
Hello! Has anyone worked with ScrollRect for mobile devices before? The component works on the editor with clicks but for some reason it doesn't allow me to scroll on mobile with touch, does anyone have any suggestions?
have you tried the same resolution in the editor as your phone?
make sure you anchored everything properly
reading euler angles is usually a bad idea... they can be somewhat unpredictable and provide undesirable results... that's why I tend to use quaternions and directions... buuut I don't have a quick solution to the clamping with those (that I can explain rather than just write) 🤔
i think i picked something dumb and tough right?
honestly, it doesn't need to be 'good' for the prototype, it just needs to work, so even if i use hammy scripting and know it could be done better i'm sure it'll be okay
ik that's not a good thing to say in a code chat of all places
if it works - that's good enough (which as we all know is better than good 😉 )
Is it somehow possible to spawn an object under mouse cursor in a way that it would trigger IBeginDragHandler.OnBeginDrag --> IDragHandler.OnDrag?
And at the same time not force to hold left click down for it, but instead trigger IEndDragHandler.OnEndDrag on click?
is this for a dropper tool/feature?
I have an inventory with item stack and a button for splitting it. But I'd like the new stack to spawn under mouse as if it was being dragged already.
If I can't figure this out, I can just drop it into next free slot or ground.
is the instantiated object a generic draggable type which you assign a value to or is each one unique?
hm, not sure I understand what you mean
sorry i misread
can you call the interface functions directly?
so when the object is split, you instantiate the object and call the function
I remember I tried this some time ago, but failed... it kind of worked partially
I figured you'd just be able to do OnEndDrag(), right?
I'll try that again and try to remember what the exact issue was
anyways thanks, I probably won't get to it before tomorrow morning
good luck!
Yes I did the same resolution & for some reason I still can't scroll on my phone
SerializedObjectNotCreatableException: Object at index 0 is null
UnityEditor.Editor.CreateSerializedObject () (at <25578071f6e44201aac745680e5c8dfc>:0)
UnityEditor.Editor.GetSerializedObjectInternal () (at <25578071f6e44201aac745680e5c8dfc>:0)
UnityEditor.Editor.get_serializedObject () (at <25578071f6e44201aac745680e5c8dfc>:0)
UnityEditor.EditorUtility.IsHiddenInInspector (UnityEditor.Editor editor) (at <25578071f6e44201aac745680e5c8dfc>:0)
UnityEditor.PropertyEditor.ShouldCullEditor (UnityEditor.Editor[] editors, System.Int32 editorIndex) (at <25578071f6e44201aac745680e5c8dfc>:0)
UnityEditor.PropertyEditor.ProcessEditorElementsToRebuild (UnityEditor.Editor[] editors) (at <25578071f6e44201aac745680e5c8dfc>:0)
UnityEditor.PropertyEditor.DrawEditors (UnityEditor.Editor[] editors) (at <25578071f6e44201aac745680e5c8dfc>:0)
UnityEditor.PropertyEditor.RebuildContentsContainers () (at <25578071f6e44201aac745680e5c8dfc>:0)
UnityEditor.InspectorWindow.RedrawFromNative () (at <25578071f6e44201aac745680e5c8dfc>:0)
what do
context? 🤔
i fixed it
ah.
some how restrarting unity for the 5th time worked
no idea why the first 4 times didnt work
It looks like a random ui bug. It must be some window or tab misbehaving.
Usually resetting the windows layout would fix it if it's recurring.
This looks better to me. That said, reading Euler angles is always dicey from a quaternion, as the translation isn't one-to-one.
if i have a child with a collider, does the OnCollision event called in the parent ?
ie expect loss of information
if the parent doesnt have a rb
if child has RB, I believe the callback goes there
don't collision checks expect a rigidbody?
pretty sure you need a rigidbody and a collision compoent of some kind, trigger or not
the player has a rb
but this object doesnt have rb, only a collider of trigger type
also i think you can only do OnCollision/OnTrigger events from a game object that has a collision component, not its children or parents
i could be wrong, but i was looking at that today and it seemed unanimous
is there an equivalent to Debug.Assert that gets removed in final build, but without using UnityEngine?
some generic helper clases I write would not need to import UnityEngine if not for Debug.Assert
It should receive a collision event then.
does it matter? but in any case, I assume you can write your own (that just calls the other) and put it in global namespace?
What is the difference between CapsuleCastAll and CapsuleCast with a RaycastHit[] array as parameter?
have you checked the docs? they probably explain it
I did, they seem to do the same thing
But I assume they must be different, otherwise why have two things
Where are you seeing an overload for CapsuleCast that takes a RaycastHit[]
I guess the array is the result on the same collider?
well that takes a RaycastHit2D which is why i did not see it because I assumed you were using 3d since you specified RaycastHit and did not specify 2d anywhere
Ah physics 2d. I was wondering the same as boxfriend
but anyway, CapsuleCastAll returns an array. CapsuleCast populates an existing array to reduce garbage generation
prefer CapsuleCast over CapsuleCastAll and reuse the array
Is there any use case for CapsuleCastAll?
laziness, and if you want to get a new array with the exact number of hits in it
being lazy / not caring about some cast, because super rare... but mostly it's there for backward compatibility I guess
I see, ty
it matters if people not in unity want to use a generic class that has no real need to rely on UnityEngine
well it would need to rely on the class that does the Assert anyway... which would need to rely on Unity in some shape or form... not sure there's much to be done about that 🤔
it always bothered me that you can't have a script on a child object and push all of its exposed variables to the main parent for the sake of prefabs being easier to work with
you can always do #if UNITY and define UNITY in Unity (there's possibly some pre-defined symbol)
is there a work around for that?
ah! you can use Pulni's Editor Tools, which I just made public yesterday! 😂 you'll probably be the first user and tester, so fair warning that there might be stuff that needs fixing
on the scale of 1 to 10, how forbidden is that here? 😅 I can DM you the repo link, yeah
System.Diagnostics also has Debug.Assert, which I could maybe use
i'm surprised the standard starter content for unity doesn't contain things like that, or folder colorings
that one behaves differently though
still shocked we can't change the icons of folders, only scripts 💔
does that one throw a formal error?
also twilight sparkle was my college roommate's second favorite
i have avatar icons turned off on discord and got v confused for a second
must be a nice person! 🙂 after who though? 🤔 🙂
can InvokeRepeating have params to pass to the method ?
in the docs it doesnt look like it
I think it throws an exception, yes, though you can check to be sure... but in any case it wouldn't behave like Unity's because it does not know about Unity, the console and all that
no, but also it sucks really bad... just use a coroutine to invoke the method and pass in whatever params you want 🙂
@pearl bay I DM'd you btw
im curious, why is it bad ?
bad performance, also uses strings which makes it super fragile, also no params, and the list probably goes on
rainbow dash
you can make a much nicer InvokeRepeating method if it's something you need often and don't wanna write the coroutine every time
Very good choice! RD was one of my initial favourites as well, but over time I started appreciating all of them. The series make quite a lot of good points about... being tolerant and accepting people (ponies) for who they are.
how come unity says that my variable "percentageComplete" doesnt exist when it is literally defined in my code?
get your !IDE configured
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
thx 🙏
any ideas why a StopCoroutine doesnt stop a coroutine ?
public void SetConnectedStatus(bool newStatus)
{
if (_isConnected != newStatus)
{
StopCoroutine(HandleHealth(!newStatus));
}
_isConnected = newStatus;
_playerHealthBatterie.SetStatus(newStatus);
StartCoroutine(HandleHealth(newStatus));
}
private IEnumerator HandleHealth(bool gain)
{
while (!_playerHealthUI.AddHealth(gain ? 3 : -1))
{
Debug.Log(gain);
yield return new WaitForSecondsRealtime(1);
}
}
when i do
SetConnectedStatus(false);
i lose health every sec
then when i do
SetConnectedStatus(true);
i regain health until max, but i still have the removing coroutine going
i did some test with Debug.Log and it is doing StopCoroutine(HandleHealth(false))
Hello, I need help to remove all the parts after a certain time. I've tried a lot of different ways but to no avail :
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.
if you're going to use pastebin, at least have the courtesy to select the correct language so there's syntax highlighting. you also just dropped nearly 300 lines of code on us with very little info about what isn't working
Sorry I did this fast, I'm super tired and I've never used pastbin.
The script allows you to procedurally destroy an object in several parts
And I'd like those parts to get destroyed after a while
I've put the highlight sorry...
if you've gone through all of the steps to configure it and it still isn't providing proper syntax highlighting or underlining errors, then yes, regenerate project files and restart visual studio
you should point to the part where your attempt at destroying the objects after a while is and explain what isn't working with the current attempt
I deleted it because it didn't work at all
I did a simple coroutine with a destroy and it didn't work
I called my coroutine line 80 with the argument parts[i].GameObject
And in the coroutine I was destroying the object so
please see #854851968446365696 for what to include when asking for help. because honestly i have no idea what specifically you are having trouble with, and you expect me to read through your 300 lines of code to figure it out for you
In theory, I think I've said it all. I agree, I screwed it up a bit in a hurry. But in itself it's just a script to procedurally quote a mesh into several other mesh.
And I'd like to destroy the parts after x amount of time
I had made a coroutine using a GameObject as an argument and then destroying it.
And this coroutine I called line 80 with the argument parts[i].GameObject
But it hadn't worked
I feel like #854851968446365696 could include "describe what you want to happen, what you have tried to make it happen, and what's actually happening"
"Not working" isn't much information for people to help, you gave the second part but not the first or third.
pretty sure it did have that (or rather something very similar to that) for a while. no idea why it got removed though
It doesn't matter so much what you put in the readme because the people who you actually need to read it are the ones who don't. So I expect it's a balance of keeping it concise enough that it actually gets read.
would you say that #854851968446365696 is just not working?

Eh, not sure. I mean what @wicked scroll says is also very true, and it's hard to measure how effective it is.
if you have enough situational awareness to read the readme, then you also have enough awareness to explain your situation
I mean, "describe what you want to happen, what you have tried to make it happen, and what's actually happening" is very concise and a lot of badly asked questions are boiled down to missing some/all of the three parts.
The argument of "people who don't read are the ones that need it the most, so there's no point in improving it" is kind of flawed.
I don't think anyone is saying 'nobody reads it so why bother improving it?' it's more 'people will glance at it and make a decision about whether they are going to read it, or skim it, or start it and not finish, and given that, how do we optimize for as many people actually internalizing as much of it as possible?' it's tutorial design baby, and that shit ain't easy
anyone know how to make water like terraria in a procedurally generated world or know any tutorial for it?
pretty broad question... start by googling up perlin noise, probably
Also, another reason I was trying to use CharacterController is so I could have a custom acceleration.
yea i got a world generating and ik where water is going to be and stuff but i just need to know how to actually implement the water physics and the actual water
Hi, first off, sorry if I'm overlooking something incredibly obvious, but I'm trying to allow user to click a waveform (generated via a texture) and the game will know at which point in a waveform it was clicked. Just like Audacity/DAW.
So, like the % of the length of a object/collider the click occurred on would be enough information to estimate it, I suppose. But is it possible to get that level of detail about a collider (or other) click? Thanks for any tips!
sure, you just need to know where it starts and where it ends and where they clicked. give it a go
how do you guys keep const like float variables in sync between scripts?
Give me an example what you mean?
You cant change const value
Const variables are not meant to be changing, so that sentence doesn't make sense.
You don't need to sync something that doesn't change.
sorry for misunderstanding, what I wanna change is movement speed, normally it is stored in PlayerData but I wanna keep it short like movementSpeed instead of data.movementSpeed, but in the process of playing the game, the movementSpeed may subject to some changes
most classes are stored as references, can I do similar things to float etc
Create a property:
float MovementSpeed => data.movementSpeed;
is there a way to enable rider inspections in read only packages? Specifically, I would like to be able to browse ShaderGraph module
For now I only found that in the top-tight of editor window I can enable inspections for one file only, but then all references are red if I don't enable in other files as well.
And it seems I'm unable to find "enable inspections for directory"
how would i make adialogue window that resizes like this because when im trying to making a dialogue system outside of a canvas, the vertical layout group and the content size fitter dont work. how can i create the same effect outside of the ui or will i have to code my own custom script that takes the values from the textmeshpro component
to use JSON.Net that is il2cpp supported do you have to use the Unity package that is included with entities or something in 2022?
are there any reason why you make it outside of canvas?
Ah Unity is still hiding their version for some dumb reason - https://github.com/applejag/Newtonsoft.Json-for-Unity/wiki/Install-official-via-UPM
but then how would i get it to track characters in the game?
you can/need to calculate the image position based on the character.
or make a worldspace canvas, attached to the character, to contain the textbox
alright ill give that atry
Hi ! I'm using a UnityEditor.PopupWindow which is working well, but each time I'm using VisualStudio debugger, it catches an ExitGUIException that is thrown when I try to open the PopupWindow. In the documentation, it is said that this exception is by design and that I shouldn't catch it, but do I need to do something to prevent VS from stopping each time I'm trying to display a PopupWindow ?
Hello, I need to help, I used Obs pattern here and when I shoot the left one enemy i see flash effect on both but when i shoot other one it doesn't happen anything
Didn't see I could untick some option to prevent VS from catching it in the 1st place 🙃
seems like your observer (that's what you meant by Obs, right) setup is slightly wrong... both effects are observing the same thing, instead of each of them observing the one on "their" ship
you'll need to show code though, if you need more help 🙂
yeap i meant observer
okay i send the codes
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
should be simple though - just check what's observing what and adjust so that each things observes what's appropriate