#archived-code-general
1 messages · Page 446 of 1
tbh I tend to lean on "add convenience methods as needed" but it's harder with external APIs lmao
I'm spoiled because I worked in AAA and I could modify literally anything I want
Does Unity define motion control inputs as a press? Because at least in human speak imo they are input but not a press
This is separate from the "pointer" or "motion" inputs, which are multi-dimensional vectors
Exactly my point, yes.
that is a valid middle ground case then
lucky for all, unity was built on the idea that everyone needs different things and so they make APIs that give you all the info you need to make your custom thing, to satisfy your custom needs while not polluting other people's needs with yours
That's the issue with making convenience functions - you can't cover every case. At some point, you have to stop
tbh, the ability to use wildcards in the bindings (which I didn't know about until Praetor pointed it out earlier) does help immensely in this use case
You right. Unity should remove all convenience methods. They might pollute someones project. (You see the absurdity in that statement right?)
sometimes, we'd wish they'd have gone a smidge further before stopping
but it has to stop somewhere
yeah, I didn't finish my htought earlier but at my job I could just add convenience functions as needed, I've always had a harder time with third party APIs even when they're designed for flexibility like Unity is lmao
not what i'm saying, not what praetor or digi are saying, and there is no need for hyperbole
I inevitably run into a use case where I wish just a tiny bit more info was available/etc.
For any mario 64 nerds i’d argue if you can’t half press an input it’s not a press 😅. Motion shake is not a great example imo because unless im mistaken it’s kind of just a firing rather than a state based bool(?)
If you get to draw arbitrary lines in the sand with that line of thinking, why stop there?
That is what I'm pointing out here
eh, I don't think this was really the intended interpretation
you arent pointing out anthing that isnt obvious and was already considered
The statement is a flawed one because it implies that by having convenience calls at all you might be "polluting" someones game with bloat.
it is objectively difficult to gauge the full extent of every possible use case
No one is drawing arbitrary lines, we're just saying that it is literally impossible to cover every kind of function and there has to be a stopping point somewhere
you ar ejust dragging this discussion into the dirt with these pointless extremes
Not at all
but I also think framing convenience methods as "polluting" isn't the way to go, otherwise we wouldn't have Unity.VisualScripting
which I objectively only use by mistake
Wouldn’t an any press solution be fine as a generic connivence solution regardless since devs could choose to blacklist odd outlier inputs rather than build the entire whitelist themselves?
yeah i mean this makes the most sense
it might not be the cleanest/nicest solution but realistically speaking nobody has time to create perfect solutions for everything, unless you're the guy who made Kenshi I guess, but even then...
(Kenshi took a long ass time to make and still ended up jank)
An anyButtonPressed convenience method is not at all an extreme. Nor is it unreasonable to have in an input system. It is, in fact, something Unity had previously but didn't carry over. It is not an uncommon use-case either.
But instead of engaging with that and saying "Yeah, I suppose it could be" I'm told tall tales of how Unity needs to "stop somewhere" and "lucky for all, unity was built on the idea that everyone needs different things and so they make APIs that give you all the info you need to make your custom thing, to satisfy your custom needs while not polluting other people's needs with yours"
Like give me a break here.
yeah see
It seems that only keyboard has any kind of "anykey" check: https://docs.unity3d.com/Packages/com.unity.inputsystem@1.14/api/UnityEngine.InputSystem.Keyboard.html#UnityEngine_InputSystem_Keyboard_anyKey
I agree there, there is in fact a point where a discussion needs to stop
and by that I mean "don't drag someone's suggestion for a single method into an abstract argument in defense of Unity" lmao
They had it previously, because the sample space of what a button means was much smaller. The new input system lets you bind all sorts of weird jank to a "button" input and it'll work with it completely fine. So, rather than trying to draw a line between what counts as a button and what doesn't, they just figured "whoever is using the system can make an 'Any button' mapping and include only the ones they want"
most reasonable response tbh
as someone who routinely writes code that is extensible to the point of creating jank, i understand that lmao
Again curious for my own education than this convo, would that motion control shake input be referred to as a button? Since afaik you can’t keep it in a held state (unless that’s wrong)
probably, in the constraints of the input system? as a CallbackContext you'd probably end up getting performed and canceled fired one frame after another or something, but I'm not speaking from experience
I think the issue comes from not quite realizing how expandable the Input System is. You can have it do basic "I hit this round plastic thingy on my gamepad" buttons, but it can do things like the aforementioned joycon shake, a UI button in-game, a high signal from an Arduino board pin, releasing a plunger on an electronic pinball machine, etc.
It's designed to be completely hardware-agnostic
I believe it sends a press and a release in the same frame. I don't actually have a joycon here to test it with
man I wish this server had star stickers because this is probably the best argument i've seen in a while lmao
unfortunately, star stickers are relegated to first graders' desks (ask me how I know)

LMAO
Yet can still make the distinction between what is and isn't abstracted to be considered a button.
So do that. In your own input system asset, in your project. That's what it's there for
i feel like yall are kinda talking past each other
anyButtonPressed for any kind of input device? there's gonna be people disagreeing on what counts for that, unity can't satisfy everyone, so it's less of a headache to let everyone who needs it, define it for themselves
eh, I think when you view it that way, and considering we do have the ability to just have a binding use a wildcard for any button, it's reasonable enough
lemme scroll up a ways
Which leads me to what I said; A convenience method that can tell you whether any button is held or not, does not clash with the flexibility of the system because the system can already distinguish between what is and isn't a button. You set that up.
Either way, I tried the solution that was suggested and it doesn't seem to work.
Again, I might be using a "button" input elsewhere in my project -- meaning it's in my input map -- but not want it to count for whatever specific use case this is
anyButtonPressed kinda already has an ambiguous meaning
does it mean only stuff bound to button-type inputs? or actual hardware button presses?
So, simply existing as a binding isn't enough of a decider
i think he just wants button type inputs
if the former, then it's not really "any button", is it
like literally any discrete input lmao
Then you work around that use-case in that case.
In most cases a call like "Any button held" has use-cases where you don't care about those buttons.
it's just, any of my buttons, so it's again, misleading
I don't understand why that is such an alien concept.
I wouldn't go quite so far as to call it misleading. Perhaps just having it be something on an action map
But in that case you could write it as an extension method even
There's like, a universal law in software development. Any solution that is "common sense" and "easy to implement" is invariably always going to break things in heinous ways
are ps2 triggers buttons? what about ps3 triggers?
one is analog and the other is digital (if im remembering controllers right)
what about keyboards with analog keys
Point me to that law. Who said that?
cgp grey
never heard of it but my experience working in AAA dev taught me that it's very true
Just, y'know, *gestures vaguely at everything* experience
solutions that are easy to implement but not common sense are generally what happens in AAA to the point where everything is held together by duct tape and loose nails, but it works (it's hideous)
it isn't
but there are many ways to interpret it, most of them seemingly valid, some of them conflicting
I disagree. There are solutions that are common sense and easy to implement which do not "invariably always" break things in "heinous" ways. We call those programming patterns.
It's such a blanket statement, it's easy to find examples where it can be disproven 🤷♀️
also depends on how far into a project you are
yeah if you're abstracting the issue enough to where we hit "programming patterns" territory lmao
What do you mean abstract it enough??
Unfortunately in any "mature" software environment all of that has gone out the window
at least IME
Like I don't know what abstract you work in, but there are programming patterns that are not these nebulous thought clouds
that's... what patterns are though..
they aren't concrete, they can be adapted to each specific scenario
You're always going to run into things that really ought to be easier, but when it isn't you just roll with it and do it the hard way
i'm not articulating my thoughts very well right now, sorry
give me a sec to figure out what i'm trying to say lmao
Patterns do not produce concrete solutions, they produce ways in which to approach common problems in programming. That is why they are patterns. Because they repeat.
But to sit and say that you need to put in tons of extra work to get to that point of using any patterns is absurd.
Even in mismanaged projects you can spot common patterns.
It's not impossible to implement an "any button" that works in like 90% of all cases, but attempting to engineer 100% out of that 90% could pretty easily get an entire feature axed because it's just not coming together
It's not like systems in Unity always cover 100% of all use-cases in the first place, so I don't know why this is different somehow.
imo, "any button" is just too vague in one direction and not super useful in the other direction
there's probably a balance, but no one's ever gonna agree on where it is
ah. there's the rub, and that's what i'm getting at - generally in software, past the early stages of a product, "common problems" are replaced with hyper-specific shit that requires domain knowledge, and patterns stop being applicable. you end up with domain-specific "patterns" like "in order to add a new type of map object you have to declare it in 18 separate files and then sacrifice a goat on the nearest ziggurat"
I'm only slightly exaggerating there. where I worked there were like 20+ files you had to fuck with just to make sure something existed in the right places lmao
no goat sacrifice was required though
i think we've lost sight of the original topic though
i think a good middle ground would just be having it on an input action map or something
e.g. "is any button from this map currently pressed"
but then you lose the "press any button to continue" aspect
you could just have a map with that one binding for any button
I get that you are using metaphore for the sake of humor or exaggeration here, but this is simply not always the case. I have worked in big software, in fact most of the giant software suites, products or services I've worked with professionally have made heavy use of common patterns because otherwise there would be no way to maintain the software.
I don't know what your experience was but if you somehow managed to always be in badly managed projects, then I guess that's that.
right, and I worked in AAA game dev, which is extremely poorly managed
like across the board
company agnostic
that just moves the problem though
software patterns? libraries? this code is C++ from the late 90s, we don't do that here
maybe it's different outside game dev idk
This also happens in gamedev.
can't relate
While gamedev happens different to traditional software, games are still software.
Games do not sidestep good code.
yes they do.
code as a whole sidesteps good code
No. Rushed programmers sidestep good code.
The engine code is efficient. That's what it is. It runs well.
Probably the best way to handle this would be a sort of "Scriptable Input Device Asset" that you could attach to an input map, and letting you define which inputs on that device count as "Any Button", but that's a whole nother inspector to make and another asset to lug around and makes the already complicated onboarding process of the new input system even clunkier
But holy fuck we do not know what half of it does, nor who wrote it or why
But the "best" way is not always the best way
are rule tiles aod sorting layers mutually exclusive? is there a way to get a rule tile to paint tiles on a floor map with no collision and a wall map WITH collision?
is this a 2d tileset thing?
yes'
ah, shit. i don't know much about 2d in unity, apologies
all my 2d stuff has been lwjgl or monogame
no one does here so no prob
#🖼️┃2d-tools might know more, but I also haven't touched 2D
yeah there is a 2d tools channel in artist tools, if you aren't strictly after a scripting solution
the already complicated onboarding process of the new input system
you don't have to remind me. i nearly cried with relief when i found out you could tell it to generate InputSystemActions.cs
i'm developing this game almost entirely through code so having to stop and work out the editor side was giving me an aneurysm lmao
Yeah, the Input System is, like, stupidly powerful, but it also reeks of design by committee, and that's why there's like twelve ways to do anything in it because a bunch of people couldn't agree on the best way to do something and just stuffed it with a bunch
I still am not sure I'm actually using it right most of the time
From what I've been told, by talking to people who worked at Unity and people who knew people that worked at Unity, it's not a "designed by commitee" problem. It's a "does this bring money to the company short term?" problem as the company was seeking to only grow profits.
So the resources allocated to make this were there, and then not, and then they were, and then they redid it because no one was there, etc.
DOTS and ECS had the same problem
Development Limbo as the future of it was uncertain, not because there were too many chefs in the kitchen
🌈 Capitalism! 👐
this is where all bad code comes from
that and yanderedev
the latter seemed to be self-taught so I can kind of excuse them producing bad code
Oh yeah. I've got no clue if I'm doing it right, especially since my control scheme is really complex
It's usually inevitable
Balatro was terribly programmed too, but man do I love that game and don't care at all that it was badly coded.
oh yeah, a lot of successful indie games have awful code. terraria used to (and might still) determine item stats using a massive switch statement.
literally thousands of lines
Terraria still has it ye
minecraft originally handled first person animation by just using immediate mode OpenGL in the main game loop
If it works :U
Balartro isn’t to horrible tbh, at least in the examples that we’re floating around
Step 1: Make it run
Step 2: Make it right
Step 3: Make it fast
And always that order
eliminate step 2 if profits are involved
Meanwhile nowadays people making minecraft mods for their thesis
or their job even
It's not as bad as some other code I've seen from other released games (like the Shadowrun games on Steam. The nightmare it was to decompile those games). But it wasn't exactly average either.
kenshi wants to know your location
(tbf, Kenshi did do something really cool, which is pathfinding through unloaded regions of the world)
One that surprised me a bit is that Lethal Company commits a fairly small amount of sins given the development context
lethal company was written by a furry, and they're always inexplicably good at what they do. and rich.
i have never known an incompetent furry
"yeah, i'm a brain surgeon. i live on a superyacht with my summoned minions and dress up like a neon green dog."
I have seen plenty
a majority of the game was made without events or properties so don’t go too far lol 😛
Which one?
events as in C# events or
because I am not using those myself (I actually hate the C# event system)
i wrote my own
(it was painful)
We are one plane crash on the way to AnthroCon from total societal collapse
c# and the general concept
What's wrong with the C# event system?
reminds me of the time I got off a plane to Seattle and was greeted with a military escort because 3/4 of my flight were air force veterans
oh i just personally don't like it
nothing wrong with it from a technical standpoint, using it just makes my brain itch
Right, but I wanted to know why you didn't like it
I get annoyed at the += and -= syntax for registering listeners mostly
Is it a syntax thing or?
It just feels so unintuitive
it's hard to explain. i am probably a little bit on the spectrum lmfao
could also be the adhd though
Are you not just adding a pointer to a list of pointers?
In that sense I think it would make sense to use that
it's a bit more complex than that unfortunately
there's some weird shit with MulticastDelegate
Right, I get why it was chosen, but syntactically it just doesn't seem right
You don't += to add things to a list
Which functionally ends up as a bunch of pointers
So why += to add things to a list of pointers specifically?
True. Although now I question why not because that seems easy
I mean you could probably write an extension method for that one lmao
Its because you can assign or add to delegate types normally but event changes functionality such as preventing assignment outside the class
Also for my own game I didn't like how the event/delegate system felt like it was discarding types
Yeah, I get it. I just don't particularly like it. I deal with it anyway
I love events I use them a lot 😄
I wanna be clear that, I'm not here to change minds as much as to understand why the syntax was annoying. I think I get why you don't like it at least.
I used to do Minecraft server mods, so I wanted something where I could do this
[EventHandler]
public static void TestConstructionCompleteHandler(ConstructionCompleteEvent @event)
{
// do whatever
}
oh god the format, hang on
okay discord is not cooperating today
i give up
i have never before had it not register the language like that 💀
I'd like somewhere between C#'s entirely too abstract but incredibly concise += syntax, and Java's "Add an entire goddamn package in the middle of this anonymous function" of early Swing
I use C# events whenever I can. They are fast, easy to setup and make for such an easy event system the way I use it at least.
I don’t like having to nullcheck empty ones either but that’s just dumb brain wise
java lmfao
i have a love hate relationship with that one
i stopped talking to java developers because every question was answered with "use this package"
People do that with JavaScript and Python too.
Fortunately, I have never had to use JavaScript, beyond one uni course, where I wanted to die
python devs be like "checkout my cool one liner!" but dont realise it just wraps some C lib 😆
If it gets the job done within spec
i use the typing library explicitly to make them sad
🤷♀️
but yeah I just wanted to be able to declare event handlers via annotation and have them respond only to a specific event type
and I didn't know how to do that with C# events, nor did I want to learn
normally I will learn new things as needed, but something about the event keyword just wasn't clicking for me, even though it seems simple in concept
so in java its just magically done for you?
how I ended up writing it is pretty much identical to how Spigot handles it for minecraft servers
nah
Look at this simple event system
public static class ItemEvents
{
public static event Action<GameObject> OnItemPickedUp;
public static event Action<GameObject> OnConsumablePickedUp;
public static event Action<HotbarData.HotbarSlot> OnHotbarSlotUpdate;
public static void BroadcastOnItemPickedUp(GameObject item) => OnItemPickedUp?.Invoke(item);
public static void BroadcastOnConsumablePickedUp(GameObject consumable) => OnConsumablePickedUp?.Invoke(consumable);
public static void BroadcastOnHotbarSlotUpdate(HotbarData.HotbarSlot slot) => OnHotbarSlotUpdate?.Invoke(slot);
}
Love the simplicity of it ~
this looks pretty straightforward honestly
Because it is 👀
Anything can Broadcast, anything can listen.
It's the Mediator pattern.
Fancy that
I think my big thing might've been something to do with event priorities
but I'm sure there's a way to add that lmao
Sure, if you require prioritzation of sorts, then my approach would be far insufficient
well there is no such concept unless you program your own thing
Out of curiosity why pass go rather than a related class ref?
this sure is what I did
hence the [EventHandler] annotation lmao
sorry "attribute"
annotation is the Java/C++ term
I just needed to get a specific finnicky component from the gameobject that was affected and this was means that if something changes in future, I can just let listeners change their approach rather than senders.
I use this cute little wrapper for events myself
https://github.com/IAmBatby/IAmBatby.IterationToolkit/blob/main/Runtime/Scripts/ExtendedEvent.cs
i'll have to take a look at that one
What does it do?
What does it wrap, I suppose
UnityEvent does this already btw
well the inspector made ones are yes as they are implemented with reflection
They are useful for the few times where you need them, like UI events and other event invocation lists on components
but code subscriptions should be almost the same as normal
you can actually use reflection to implement things "quickly" but it's a huge pain
ask me how i know
I hear someone say events https://www.youtube.com/watch?v=co4s1zC7q6o
I remember I saw a benchmark test pitting UnityEvents and C# events against each other.
The C# events won out because while C# events might take more to allocate, their speed over a long period of time far outclasses UnityEvents
It could of course be that Unity changed this since that benchmark. It was a while ago.
Nothing crazy just kinda half a unity event. Built in null check, add/remove functions rather than += and you can add paramless listeners to param events. I have a very scuffed implementation somewhere else that clears them statically when you have that one domain setting disabled
generally speaking anything that uses Delegate.DynamicInvoke or similar will be slower
Action is much faster IIRC
Not to be confused with Invoke on event
public static event Action<GameObject> OnItemPickedUp;
I use actions at least 👀
But far as I was told by someone much more involved with C# than me as soon as event is used, it will be treated as a delegate under the hood anyway. Unless I misremember.
IIRC multicast delegate also allocates more than if you manage your own List<Action>.
Hm, I see. Sounds like a lot to keep track of but I do see the usefulnes in an implementation like that some times.
Couple reasons I didn’t wanna use those but won’t pretend they are not very similar. (One being I explicitly do not want these in inspector)
honestly best thing you can do is just benchmark your shit
use the profiler in the editor
address issues as they arise
then you'll know which event system is causing slowdowns lmao
I’m a game designer turned programmer so a lot of my shit compromises on preferred programming practice if it can further empower easier prototyping with potentially less required programming knowledge 😄
i'm technically a professional game dev (except i hated it) and i do this shit too. imo this is the saner approach lmao
As we talked about earlier, in the end if you get your game out and it works to spec, then it doesn't really matter all that much how you do it. That is one thing that games have which traditional software does not.
Hey, is there any way to control the speed variable of the cinemachine spline dolly when auto dolly - fixed speed is turned on via code
#🎥┃cinemachine might know? idk if they handle scripting there
I’ve yet to find industry work so i am the spec fortunately
if you can make a living doing indie dev, do it
or working for a smaller studio
i worked for a huge publisher (probably the largest one actually, i never checked) and the workload was just...too much for me after a while lmao
started getting really anxious every time i wasn't at my work pc
I started this repo to start looking at patterns in C# from a games context. I recommend checking it out if you wanna level up your programming 🙂 https://github.com/mads-fs/csharp-patterns
we devs get crunched a lot cus we are often at the end of the chain 😦 Hope you are doing better now
Yeah I’ve gone for local funding before but no luck. Doing a shit it diploma right now to get a semi related job to support living then will probably persue further.
Had a big mod blow up but no job leads off that unfortunately
Ooo ty
It's not complete, but it has some of the more useful ones I'd say
thanks. i got laid off like a month ago and i'm doing an indie project for now, i feel a hell of a lot better. i've still got some residual brain fog around programming from the stress but even though the game i'm working on is far from simple, it's still easier than working in rendering lmao
tbh if you wanna look into funding, Bigmode is a publisher for indie games. youtuber called videogamedunkey started it to try and support indie devs. was considering applying for support from them myself, but i'm paranoid so i wanna make more progress before i do anything like that
alternatively if you have an actual prototype kickstarter could help, i'm planning on doing that myself if i make enough progress before like...october
Kickstarter is basically "have a finished game" now, so I wouldn't count on that necessarily.
But work up to word of mouth, early access on steam and that might actually get you close to a kickstarter.
yeah, that's what i'm planning. i guess when i say "prototype" i mean "early access" lmao
I’m in a weird position since i’ve studied professional game dev (luckily really good course tbh) and have been using Unity for about 6 years now. With some recent modding and editor tooling stuff I feel pretty confident about my ability to use c# to make solid systems in a game-dev context and I’m reasonably experienced in wrangling Unity abit but the lack of working on larger scale productions and not coming from a programming specific educational background has created a lot of blindsides for me that I’ve been trying to patch up. that link looks like a good way to help in that 🙂
At the very least, the repository was an attempt at making engine agnostic example code which implemenets commonly used programming patterns which have been nicely explained on a link in the README.md file.
Dunno if this is off-topic atp but here’s a snippet of the game I went for local funding for which is a a-symmetrical multiplayer game about the brutal working conditions taking place at the north pole
The page that I link to in the repo description is one I come back to often when I can't quite remember what pattern solves my problem. 9/10 times there is a pattern on that page which gets close or outright solves the problem, because that's the beauty of programming; simple building blocks that can give you infinite complexity which repeats.
one good thing that came out of working in AAA - i keep forgetting i actually do work relatively fast. it's been a bit over a month and i have a working content loader, a job/task system, an AI system, a building system, and functioning inventories for entities/structures/etc. and I keep beating myself up for not having more done lmao
could all use some polish but that's the easy part
Like using the factory pattern for persistence or achievements so you can support completely different storage and achievement APIs irregardless of platform without having to make separate codebases for it
Interfaces are often criminally underused in games programming, at least those interfaces you can write yourself, and it's a shame because they are so powerful both for making your games but also to write tests for, which is a whole other beast of course, but still.
I only found out yesterday that interfaces can request property definitions and implement default functions (although thats controversial ig). Which has made me eager to dive in abit more
In a game I'm working on right now, which is on steam, I've had to rewrite the persistence api from scratch as the one that existed before was just awful to work with.
To do that, I made a simple interface:
public interface ISerializable
{
public byte[] Serialize();
public void Deserialize(byte[] data);
}
And I put this on anything I want to persist. Then I implement the methods for whatever I put it on and add it as part of my save routine so that it gets included with everything else.
This way, my persistence api does not need to care at all how something is serialized. The object itself knows how to be deserialized again. I just need an identifier so I can let the object deserialize itself properly, and that's it.
this is basically just how you handle serialization in clangs
java/c# serialization is always so overcomplicated lmao
only time that's justified is when you're doing json/xml content loading
if you're just reading/writing objects from/to a file that a user is never gonna touch, just write out the bytes, problem solved
I don't know how it's complicated. I let a binary reader and writer do it's job and that's it 🤷♀️
I don't need to care about any other complexity
sorry if it wasn't clear but i meant i prefer your solution lmao
it's much nicer
Hello im trying to get ray casting to work and its not working for me, no red or green debug recast or the enemy moving.
{
[SerializeField] float speed;
private GameObject player;
private bool hasLineOfSight = false;
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
}
void Update()
{
if (hasLineOfSight)
{
transform.position = Vector2.MoveTowards(transform.position, player.transform.position, speed * Time.deltaTime);
}
}
private void FixedUpdate()
{
RaycastHit2D ray = Physics2D.Raycast(transform.position, player.transform.position - transform.position);
if (ray.collider != null)
{
hasLineOfSight = ray.collider.CompareTag("Player");
if (hasLineOfSight)
{
Debug.DrawRay(transform.position, player.transform.position - transform.position, Color.green);
}
else
{
Debug.DrawRay(transform.position, player.transform.position - transform.position, Color.red);
}
}
}
}```
- would suggest naming your raycasthit
hitinstead ofray, for clarity, but that's a nitpick - aRayis an existing type - put your debug draws outside the hit check so you can see what ray is actually being cast, regardless of hit
- from what I'm seeing, if
hasLineOfSightistrue, it will remaintrueif the raycast hits nothing, because it only updates the value ofhasLineOfSighton a hit. maybe this isn't a problem for you but it does seem to mean that this enemy will stalk the player indefinitely in open areas, provided it saw the player at least once lmao
Little known fact; under the hood, Abstract Classes and Interfaces are the same :U
Neat. Ive been trying to find a pattern I’m comfortable with that basically does that explicitly, with a generic interface that requires a reference to a real class so i can handle creating content via composition in a way that supports stuff like GetComponent
Well, MonoBehaviour already is that
fwiw
you can always do
public interface GenericInterface<T> where T : new() {}```
I don't know offhand if that works for abstracts
but you can't do new on an abstract lmao
That is close to what im using yeah
I use that for singletons since i've got a few of those lying around
Either way, don't abstract too far too quickly anyway, and don't generalise too much either. It will become a problem later when you need support for specific use-cases rather than generalised ones.
I add public GameObject gameObject {get;} to an interface used on monobehaviours only 🙂
The enemy is not even moveing wven when it is in sight
yes so draw your rays regardless of whether you get a raycast hit
then you can see if you're just raycasting in the wrong direction, etc.
i didnt give it a specific direction
you did in fact give the raycast a direction
player.transform.position - transform.position
realised that the server blocked questernmarks huh
oh huh..
which...looks correct, off the top of my head
I just riped this code from a video and it worked on his end also his video is juts a year old
e.g. if your player is at (1, 0) and your enemy is at (0, 0) it should raycast in the direction (1, 0)
Forsure I’m just building a similar system for my own tailor made content setups. Ideally I think I want a “EntityBehavior” / “ContentBehaviour” class managing a given piece of content and smaller classes under it for individual feature support, (eg, value, saving, pickupable etc.). Pretty much what interfaces are for(?) but with their implementation aswell
And then inheritance on the Entity/ContentBehaviour is used to define those smaller modules/features via the interfaces
i would suggest making sure you read and understand the code
there's nothing intrinsically wrong with copy-pasting code for really generic use cases like this, provided you know what it's doing and why
but if you don't, it'll cause you problems later on lmao
yeah obv still confused why it didnt work as the use case was simple
again, try invoking your Debug.DrawRay calls regardless of whether or not the ray hits
Hmm, I think you might be working against the engine a bit there, unless I misunderstand. The MonoBehaviour Compositioning model is already one that can give you a bunch of compartmentalized design which increases your flexibility. Then you save Interfaces for the more abstract things which might not only account for MonoBehaviour specific functionality (as interfaces could be used anywhere) or you create specific generalised interfaces that all monobehaviours should have and let game logic stay in monobehaviours.
To get a direction to a position it should be target - me
right and that's what he's doing
player - self
(this is for an enemy)
you are right carry on 😆
(as an aside you might want to do (player.transform.position - transform.position).normalized * viewDistance or something, so you can give enemies dynamic view distance...and you can do vision cones with dot products so bro isn't psychically aware of the player behind him)
(but worry about that later)
i putDebug.DrawRay(transform.position, player.transform.position - transform.position, Color.green); in my FixedUpdate, nothing
should be in OnDrawGizmos()
FixedUpdate is only really used with physics stuff
oh really huh
But it should still draw
It'll be on the far right here, at the top of the play window
It's only when you do Gizmos that it has to be in the Gizmos call far as I remember
i'm using it for my game logic at the moment because the player is in control of the game speed
I don't follow the logic there
fixed
Wouldn't you just put it in a LateUpdate then?
wait, I don't get why I'd use LateUpdate here then
the draw ray works but its only on red
screenshot?
to be clear the player is also controlling the speed of any physics simulations lmao
You said you'd use FixedUpdate because your game logic lives there since "the player can control game speed", but FixedUpdate runs in fixed step (hence the name) so unless you are doing strictly physics related game logic, why run it in FixedUpdate?
does your player have a collider?
ah nvm I see what you mean there
yeah, cant go though that wall
are you using visual studio?
yeah
you can try setting a breakpoint and hitting "attach to unity" at the top before you run your game
click on the left side of the code window to set a breakpoint
(the white is just where my mouse was, the red is a breakpoint)
if you set that on the line after your raycast call, you should be able to inspect the raycast result and the collider it hit, if any
at RaycastHit2D ray = Physics2D.Raycast(transform.position, player.transform.position - transform.position); ?
i guess this is what has me confused, my brain views "update" as things that can afford to be dependent on FPS lmao
right after that (breakpoints will be hit prior to executing that line)
FixedUpdate does not run in step with the rest of the game. It runs separately at a fixed step to keep physics consistent.
But why you'd delegate all your game logic to FixedUpdate when some of it surely is dependent on the Update loop unless all of it is physics based.
ah, that. i'm trying to keep my game logic as removed from Unity as possible tbh
Not sure what that has to do with using FixedUpdate then.
i put it here ok
yeah i don't know either if i'm honest
that's fine yeah
when you hit "attach to unity" and run your game, it should trigger the breakpoint, and you can mouse over ray to inspect it and see what collider says
the fun part is that because all the updates are invoked from a main game loop, I can just change the loop to be invoked on Update instead if need be
All Update calls in all MonoBehaviours are run on Unity's Main loop
So unless you mean something else I'm not sure I follow
right. and i don't have any update calls on those
FixedUpdate is no different in that sense. The timestep is just fixed.
monobehaviours in my game are basically just ways of binding something like an Entity to a gameobject
is this normal??
switch back to visual studio lol
Have you considered just, using Unity's ECS?
It might be more your speed.
elaborate
what I wanted to do was write my own game code and basically just interface with Unity as little as possible lmao
If you just want somewhere to tie data to, so that GameObjects are data objects and you have separate systems to manipulate that data, then you are losing a lot of processing to GameObject overhead whereas if you use the ECS implementation instead you'd just have data and systems.
im on visual studio rn
ah. I mean I'm using gameobjects to actually hold and render the meshes/etc.
yeah that "hold on" bar will be visible as long as you're on a breakpoint, that's normal
does the ECS provide an alternative to this?
ECS stands for Entity-Component-System It's a paradigm. One that Unity only half follows with GameObjects but intended to codify better in their own "Unity ECS" implementation.
I know what an ECS is, but there seems to be a distinct difference between "unity ECS" and the term "ECS"
so I'm wondering what the hell it is lmao
ECS is just the paradigm. Agnostic. Not tied to anything.
Unity ECS is their specific implementation of that paradigm.
is this an upcoming thing?
GameObjects are partially ECS but there is no distinction between E and C so it's more EC-S.
or like a beta or whatever
No you can use it right now.
i'll have to look into that, i'd like if i could just handle all my game logic and not have to interface with gameobjects honestly
It requires that you change your way of thinking, but you do become a better programmer from doing it ultimately anyway.
A big part of my problem is that I'm going to want to fence off game entity updates
Unity's own learning resources on this are quite nice, I found.
sorry about having to keep distrubring ur convo but idk what i do next for this
nah it's fine
Oh don't worry. Your issue comes first @wheat shoal
Please interrupt.
when you go back to visual studio, you should see your breakpoint with an arrow on it
try mousing over ray
this just seems like what I did in AAA anyway
I would be surprised if there are any serious AAA studio out there who are not primarily using ECS
well, we didn't use an ECS lmao
but we did store everything in subscenes and "bake" them
I pin it?
except that "baking" process took a long fucking time and honestly everything sucked.
good idea in principle though
you can click that little arrow to expand the tooltip for more info
ah. so what's happening is that it's hitting the rifle.
could anyone help me optimize this? its currently super super slow and is not exactly functioning how I expect. Its supposed to randomly place structures around a tilemap however it is leaving a lot of open space despite rejecting most of the structures due to it not finding a position. It does work though so there are no bugs. https://paste.ofcode.org/HtdDiZrTzQywXLQ9Za7LRK
you can see under the collider field it's hitting the rifle first
the entity is called EnemyRifle
that's what the ray is hitting
so you'll have to use something like layers to only raycast for the player, or use RaycastAll and go through your hit results for the player
That might not be totally right, but it's roughly what you'd do
what i mean is this thing is CALLED EnemyRifle as im gona have multiple enimies with diffrent guns but same other atributes
Are you doing something like generating lists of possible structure locations and placing them randomly?
not really the point - your raycast is hitting that collider immediately
that's the problem lol
ECS is not a thing, it's a paradigm. A way of thinking about code.
that's why it's not picking up the player
yes. we did not have anything like an ECS.
"An"... 🤔
sorry got confued bu ur answer for a bit
yes so the input is a list of structures which is a just a premade small tilemap
it contains duplicates as well
There are implementations of ECS, yes.
But "an ECS" is not a thing. Confusing.
i think colloquially "an ECS" would translate to "an implementation of ECS"
Not at all. Never heard anyone call it "an ECS" before.
well, now you have :p
Apologies, early morning on public transport so I’ve partially butchered what I’m trying to convey.
I wanna do this all with MonoBehaviours and work with the Unity ecosystem but I want to build my own content system for prototyping that is based around modular components (I’ve been calling them Modules or SubBehaviours) that rely on being managed by the prefab root managing class/ “brain” (I’ve been calling this a ContentBehaviour or EntityBehaviour).
C# doesn’t directly support multi inheritance and of course Unity is built to somewhat support it by multiple components living on a given gameobject. The thing I’m looking to support for my own usage is the explicit required associates and chain of command between these separated components.
I don’t have a working and comfortable implementation yet but I wanted to use Interfaces for this to define what SubBehaviours are expected to exist under a ContentBehaviour, very rough eg
ContentBehaviour : MonoBehaviour
ContentModule : MonoBehaviour
IContentModule<T> where T : ContentModule
public T Module { get: }
IValuable : IContentModule<ValuableModule>
ITransportable : IContentModule<TransportableModule>
ItemBehaviour : ContentBehaviour, IValuable, ITransportable
I know it’s probably not super ideal in the long term but I think something like this would help me prototype a bit better and it’s been fun to learn more c# stuff to try and figure it out
EDIT: There’s also this whole side-layer of scriptableobject stuff im omitting here for conversational convenience
right - how are you getting the placement positions for these structures?
at the top of the TryPlaceStructure function it will take a random starting position from a list of possible positions however it has to check that the bounnds of the structure all are in walkable positions as well
sigh
RaycastHit2D ray = Physics2D.RaycastAll(transform.position, player.transform.position - transform.position);
gives error
Cannot implicitly convert type 'UnityEngine.RaycastHit2D[]' to 'UnityEngine.RaycastHit2D'
fml cant shit just work
Without knowing what you are trying to accomplish with this exactly, it's hard to tell if you are overengineering a solution for something or generally trying to solve a problem you are having. Given how many game jams I've been to, prototyping is the easy part. It requires no special setups to do 🥲
i mean are you getting those positions with something like Random or
yes this matters lol
ah mb, I missed that
let me check something
I don't think Random.Range uses any kind of normal distribution
Valid. I don’t doubt it’s over engineered tbh but I think I’m personally getting stuff out of doing it so 😅
wdym i just want a random position haha
pseudo-random number generators can and will result in irregular distributions
yeah, and that's sorta the issue
you can easily end up accidentally trying to place the same structure in similar places
I'm sure you'll get something, but it's hard to gauge what and whether the headache of trying to crack this nut outweighs what you get.
ok so how would I fix it?
is that the cause of the problems tho? i doubt that would improve performance anyway
Imagine you roll 100 dice and get 6 every time. It’s valid random result but probably not what you’d be looking for
ah makes sense
It's not the cause but it is definitely related
Have you checked with a profiler what causes your issues?
You can use something like Halton or Hammersley sampling for a uniform distribution in 2d, but anyway
RaycastHit2D makes 0 sense for something that returns an array of hits..
maybe try using the correct types lol and it will just work™️
its the constant checking over every iteration
if a position is valid
lmao
Getting the squareroot is slow 🤷♀️
But is it too slow? Eh. Depends.
i'd rather just use uniform sampling and cache it, but i digress
Yea other ways to overcome if it was an issue
I might have missed something, but how are you checking if a position is valid? Do you check it up against every other position or?
you can probably resolve this mathematically instead of checking for valid placement on every possible tile, but i'd have to think about that
i could use poisson disc sampling
its the top function, i just check if the position is walkable and its not a structure
I've used Poisson Disc Sampling before. Was pretty easy with a video from Sebastian Lauge.
over the whole structure
sebastian lague is an absolute unit. i've been piecing together a bunch of his stuff on worldgen with some other resources for my own game and he explains shit so well
Do you save information about a tile that tells you whether it's walkable or not?
yes
Should be easy enough to check a bunch of bools
yeah i mean - if you're placing 100 10x10 structures, that's still only 10k checks, which isn't a lot considering modern cpu speeds
It is a lot to go through because GameObjects
i dont use gameobjects to check
the tiles are stored in a dictionary with position and flags
gameobject my behated
How do you retrieve positions?
everything is done using vector2int until the end where i place it all on the tilemap
the tiles are stored in a dictionary
depending on your game you may want to try using a 1d array
I yearn for more highly produced content where it’s just smart people talking about their experience learning something new
sorry, you'll just get my devlog where i explain why i'm an idiot in 37 different ways before settling on a really obvious solution
i did find this one interesting https://www.youtube.com/watch?v=gsJHzBTPG0Y
IQ's Article: https://iquilezles.org/articles/morenoise/
A video about convolution: https://www.youtube.com/watch?v=KuXjwB4LzSA
MUSIC
Colorful Flowers by Tokyo Music Walker | https://soundcloud.com/user-356546060
And So It Begins by Artificial.Music | https://soundcloud.com/artificial-music/
Stay Chill by Sakura Girl | https://soundcloud.com/sa...
Have you considered using the job system or something to delegate the task out?
nope would that help a lot?
I would unironically just consider using a 2d array instead of a new vector2int every check
The job system is incredibly powerful if you can use it right
I don't actually know the overhead of doing that
2d array instead of what
Knowing those 37 failed attempts is fascinating!!
Acerola and ThinMatrix are channels I keep up with too
Acerola is a rare wiz. He knows the fundamentals and can extrapolate solutions from knowing those basics.
you've got a dictionary of vector2int instead of just Tile[][] or Tile[] (where the index is y * tileWidth + x)
oh man wait until you hear how many iterations i went through on my job system LMAO
before settling on
manually declaring job types
A dictionary should still have fast enough lookup.
it should but i'm not a fan of that new Vector2Int in n^2
It's adding to a dictionary that's slow, not the look up. The lookup is hashed.
Granted I don't know how C# handles new structs
https://paste.ofcode.org/iBpPgwukmCx5xYXayYfBwU this is my tilemap placer if you want to look
coming from C++ I'm always suspicious though lmao
i see
i'm not saying the dictionary is the issue fwiw
Though depending on the dictionary implementation you can run into really dumb cases where collisions slow it down more than necessary - but I don't think the C# Dictionary is that bad
ok makes sense
like I don't think the dictionary is necessarily the issue here
And where do you say the problem is?
no problem, he was just asking about the dictionary usage
all the tiles are stored there instead of constantly checking a tilemap
which i assume is more costly
Nah the dictionary is fine, in principle
iirc they said it was CanPlaceStructure but don't quote me on that
@merry stream do you think you could screenshot your profiler?
...can you use the visual studio profiler on unity? that might be nice.
lemme look that up, it goes a bit deeper
let me see how, i have just been putting timers before and after functions lol
does the VS profiler have a stroke if you try to use it with unity lmao
I don't think so, but why would you use it?
vs profiler lets you go pretty in depth
does unity's let you see stuff like new allocations?
Have you never used it?
I last used it like...3 or 4 years ago
when I was in uni
I used it the other day just to make sure my code wasn't eating a bunch of CPU time but didn't bother investigating further
It is one of the best profiler tools for a game engine around. Just use that to profile your game instead of trying to beat a system you haven't tried to use 🥲
Makes your life easier
It's easy to use. Open the Analyser on a separate thread. Make sure the record button is toggled.
Start playing. Do things that are problematic for performance. It will show in the graph. Then stop playing.
Now you can step through every frame of the debugger, read everything and do deep analysis.
Remember guys if you use new more than 0 times a frame you are a bad dev /s
Im going to try this, i always presumed it wouldn't work due to old mono
Huh?? Are people just looking at the debugger going "Eh, probably doesn't work and I'm not gonna check either." 🥲
I understand memory management decently enough and I usually manage just fine with the unity profiler
Then your comment confuses me
I am interested in utilizing the VS profiling tools with unity also as i presumed they would not function
You'd be analysing the editor mostly
Unity's profiler allows you to separate the editor overhead
Microsoft's profiler, from what I know, would not be able to do that.
MS profiler would let you view the callstacks but you'd have to parse them out yourself i'm sure
VS can show you the callstack of calls you debug
have you used the VS profiler recently? it's quite in depth
To a point anyway
but you make a good point about separation of editor/player loops, and yeah unity's is already solid
took a sec to figure out wtf i was looking at
I use VS often, yes. I have used it for years.
My point is that, if you are going to profile your game, you can't do much better than Unity's profiler.
Visual Studio is for debugging the game primarily, not profiling.
"what's with this script overhead" -> hdrp scripts
i used a lot of vs profiling at my last job :') and renderdoc lmao
Did you get the profiler running?
completely unrelated but configuring animations solely through script is rough
That is one area that Unity needs to really up their game. Animation. It's currently one of the worst systems to work with.
i actually don't mind messing with it in the editor, but linking up my state machine implementation with script-loaded animations is a little "hmm"
I'd still rather do the animations in Blender than use an in-editor animation system though
Thank god for stuff like Animancer
I got my code working :)
nice, congrats
It lets you treat your animation as data, meaning that you don't have to make the same state machine a million times.
You just make it once, reuse it and switch animations as needed.
@old elk thank you for the advice
🫡
im just using menu options to run the generate map function
yeah i mean i have a state machine for handling movement already, as well as AI
was thinking about how i'd resolve animation in that context lmao
but I forgot the builtin animation system through script is...not fun
thank you for reminding me Animancer exists
I meant more that Animancer acts as a Unity Animator abstraction layer so it works with Unity's systems, but makes you able to not have to deal with them at all.
mb, I misread what you were getting at - but yeah that's an excellent argument in favor of it
I'll probs pick it up again, the full version this time since I'm not a broke college kid anymore lmao
So you could make a simple state machine for bi-pedal movement, use it for all bi-pedal characters, yet just switch the animation sets out as the logic stays the same.
With Unity's animator, you'd have to remake that state machine for every single use-case that isn't the same bi-pedal gameobject
yikes
Doesn't help that my animations are dependent on both task and movement lmao
e.g. "play hammering animation if doing construction task"
you can extend mecanim with custom states to do anything you like, inject other animations etc. just the default system doesn't allow for the mobility you describe
Yeah that's the issue I have with it really. It feels incredibly outdated to work with, imo.
It could use some love
animancer is also built with the playables API, you can always use that directly
True. Playables are nicer at least. But I do prefer the abstraction that Animancer provides, personally.
i think almost nobody is aware that thing even exists
promotional issue
yes, animancer is very nice
I have found that surprisingly few use it even though they have problems that the Playable system could solve for them
i'll probably just end up using animancer honestly
playables is quite annoying to use directly
i'm not opposed to libraries (i might switch to the A* pathfinder as well), I just tend to avoid them since I might want to modify something that happens under the hood
it's why i don't use cinemachine lmao
is cinemachine nice? yes. but it's also not something i can't recreate myself
literally just a control issue at the end of the day
I like Cinemachine is principle, I don't like the execution. Feels way overengineered even for simple setups that are widely used.
problem with animancer is that you can end up with very ugly/complicated code unless you have a great appreciation for formal state machines
this is exactly it
Yeah you gotta write nice code
But at least when you do, man can you efficiently reuse it
indeed
the main thing it allows is to have objects (say an interactive one, maybe a gap in a wall) provide the animation to the controller instead of each controller having to declare a state with an animation for that object
this makes it much easier to extend a basic controller with new content
same thing with mecanim looks very ugly
yeah, I have an ai node that's just "perform task", and that's generic for every job/task a colonist can perform, so having the Task instance actually able to provide the animation is important for me lmao
not C# generic, but just a general-form "do task" node
i think the value in cinemachine is in the UX when making cutscenes and that its a generic problem which has little value to be reinvented for every project.
it being standard allows integrations to be developed, like timeline/sequences
I have been organising Nordic Game Jam this year, the biggest game jam in Northern Europe, and we had a great speaker this year. Tommy from AI & Games. In his talk he gave a good example of how you can handle a lot of complexity when it comes to AI and animations. The idea is basically that, every object knows how it can be interacted with and AI simply requests to do an action to an object. The object then guides the AI on how to do that.
So if the action is to sit down on a chair, and there are many ways to do that depending on what angle an AI comes at a chair at, the AI can simply request to sit on the chair and the chair will find out what animation needs to be used for the AI to sit on the chair. The chair knows how you can sit on it. The AI does not need to know.
This can be extrapolated to any number of objects.
this is pretty much exactly how my game works rn
good to know i was onto something lmao
yes, this inversion is basically required for any sophisticated AI that is supposed to stay maintainable
all my AI does is "do your fucking job" and the job is responsible for explaining how it's supposed to be done, problem solved
also the idea that your AI code should be a 'solver' for action problems makes things much simpler
Mostly offtopic but I’ve had to do some modding stuff with Unity’s animation system and my lord is it a nightmare to touch at runtime. I’m still shocked that you can’t read the data from AnimationClip’s at runtime
That is one of the biggest turnoffs
I immediately give up on modding anytime I have to make a Unity project to do it. It's why I never got into Risk of Rain 2 or Core Keeper modding.
I really dislike the Unity Animator
Modding through the editor is a god damn nightmare
I'm basing my game off how Rimworld and Elin handle mods instead, which is never having to touch the editor lmao
Kenshi isn't Unity but it comes with a "modding tool" which is just an abstraction around editing config files anyway
Personally disagree but it depends. A developer called nomnom made a built in implementation of assetripper that simplifies a ton of the process.
For lethal company my api allows creators to make moons, items and interiors in the editor with no code required which turned into a pretty nice workflow for newcommers
i thought i recognized your name from somewhere
😅
I haven't tried to mod through the editor since Core Keeper 1.0 released, before that i tried it with RoR2 and it was just
no thanks. never again
even now my own game's scene is just a few spheres, everything happens through code instead
handy for ensuring assets look right, though
The unity animator can sometimes look like tangled cords
downside is that debugging my own shit requires custom UI 😎
I don’t have first-hand experience with risk modding but lc modding built up without re-using any of the established concepts and workflows or the risk scene and I personally think we ended up with with some preferable solutions and workflows. That one tool they use to build bundles looked scuffed as hell
iirc the unity 7 animator should be better
That's because it was scuffed as hell
I never got into lethal company modding since I didn't enjoy modded lethal company though
one of the rare few games where I liked it exactly for what it was
Honestly I don't mind the visual representation. It's a state machine so that tracks.
The issue is that I can't generalise that state machine. It is locked to whatever animator file I'm working on.
non-generalisable anything is a turnoff for me unless it is a very specific system
but I mean I even generalized my content loader lmfao
can people use it to produce jank? yes, but that's on them
Totally fair. I'm personally someone who prefers mods that heavily follow the pre-established design rules of the base-game so I think I agree a fair bit. Although there's quite a very crazily high quality mods
I am of the opinion that, all the time I spend making something more generalised is time I don't spend making my game.
So if something doesn't reasonably needs the flexibility that generalisation allows, I have to stop myself from trying to be smart about it. Took some time to break that habit, but it pays off.
yeah I mean I think some stuff like the skinwalker mod fit the base game concept, but i was never crazy about like..."9 toolbar slots", "16 players", Among Us level cosmetics, etc.
this is a smart approach to it, tbf
and honestly I struggled with it a lot for my job system
er, task system, whatever you wanna call it
(not unity's job system, sorry)
You using GOAP or something?
I went through a few iterations of it where I kept trying to figure out if there was a way to just be able to declare a Task derivative (not C# Tasks...there's no good name for this system that doesn't overlap with something lmao)
uhh, not exactly
For my AI, I want to do something like that, but the task system is much simpler
GOAP is fairly simple in principle.
basically just
"build this blueprint"
"haul this item here"
etc.
You have a goal, the AI needs to figure out how to reach that goal given it's available actions.
and there are composite tasks like "haul resources to blueprint, then build it" that are just compositions of simpler ones
funny enough the issue i kept hitting had nothing to do with that aspect of it and everything to do with having information on available job types at runtime, and eventually I caved and just declared all of that manually lmao
i like to think i understand reflection better than most people, so it wasn't an issue of whether i could, it was more like...
Task has an abstract property for Name, but Name is something that is functionally static and unchanging for every derivative of Task. shit like that
if your game doesn't generate player value out of these clever AIs that figure solutions from componennts, you can just make "blueprints" for a whole sequence of actions (move + act) and solve all of those with fairly simple FSM or behaviour tree
One example of something I really like (little bias cuz I helped abit) is Chameleon which is a mod that does asset replacement to interiors to subtly theme it for the moon your on. (so eg. if your on a snow map and are in the Mineshaft interior the cave rock texture will be snowy etc.).
Also was a big fan of this mod I was working on but have yet to release https://www.reddit.com/r/lethalcompany/comments/1fi1n5u/heres_a_preview_of_stargazer_a_mod_that_replaces/
I am not sure I follow. You might have reinvented the wheel unnecessarily there.
GOAP adds some implementation and execution complexity that can be hard to get ROI on
well, I didn't in the end, I just ended up declaring some shit that stores information about task types and calling it a day
True, there is some of that at least.
way simpler
My concern was ensuring modders could add new types of task/job easily, since Rimworld makes it a little complex - but Rimworld also polls everything all the time
anyway point is - I tried way too hard to write a generalized system that would do a bunch of magic shit under the hood for no reason and wasted like 2 days on this lmao
when I could have just done the simple solution, which doesn't require that much brainpower for a modder to understand, and moved on
i'll have to look into GOAP more, i'm using an HFSM at present but my game logic isn't super complex, it's really just "meet your needs, do your job" lmao
what kind of game would you say GOAP is most appropriate for?
Might shed some light on it better
https://www.youtube.com/watch?v=T_sBYgP7_2k
Build a GOAP system from the ground up in this video that not only explains GOAP (Goal Oriented Action Planning) but will show you how you can implement smarter AI in your Unity project with a practical implementation from scratch. Create dynamic and unpredictable AI for your project that will leave your Players wondering how in the hell the AI...
Unless you are the type who needs reading material
don't know, depends on the specific design, i think that stuff which is less modular/theoretical works better in most cases
i'll see if the video helps, some videos don't really work for me
i learn best by doing unfortunately so i've always struggled with learning new things lmao
i would expect that a strategy game that is actually about making and solving problems for the opponent would require something like GOAP or some hierarchical action planning
It would be good for NPC scheduling. Like games where you require that NPCs have things to do, but your environment is uncertain or not necessarily static or predictable.
So you let the NPC find out how to handle it
but games with agents that just do work-tasks (a colony sim) would probably not need such a thing and can do well with a combination of HFSM and Behaviour Tree
but ofc. the BT/FSM here would be "solvers", not "descriptors" of tasks
yeah, that's how it works atm
Pretty much everything here is an agent that does certain things
so far i've always made a task-declaration language that is optimized for the specific game design and then just implement a solver with standard BT/FSMs
I suppose the exception here would be combat
but i'm mostly making colony-sim type AIs, not sure how that plays out in FPS/ARPG or strategy
the fun part is that the player in this case can take control of a colonist lmao
which means I do need a much more sophisticated combat system than just..."find cover, shoot"
You can make use of multiple solutions also, if that works better.
Using GOAP for macro planning for example and using more fine tuned behaviour trees and whatnot for certain tasks, like fighting, could still be an option.
exactly, and trying to do planning with a BT will make you question life choices 😄
Behaviour trees for combat will most likely be what I'll have to do anyway if/when I end up implementing shit like cybernetic abilities
I get the sense dewyn is that kind of person 😅
i question my life choices anyway 😔
i fully admit i'm extremely particular about certain shit, like i can let it go if i'm in a work environment but when i'm the only one doing stuff i end up shoehorning myself
my heuristic is : BT for agent stuff that takes time, FSM for agent decisions, ActionPlanner for coordination
can you explain the BT part? curious what led you to that
imo a job-system is also an action planner
inherently a BT node has a 'running' state and expressing logic beyond pass/fail is difficult to model
right, how does that tie into "agent stuff that takes time"?
you need way too many nodes in a BT to express something like a "transition" in a FSM
agent walks to destination, agent on patrol, agent searches for player... these animate/play/enable things over time
the decision to enter such states comes from an FSM, the BT 'executes' them or models what happen while in that state
I think I get what you mean now
as a beginner, would it be a good idea for me to make my own navmesh system for learning? or is it one of those things that everyone imports
Different tools for different things
Depends what your goal is. Is your goal to learn how to make a navmesh?
I've kinda got both lumped together at present
beginner...to unity, or to programming?
if programming, I wouldn't suggest trying to make one yourself
you can get a basic understanding from DIY'ing one but making a performant one will take over your life
no, its to make a game
both to the question
Okay. If it's to make a game? Don't bother.
Make a game, worry about the shortcomings of your tool later.
There's a reason packages like A* are so popular, outside of Unity's navmesh system.
Same reason you should probably avoid trying to make deformable terrain systems from scratch, unless you already know very much what you're doing
also are the navmesh components within unity incompatible with 2d?
i would only make my own navmesh thing if i have a use case thats not supported by A*PPP (existing asset)
and even then i would try to make it a plugin on top of A*PPP's foundation
been trying to get it to work for a bit now and still cant seem to figure out why it's not working
I don't think Unity supports attaching navmeshes to sprites, but you can simulate 2d with an orthographic camera and a Plane mesh and see if that helps :p
I don't know what you're using for your game though (tilemap, etc)
or that
that looks promising actually
there is also Aarons A* Pathfinding project, free version should be enough
but yeah tl;dr if you find yourself with a really generic need like pathfinding, you're better off using an existing tool. you won't really gain anything from implementing it yourself, you'll just lose a lot of time and end up with a worse product lmao
Unity does have an experimental branch of its navigation system which supports runtime mesh generation btw
but probably not 2d lmao
"experimental" as in you have to go install it from the package manager
its good to know whats going on behind the premade solutions especially appreciated when building a not so good system in comparison
right, but they want to make a game
DIY'ing gives you an appreciation for the mountain of work that goes into a production ready, performant solution
A*PP is better than what most AAA games have available
not sure if they wanna spend time learning the fundamentals of a pathfinding system, it's really up to them lol
This article is a bit old but https://theory.stanford.edu/~amitp/GameProgramming/AStarComparison.html
it's not as if the concept of A* has fundamentally changed
alright thanks, i'll learn it if I have spare time or in a few years when I need to for some reason lol
this seems pretty well put together for a GOAP, while i'm at it https://github.com/caesuric/mountain-goap
main benefit is that if something goes wrong or needs fixing you know what to do
for stuff you make yourself?
if so then yeah I agree
working with third party systems can get a little confusing at times lmao
true but if its a good asset and properly documented you can probably fix minor things yourself or even extend from it, but eitherway you probably have support from devs anyway lol
this has a fun api, but its a rats nest of function pointers and might not perform too well.
depends on whether the function pointers are going through Delegate.DynamicInvoke or being converted to Actions
I mean it literally uses Action but I don't know if that's a C# Action
doesnt matter, it jumps around in memory, just by design, so its not "optimizable"
but that might not even matter, depends on scale
Yeah no it's using an internal thing
Actually this looks like a more refined version of something I built a few years ago in Java
but I used that for shit like abilities/cutscenes
looks like a basic implementation, should be fine for ~100-200 agents
tbf, DynamicInvoke does have a lot more overhead iirc
yes, but these things can be fixed, my issue is with the entire execution model and graph structure
oh yeah if your issue is structural then my bad
its basically a linked list, lots of nested lists, zero shits given about data locality
mm nested lists
(which makes the implementation 100x simpler)
just pointing it out, no reason not to use it
my own BT implementation is a mess of pointers and i've had a lot of pain because of that 😄
as a C++ developer, not using pointers makes me anxious
but I rarely see them used in C#
what are you using them for?
well, if you use pointers to effectively create self-rewriting code, you might get anxious for other reasons
pointers to me primarily represent the distinction between "this object is located elsewhere" and "this object is located here"
If you wanna play with pointers in C# you can.
But then you'd really need a use case that warrants it
by "pointer" i mean any kind of jump in heap memory, so in C#, any old reference type
(elsewhere including the heap)
it's mostly a syntax thing
like yes i know how C# refs work lmao
also it sounds cooler to say "pointer" than "reference type"
well you see in C++ those are distinctly different
all these things, at the end of the day, are pointers
typing in C++ is an illusion though
you can wrap them and rename them, but it stays a pointer
just use reinterpret_cast and you can make everyone miserable at no cost
thats the nice thing in C#, it makes it progressively more difficult the dumber the idea you have is
this is true. C# forces you to behave to some extent.
I've tried to learn C++ several times, but every time it gets to the pointers part, all the sources I've checked falls short. They take it as a given that you know when to use what type of pointer after you've been told that you should use them.
But they don't tell you when to use pointers or what kind or how to manage it after it's done being useful. Just that it is useful, that it is good and that you need to learn how to use them.
Which infuriates me to no end.
C++ will let you just reinterpret_cast<byte*>(&literally fucking anything)
you need to come to C++ from C, then its much easier
if you come from C# you just wonder "why the fuck do i need to worry about this"
had to reevaluate how i look at programming
I had formal education in programming. I understand the why.
I don't understand the when because it's never explained.
so do I, but as a dumbass 17 year old I didn't really know what the hell the point was back in freshman year
I wasn't 17 when I learned this
I was
also in C++ it matters a lot who your peers are, your trash is anothers treasure code
I was talking about myself lol
maybe I was 18 actually, either way I was even dumber than I am now
Right but when you bring it up right after responding to me, it comes off as a comparison which doesn't really pertain to what I was talking about.
C++ is one of those things where there are no real standards. Look at production C++ in game dev, then look at Unreal C++.
understandable, my bad
and everyone is ultra-protective of their way
yep
I know C++ is different depending on domain as well. You can do anything with C++.
Again, the point is; When I've tried to learn C++ on my own time, the teaching always stops short of explaining the "when" of pointers.
It explains the what. It explains the how. Not the when.
Main thing with pointers is like
At least on my end I primarily use them when a type needs to point to something that resides elsewhere on the heap
imo time spent on dealing with basic language issues in C++ can be spent on optimizing your C# code and solving design problems --> C# ends up faster and more opulent
depends. C++ code can objectively be extremely fast
but if you don't know C++ to start with, you'll get better results from C#
only if you have infinite dev time
I think that's missing the point of wanting to learn a different language, though.
debatable, where I worked our code was optimized in a way that C# probably would have struggled with - but we also used compute shaders and SIMD very effectively lmao
its just not the productive choice for small team indie dev
100% not useful for indie
best tools for indie dev all use C# honestly
not just unity, monogame is very solid for 2d
c# uses all that stuff and you can even manuall call intrinsics
i'm not sure how C# interfaces with it
generally speaking I don't know the specifics of what overhead C# has by default, though
the only real advantage C++ has is when you don't use any modern features and do some memory tricks, but you can also do most of these in c# (with more work admittedly)
stuff like array bounds checks
People writing unsafe code in C# can get some amazing performance boosts, without having to go full C++.
That is nice.
or array initializers
But yeah, while efficient C# and efficient C++ code are timezones apart, relatively speaking, C# can still be plenty fast for what we need it for.
a problem in low level C# is the total API overkill they make your deal with... everything needs to be some typed thing, you cant just do that simple pointer magic
But it would be nice to know C++ to both further understand how to trick a computer into doing what you want it to, but also in cases where C++ can provide some tools and ways to work that C# could not.
i fully admit i'm biased, i'm a bit concerned about performance in the long run because of my experience with Rimworld and running like shit :p
how to trick a computer into doing what you want it to
write a programming book and call it this, i will buy it
rimworld is not a good example
it is a terrible fucking example, but my game is similar enough to it by virtue of being a colony sim that I'm always paranoid, even when I know for a fact I'm not doing anything in n^3 time
We already tricked a rock into doing math for us, I'm sure others have written "how to deceive the rock"
you can get absrud performance, orders of magnitude beyond what you see in rimworld, if you just deal intelligently with gameobjects
rimworld's issue isn't even gameobject related, comically enough
actually in U, gameobjects used wrong are the reason why the engine is seen as slow
GameObjects are also a legacy object that has tons of overhead to be fair.
well, they historically had issues with GOs, from that their current architecture has grown
So it's not hard to do it wrong with gameobjects
maybe years ago, but their current architecture is uh
yeah, but that overhead doesn't even matter if you use them with that overhead in mind
it ain't much better
It does matter because you can't mitigate that overhead. You can only be mindful of it.
what's the common perf pitfall with gameobjects?
They are heavy
just intrinsically?
Update() and 2K of memory per instance
Is Debug.Drawray bugged or is this something with my code? All I want the Debug.Drawray to do is to start at the hit.point position and then point in the direction of the objects position but unity does not like what I am doing for some reason.
The drawing is what it should look like and the video is what it actually looks like. This is the code https://hastebin.com/share/didapuyoja.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
also they offer no data locality
but all that can be made irrelevant without abandoning them
GOs are fantastic for iteration speed and debugging
Sure. But performance wise they suck.
hol up
well, if you don't put an Update on them, they have zero performance impact after instantiation and if you don't touch them
so you can work with them
As I said, you can be mindful of the overhead and try to work around it, but you can't really change the overhead a gameobject has
It will always be a heavy object
no need to vilify or hate them
I explicitly have a separate Update method for this reason
which isn't Unity Update
I don't see where I am "hating" or "vilifying" gameobjects. It's a fact that GameObjects are heavy and slow, relatively speaking.
You can do lots of tricks to work with that, but the fact about their weight and processing doesn't really change.
are you just trying to get it to draw a uniform-length ray in the direction of the hit point?
This is a bit confusing. The origin of the ray is hit.point, which gets updated just before, but the direction is calculated before the raycast, using whatever was previously saved in the hit variable. Is that intentional?
yeah?
you are repeatedly pointing at their weight and that is perceived as weird when the discussion is already about what that means or doesn't mean in practice
And you seem to think that criticism means "hate" or "villifying".
no, your insistence means that you aren't going with the flow
I don't have to go with any flow that I don't agree with? Who put you in charge?
You're using hit.point, which refers to where the raycast hits the collider you're querying, and Dir, which refers to the previous assignment of hit and the current collider
is that what you intended to do?
I even agreed that you can workaround the shortcomings of GameObjects, but that apparently is also "hate" and "villifying".
I hate all objects equally
They have been the source of many a heartache
if not, literally just raycast prior to computing Dir.
I fixed the direction issue which seems to have fixed the problem but the solid white lines (that are not flickering) are still there even though they should not be
chad object hater
Oh I replied to the wrong person mb
I meant to reply to the person who posted the code snippet, sorry
In general I think you want to put Physics2D.Raycast at the top of this loop
Otherwise any reference to hit will either be null (first frame) or refer to the hit from the previous iteration
the raycast is as far up as it can go without it not being able to access (ignore Distancedepth)
uh, i don't get it
what would be wrong if you just put it at the top of the loop, exactly?
hit = Physics2D.Raycast(Seeker.position, collidersinradius[i].transform.position - Seeker.position);
the call to Vector3.Distance is using hit.point prior to the raycast
i mean I see you aren't using Depth
I'm not using that though so it wouldnt do anything
I also deleted it because I realized thats not going anywhere
wait did you move the raycast above where you declared Dir? i missed that mb
Yes
ah, okay. multitasking right now sorry
so you're still getting those DrawRays flickering in at the wrong position?
or is the issue that they're not right
seems to be the latter, scrolling up
that seems to have fixed the original issue but the solid white lines in the video should not be rendering, the lines that are flickering are the ones that I want to actually see
right, okay
Not sure why Debug.drawray is making flickering and non flickering lines
something seems to be inconsistent between updates
or i'm wrong entirely, which happens often. what does it look like at the moment?
The flickering lines are doing what I want now although I need to reverse them
but the solid lines shouldn't even be rendering
I am still trying to find why my particle are drifting to positive Z velocity when I set them to zero Z velocity in my code...
var velocity = system.velocityOverLifetime;
velocity.enabled = true;
velocity.x = new ParticleSystem.MinMaxCurve(-0.3f, 0.3f);
velocity.y = new ParticleSystem.MinMaxCurve(-0.2f, 0.2f);
velocity.z = new ParticleSystem.MinMaxCurve(0.0f, 0.0f);
var limitVel = system.limitVelocityOverLifetime;
limitVel.enabled = true;
limitVel.separateAxes = true;
limitVel.space = ParticleSystemSimulationSpace.World;
limitVel.limitX = new ParticleSystem.MinMaxCurve(999f); // no limit
limitVel.limitY = new ParticleSystem.MinMaxCurve(999f); // no limit
limitVel.limitZ = new ParticleSystem.MinMaxCurve(0.0f, 0.0f); // Z locked
What should I do I tried everything!!!
is this a Unity bug ???
i assume what you want is for the rays to hit the cover and stop
I want the rays to draw from the hit.point to the middle of the gameobject without flickering
the only problem is the flickering and the solid lines that aren't flickering
seems to me like that's not exactly happening in any case
yeah I just need to reverse them
just a thought, but you're doing hit = Physics2D.Raycast(Seeker.position, Direction, Direction.magnitude); and that's going to hit whatever comes first
yes
wouldn't that mean that if you have cover between Seeker and the targeted collider, the raycast will hit that intermediate cover, but Dir will still point to the center of the targeted collider? which means you'd have a way longer ray than you expected, and from the wrong position
understandable lmao
same boat tbh, but i told myself i'd get item transport working today
Is there anything C# specifically offers that would create a contract that every related class regardless of inheritance has to define? Eg in a perfect world a way to do a virtual function where any override has to call base?
It’s fine if there isn’t just curious
The only way I can think of is use a class constructor instead of a virtual function. An inheriting class constructor has to call the base class constructor, so you have that part covered.
One thing you can do is a base class method, which calls an abstract method at the end of it's call.
Other than that you could do something like:
BaseClass
{
public void MustCallMethod()
{
MethodForOverride();
//other necessary logic
}
protected virtual MethodForOverride(){}
}
Yeah this is what I was thinking
But you cannot make it auto-call. Some class has to call the MustCall method at some point
Mhm yeah, Might help but shame it’s not viable with MonoBehaviour shenanigans
with constructors?
Well, not everything needs to be a component.
Put whatever you need in your base class' Start or Awake call
Make the virtual call be called at the end of your base class Start call
Implement the virtual calls in all derivatives
I’d lose out on required params that constructors offer though, right? I know there’s patterns to work around that but in terms of direct use it’s a little different
Are these components that must be initialized and cannot be made with prefabs or otherwise?
This is to understand your specifications, not to question your approach
Very possible they could be, Asking these more-so to understand my options than to solve a specific practical problem rn.
My specifications are pretty vague as a result because I want to know what I could specify so no stress if you can’t provide a concrete answer
Anything is possible when you have no specifications
Blank canvas
If the requirement is that you must have a constructor like setup but also you must run a base class method which must run a virtual method for all derived derivatives, then there is a way.
Base Class calls initializer method.
At the end of the initializer method, calls Base method that must be called.
At the end of the Base method that must be called, you call the virtual method which then is called on all derivatives.
I think it's a bit roundabout, but that should be possible.
public abstract class BaseClass : MonoBehaviour
{
public abstract void Initialize(object[] parameters); // run BasePostInitialize at the end of this implementation
protected void BasePostInitialize()
{
// Whatever has to run, goes here
Ready();
}
protected virtual void Ready() { }
}
Something like that perhaps
public class MyImplementation : BaseClass
{
public override void Initialize(object[] parameters)
{
// You know what goes here and how to initialize it
BasePostInitialize();
}
protected override void Ready()
{
// Whatever needs to get called after init goes here
}
}
Every derivative knows how to initialize. So the objects that are passed need to be cast and assigned, but I assume that you'd need to know what each type of derivative would need to initialize properly already regardless so. Should work out.
Heard chef. Will think about this 🙏
not sure where to put this. anyone good with camera stuff can you tell me why my camera is bahaving like this. its supposed to look like google earth
show code..
@rigid island
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
no, see the "large code blocks" section
Why does my list appear in such a broken way? I can't quite tell when it happened first
code:
public abstract class ScriptableObjectList<T> : ScriptableObject
where T : ScriptableObject, IIdentifiableScriptableObject
{
[SerializeField] protected List<T> items = new();
}
oops copied wrong code, edited to fix
switching from List<T> to T[] fixed the issue but I'd rather use lists
unity 6.0.41 and 6.0.48 are affected
issue seems to be related to all lists (but not arrays for some reason, of children of this class:
IIdentifiableScriptableObject is just a plain and simple interface
Abstract types are not serializable. Or rather, there can't be an instance of an abstract type, so perhaps that's the cause?
you might have missed my edit - the scriptable objects that are already added to this list, are of types that derive from this abstract class
so not abstract classes
I don't see any edits
I specified lists of children of this class, rather than lists of this class
doesn't matter
Oh, you mean extending classes
yes
Could be an issue with a list of generics and how they're serialized.
If arrays work and lists don't, then it's probably worth reporting as a bug
even just a list of PuzzleStyleConfig where
[Serializable]
[CreateAssetMenu(menuName = "Puzzles/Puzzle Style Config")]
public class PuzzleStyleConfig : IdentifiableScriptableObject
{
// stuff
}
is affected by this bug
This is likely just a bug in the reorderable list property drawer.
Does it fix it if you put [NonReorderable] on the list field?
Or maybe not... Arrays use the same reorderable property drawer.
the drawer definitely got applied since I can no longer reorder the elements, but no - the issue persists
I think the issue is with the generic class that contains the list
adding an empty element (actually empty, double-checked in the .asset file) to the list still results in a broken element displayed