#archived-code-general

1 messages · Page 446 of 1

naive swallow
#

You can bind values to "Shake" on a Joy-Con, which is a binary value whether it has received a "Shake"

old elk
#

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

night harness
#

Does Unity define motion control inputs as a press? Because at least in human speak imo they are input but not a press

naive swallow
#

This is separate from the "pointer" or "motion" inputs, which are multi-dimensional vectors

old elk
cold parrot
#

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

naive swallow
#

That's the issue with making convenience functions - you can't cover every case. At some point, you have to stop

old elk
#

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

last island
naive swallow
#

sometimes, we'd wish they'd have gone a smidge further before stopping

#

but it has to stop somewhere

old elk
cold parrot
old elk
#

I inevitably run into a use case where I wish just a tiny bit more info was available/etc.

night harness
#

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(?)

last island
#

That is what I'm pointing out here

old elk
cold parrot
#

you arent pointing out anthing that isnt obvious and was already considered

last island
#

The statement is a flawed one because it implies that by having convenience calls at all you might be "polluting" someones game with bloat.

old elk
#

it is objectively difficult to gauge the full extent of every possible use case

naive swallow
cold parrot
#

you ar ejust dragging this discussion into the dirt with these pointless extremes

last island
#

Not at all

old elk
#

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

night harness
#

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?

old elk
#

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)

last island
#

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.

old elk
#

yeah see

steady bobcat
old elk
#

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

naive swallow
# last island An anyButtonPressed convenience method is not at all an extreme. Nor is it unrea...

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"

old elk
#

most reasonable response tbh

#

as someone who routinely writes code that is extensible to the point of creating jank, i understand that lmao

night harness
old elk
naive swallow
#

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

naive swallow
old elk
#

unfortunately, star stickers are relegated to first graders' desks (ask me how I know)

naive swallow
old elk
#

LMAO

last island
naive swallow
vestal arch
old elk
#

lemme scroll up a ways

last island
#

Either way, I tried the solution that was suggested and it doesn't seem to work.

naive swallow
vestal arch
#

anyButtonPressed kinda already has an ambiguous meaning
does it mean only stuff bound to button-type inputs? or actual hardware button presses?

naive swallow
#

So, simply existing as a binding isn't enough of a decider

old elk
#

i think he just wants button type inputs

vestal arch
#

if the former, then it's not really "any button", is it

old elk
#

like literally any discrete input lmao

last island
vestal arch
#

it's just, any of my buttons, so it's again, misleading

last island
#

I don't understand why that is such an alien concept.

old elk
#

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

naive swallow
#

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

vestal arch
#

what about keyboards with analog keys

last island
vestal arch
#

cgp grey

old elk
naive swallow
#

Just, y'know, *gestures vaguely at everything* experience

old elk
#

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)

vestal arch
last island
#

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 🤷‍♀️

old elk
#

also depends on how far into a project you are

vestal arch
#

that's why it's a rule, not a law

#

oh wait i might be misremembering

old elk
#

yeah if you're abstracting the issue enough to where we hit "programming patterns" territory lmao

last island
#

What do you mean abstract it enough??

old elk
#

Unfortunately in any "mature" software environment all of that has gone out the window

#

at least IME

last island
#

Like I don't know what abstract you work in, but there are programming patterns that are not these nebulous thought clouds

vestal arch
#

that's... what patterns are though..

#

they aren't concrete, they can be adapted to each specific scenario

naive swallow
#

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

old elk
#

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

last island
#

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.

naive swallow
#

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

last island
#

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.

vestal arch
#

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

old elk
#

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

old elk
#

e.g. "is any button from this map currently pressed"

vestal arch
#

but then you lose the "press any button to continue" aspect

old elk
#

you could just have a map with that one binding for any button

last island
# old elk ah. there's the rub, and that's what i'm getting at - generally in software, pas...

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.

old elk
#

like across the board

#

company agnostic

vestal arch
old elk
#

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

last island
#

This also happens in gamedev.

old elk
#

can't relate

last island
#

While gamedev happens different to traditional software, games are still software.

#

Games do not sidestep good code.

old elk
#

yes they do.

vestal arch
#

code as a whole sidesteps good code

last island
#

No. Rushed programmers sidestep good code.

old elk
#

The engine code is efficient. That's what it is. It runs well.

naive swallow
#

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

old elk
#

But holy fuck we do not know what half of it does, nor who wrote it or why

naive swallow
#

But the "best" way is not always the best way

chrome sage
#

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?

chrome sage
#

yes'

old elk
#

ah, shit. i don't know much about 2d in unity, apologies

#

all my 2d stuff has been lwjgl or monogame

chrome sage
#

no one does here so no prob

naive swallow
old elk
#

yeah there is a 2d tools channel in artist tools, if you aren't strictly after a scripting solution

old elk
#

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

naive swallow
#

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

last island
#

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

naive swallow
#

🌈 Capitalism! 👐

old elk
#

that and yanderedev

last island
#

the latter seemed to be self-taught so I can kind of excuse them producing bad code

old elk
last island
#

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.

old elk
#

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

night harness
#

Terraria still has it ye

old elk
#

minecraft originally handled first person animation by just using immediate mode OpenGL in the main game loop

last island
#

If it works :U

old elk
#

p much

#

ironically "bad" code is easier to mod

night harness
#

Balartro isn’t to horrible tbh, at least in the examples that we’re floating around

naive swallow
#

Step 1: Make it run
Step 2: Make it right
Step 3: Make it fast

And always that order

old elk
night harness
last island
old elk
#

kenshi wants to know your location

#

(tbf, Kenshi did do something really cool, which is pathfinding through unloaded regions of the world)

night harness
#

One that surprised me a bit is that Lethal Company commits a fairly small amount of sins given the development context

old elk
#

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."

last island
night harness
#

a majority of the game was made without events or properties so don’t go too far lol 😛

last island
#

Which one?

old elk
#

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)

naive swallow
night harness
#

c# and the general concept

last island
#

What's wrong with the C# event system?

old elk
old elk
#

nothing wrong with it from a technical standpoint, using it just makes my brain itch

last island
#

Right, but I wanted to know why you didn't like it

naive swallow
#

I get annoyed at the += and -= syntax for registering listeners mostly

last island
#

Is it a syntax thing or?

naive swallow
#

It just feels so unintuitive

old elk
#

it's hard to explain. i am probably a little bit on the spectrum lmfao

#

could also be the adhd though

last island
#

In that sense I think it would make sense to use that

old elk
#

it's a bit more complex than that unfortunately

#

there's some weird shit with MulticastDelegate

naive swallow
#

Right, I get why it was chosen, but syntactically it just doesn't seem right

#

You don't += to add things to a list

old elk
#

Which functionally ends up as a bunch of pointers

naive swallow
#

So why += to add things to a list of pointers specifically?

last island
old elk
#

I mean you could probably write an extension method for that one lmao

steady bobcat
#

Its because you can assign or add to delegate types normally but event changes functionality such as preventing assignment outside the class

old elk
#

Also for my own game I didn't like how the event/delegate system felt like it was discarding types

naive swallow
steady bobcat
#

I love events I use them a lot 😄

naive swallow
#

Me too

#

Arguably too much

last island
#

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.

old elk
#

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 💀

naive swallow
last island
#

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.

night harness
#

I don’t like having to nullcheck empty ones either but that’s just dumb brain wise

old elk
#

i have a love hate relationship with that one

#

i stopped talking to java developers because every question was answered with "use this package"

last island
#

People do that with JavaScript and Python too.

old elk
#

Fortunately, I have never had to use JavaScript, beyond one uni course, where I wanted to die

steady bobcat
#

python devs be like "checkout my cool one liner!" but dont realise it just wraps some C lib 😆

last island
#

If it gets the job done within spec

old elk
#

i use the typing library explicitly to make them sad

last island
#

🤷‍♀️

old elk
#

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

steady bobcat
#

so in java its just magically done for you?

old elk
#

how I ended up writing it is pretty much identical to how Spigot handles it for minecraft servers

#

nah

last island
#

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 ~

old elk
last island
#

Because it is 👀

#

Anything can Broadcast, anything can listen.
It's the Mediator pattern.

#

Fancy that

old elk
#

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

last island
#

Sure, if you require prioritzation of sorts, then my approach would be far insufficient

steady bobcat
#

well there is no such concept unless you program your own thing

night harness
old elk
#

hence the [EventHandler] annotation lmao

#

sorry "attribute"

#

annotation is the Java/C++ term

last island
night harness
old elk
#

i'll have to take a look at that one

last island
#

What does it wrap, I suppose

steady bobcat
#

UnityEvent does this already btw

last island
#

UnityEvent is slow

#

Much slower than C# events

steady bobcat
#

well the inspector made ones are yes as they are implemented with reflection

last island
#

They are useful for the few times where you need them, like UI events and other event invocation lists on components

steady bobcat
#

but code subscriptions should be almost the same as normal

old elk
#

you can actually use reflection to implement things "quickly" but it's a huge pain

#

ask me how i know

chilly surge
last island
#

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.

night harness
# last island What does it do?

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

old elk
#

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

last island
#
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.

chilly surge
#

IIRC multicast delegate also allocates more than if you manage your own List<Action>.

last island
night harness
old elk
#

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

night harness
old elk
last island
uncut tundra
#

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

night harness
#

I’ve yet to find industry work so i am the spec fortunately

old elk
#

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

last island
# night harness I’ve yet to find industry work so i am the spec fortunately

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

GitHub

This repository serves as an example of how to implement some of the most common software development patterns but in a games context. - mads-fs/csharp-patterns

steady bobcat
night harness
last island
#

It's not complete, but it has some of the more useful ones I'd say

old elk
old elk
#

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

last island
#

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.

old elk
#

yeah, that's what i'm planning. i guess when i say "prototype" i mean "early access" lmao

night harness
# last island It's not complete, but it has some of the more useful ones I'd say

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 🙂

last island
night harness
last island
#

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.

old elk
#

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

last island
#

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.

night harness
#

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

last island
#

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.

old elk
#

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

last island
#

I don't need to care about any other complexity

old elk
#

it's much nicer

wheat shoal
#

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);
            }
        }
    }
}```
old elk
#
  1. would suggest naming your raycasthit hit instead of ray, for clarity, but that's a nitpick - a Ray is an existing type
  2. put your debug draws outside the hit check so you can see what ray is actually being cast, regardless of hit
  3. from what I'm seeing, if hasLineOfSight is true , it will remaintrue if the raycast hits nothing, because it only updates the value of hasLineOfSight on 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
last island
night harness
#

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

last island
old elk
#

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

night harness
#

That is close to what im using yeah

old elk
#

I use that for singletons since i've got a few of those lying around

last island
#

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.

steady bobcat
wheat shoal
old elk
#

then you can see if you're just raycasting in the wrong direction, etc.

wheat shoal
old elk
#

you did in fact give the raycast a direction

#

player.transform.position - transform.position

wheat shoal
#

realised that the server blocked questernmarks huh

wheat shoal
old elk
#

which...looks correct, off the top of my head

wheat shoal
#

I just riped this code from a video and it worked on his end also his video is juts a year old

old elk
#

e.g. if your player is at (1, 0) and your enemy is at (0, 0) it should raycast in the direction (1, 0)

night harness
# last island Well, MonoBehaviour already is that

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

old elk
#

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

wheat shoal
old elk
#

again, try invoking your Debug.DrawRay calls regardless of whether or not the ray hits

last island
# night harness Forsure I’m just building a similar system for my own tailor made content setups...

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.

steady bobcat
#

To get a direction to a position it should be target - me

old elk
#

player - self

#

(this is for an enemy)

steady bobcat
#

you are right carry on 😆

old elk
#

(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)

wheat shoal
#

i putDebug.DrawRay(transform.position, player.transform.position - transform.position, Color.green); in my FixedUpdate, nothing

steady bobcat
#

should be in OnDrawGizmos()

old elk
#

do you have "Gizmos" checked in your play window?

#

Nah Debug.DrawRay always works

last island
#

FixedUpdate is only really used with physics stuff

steady bobcat
#

oh really huh

last island
#

But it should still draw

old elk
#

It'll be on the far right here, at the top of the play window

last island
#

It's only when you do Gizmos that it has to be in the Gizmos call far as I remember

old elk
last island
#

I don't follow the logic there

wheat shoal
last island
#

Wouldn't you just put it in a LateUpdate then?

old elk
#

did they change LateUpdate?

#

hang on now i have to double check something

last island
#

LateUpdate happens after Update...?

#

What should they have changed?

old elk
#

wait, I don't get why I'd use LateUpdate here then

wheat shoal
#

the draw ray works but its only on red

old elk
wheat shoal
old elk
#

to be clear the player is also controlling the speed of any physics simulations lmao

last island
#

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?

old elk
wheat shoal
old elk
#

are you using visual studio?

wheat shoal
#

yeah

old elk
#

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

wheat shoal
#

at RaycastHit2D ray = Physics2D.Raycast(transform.position, player.transform.position - transform.position); ?

old elk
old elk
last island
old elk
last island
wheat shoal
#

i put it here ok

old elk
#

yeah i don't know either if i'm honest

old elk
#

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

old elk
last island
#

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

old elk
#

right. and i don't have any update calls on those

last island
#

FixedUpdate is no different in that sense. The timestep is just fixed.

old elk
#

monobehaviours in my game are basically just ways of binding something like an Entity to a gameobject

wheat shoal
#

is this normal??

old elk
last island
old elk
#

what I wanted to do was write my own game code and basically just interface with Unity as little as possible lmao

last island
#

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.

wheat shoal
old elk
#

ah. I mean I'm using gameobjects to actually hold and render the meshes/etc.

old elk
old elk
last island
#

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.

old elk
#

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

last island
#

ECS is just the paradigm. Agnostic. Not tied to anything.

#

Unity ECS is their specific implementation of that paradigm.

old elk
#

is this an upcoming thing?

last island
#

GameObjects are partially ECS but there is no distinction between E and C so it's more EC-S.

old elk
#

or like a beta or whatever

last island
#

No you can use it right now.

old elk
#

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

last island
#

It requires that you change your way of thinking, but you do become a better programmer from doing it ultimately anyway.

old elk
#

A big part of my problem is that I'm going to want to fence off game entity updates

last island
#

Unity's own learning resources on this are quite nice, I found.

wheat shoal
#

sorry about having to keep distrubring ur convo but idk what i do next for this

old elk
#

nah it's fine

last island
#

Oh don't worry. Your issue comes first @wheat shoal
Please interrupt.

old elk
#

when you go back to visual studio, you should see your breakpoint with an arrow on it

#

try mousing over ray

old elk
last island
old elk
#

well, we didn't use an ECS lmao

#

but we did store everything in subscenes and "bake" them

wheat shoal
old elk
#

except that "baking" process took a long fucking time and honestly everything sucked.

#

good idea in principle though

old elk
wheat shoal
old elk
#

ah. so what's happening is that it's hitting the rifle.

merry stream
#

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

old elk
#

you can see under the collider field it's hitting the rifle first

wheat shoal
old elk
#

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

wheat shoal
old elk
old elk
#

that's the problem lol

last island
old elk
#

that's why it's not picking up the player

old elk
last island
#

"An"... 🤔

wheat shoal
merry stream
#

it contains duplicates as well

old elk
#

is there no such thing as an implementation of ECS?

#

cause uh

i've seen a number

last island
#

There are implementations of ECS, yes.
But "an ECS" is not a thing. Confusing.

old elk
#

i think colloquially "an ECS" would translate to "an implementation of ECS"

last island
#

Not at all. Never heard anyone call it "an ECS" before.

old elk
#

well, now you have :p

night harness
# last island Hmm, I think you might be working against the engine a bit there, unless I misun...

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

old elk
merry stream
wheat shoal
#

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

last island
old elk
#

i mean are you getting those positions with something like Random or

#

yes this matters lol

merry stream
#

yes if you look at the code i sent i use Unity Random.Range

#

to index

old elk
#

ah mb, I missed that

#

let me check something

#

I don't think Random.Range uses any kind of normal distribution

night harness
merry stream
#

wdym i just want a random position haha

old elk
#

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

last island
merry stream
#

ok so how would I fix it?

#

is that the cause of the problems tho? i doubt that would improve performance anyway

old elk
#

this kinda illustrates what i'm trying to say

night harness
merry stream
#

ah makes sense

old elk
last island
old elk
#

You can use something like Halton or Hammersley sampling for a uniform distribution in 2d, but anyway

rigid island
merry stream
#

if a position is valid

steady bobcat
old elk
last island
#

Getting the squareroot is slow 🤷‍♀️
But is it too slow? Eh. Depends.

old elk
#

i'd rather just use uniform sampling and cache it, but i digress

steady bobcat
#

Yea other ways to overcome if it was an issue

last island
old elk
merry stream
#

i could use poisson disc sampling

merry stream
last island
#

I've used Poisson Disc Sampling before. Was pretty easy with a video from Sebastian Lauge.

merry stream
#

over the whole structure

old elk
#

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

last island
merry stream
#

yes

last island
#

Should be easy enough to check a bunch of bools

old elk
#

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

last island
#

It is a lot to go through because GameObjects

merry stream
#

i dont use gameobjects to check

#

the tiles are stored in a dictionary with position and flags

old elk
#

gameobject my behated

last island
#

How do you retrieve positions?

merry stream
#

everything is done using vector2int until the end where i place it all on the tilemap

#

the tiles are stored in a dictionary

old elk
#

depending on your game you may want to try using a 1d array

night harness
old elk
#

i did find this one interesting https://www.youtube.com/watch?v=gsJHzBTPG0Y

last island
merry stream
#

nope would that help a lot?

old elk
#

I would unironically just consider using a 2d array instead of a new vector2int every check

last island
#

The job system is incredibly powerful if you can use it right

old elk
#

I don't actually know the overhead of doing that

merry stream
#

2d array instead of what

night harness
#

Knowing those 37 failed attempts is fascinating!!

Acerola and ThinMatrix are channels I keep up with too

last island
#

Acerola is a rare wiz. He knows the fundamentals and can extrapolate solutions from knowing those basics.

old elk
#

you've got a dictionary of vector2int instead of just Tile[][] or Tile[] (where the index is y * tileWidth + x)

old elk
#

before settling on

manually declaring job types

last island
#

A dictionary should still have fast enough lookup.

old elk
#

it should but i'm not a fan of that new Vector2Int in n^2

last island
#

It's adding to a dictionary that's slow, not the look up. The lookup is hashed.

old elk
#

Granted I don't know how C# handles new structs

old elk
#

coming from C++ I'm always suspicious though lmao

merry stream
#

i see

old elk
#

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

merry stream
#

ok makes sense

old elk
#

like I don't think the dictionary is necessarily the issue here

last island
merry stream
#

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

old elk
#

Nah the dictionary is fine, in principle

last island
#

But you said that you located where the actual issue is right?

#

Can you show me?

old elk
#

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

merry stream
#

let me see how, i have just been putting timers before and after functions lol

last island
#

You don't wanna use the VS profiler

#

Just use Unity's

old elk
#

does the VS profiler have a stroke if you try to use it with unity lmao

last island
#

I don't think so, but why would you use it?

old elk
#

vs profiler lets you go pretty in depth

last island
#

Right, but so does Unity's?

#

It sounds like injecting a middleman

old elk
#

does unity's let you see stuff like new allocations?

last island
#

Have you never used it?

old elk
#

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

last island
#

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

old elk
#

oh nvm I see you can view allocations here too

#

that's nice

last island
steady bobcat
#

Remember guys if you use new more than 0 times a frame you are a bad dev /s

steady bobcat
last island
steady bobcat
#

I understand memory management decently enough and I usually manage just fine with the unity profiler

last island
#

Then your comment confuses me

steady bobcat
#

I am interested in utilizing the VS profiling tools with unity also as i presumed they would not function

last island
#

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.

old elk
#

MS profiler would let you view the callstacks but you'd have to parse them out yourself i'm sure

last island
#

VS can show you the callstack of calls you debug

old elk
#

have you used the VS profiler recently? it's quite in depth

last island
#

To a point anyway

old elk
#

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

last island
#

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.

old elk
#

"what's with this script overhead" -> hdrp scripts

#

i used a lot of vs profiling at my last job :') and renderdoc lmao

last island
old elk
#

completely unrelated but configuring animations solely through script is rough

last island
#

That is one area that Unity needs to really up their game. Animation. It's currently one of the worst systems to work with.

old elk
#

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

last island
#

Thank god for stuff like Animancer

old elk
#

for many reasons

#

that sounds familiar, I think I've used it before

last island
old elk
#

i usually roll all my own solutions lmao

#

ah, I did use this before

wheat shoal
#

I got my code working :)

old elk
#

nice, congrats

last island
#

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.

wheat shoal
#

@old elk thank you for the advice

old elk
#

🫡

merry stream
old elk
#

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

last island
#

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.

old elk
#

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

last island
#

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

old elk
#

yikes

#

Doesn't help that my animations are dependent on both task and movement lmao

#

e.g. "play hammering animation if doing construction task"

cold parrot
#

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

last island
#

Yeah that's the issue I have with it really. It feels incredibly outdated to work with, imo.

#

It could use some love

cold parrot
#

animancer is also built with the playables API, you can always use that directly

last island
#

True. Playables are nicer at least. But I do prefer the abstraction that Animancer provides, personally.

cold parrot
#

i think almost nobody is aware that thing even exists

old elk
#

promotional issue

cold parrot
#

yes, animancer is very nice

last island
#

I have found that surprisingly few use it even though they have problems that the Playable system could solve for them

old elk
#

i'll probably just end up using animancer honestly

cold parrot
#

playables is quite annoying to use directly

old elk
#

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

last island
#

I used it to make cut scenes for a game jam once.

#

Was quite cool

old elk
#

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

last island
#

I like Cinemachine is principle, I don't like the execution. Feels way overengineered even for simple setups that are widely used.

cold parrot
#

problem with animancer is that you can end up with very ugly/complicated code unless you have a great appreciation for formal state machines

last island
#

But at least when you do, man can you efficiently reuse it

cold parrot
#

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

old elk
#

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

cold parrot
#

it being standard allows integrations to be developed, like timeline/sequences

last island
#

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.

old elk
#

good to know i was onto something lmao

cold parrot
old elk
#

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

cold parrot
#

also the idea that your AI code should be a 'solver' for action problems makes things much simpler

night harness
#

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

last island
#

That is one of the biggest turnoffs

old elk
#

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.

last island
#

I really dislike the Unity Animator

old elk
#

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

night harness
# old elk Modding through the editor is a god damn nightmare

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

old elk
night harness
#

😅

old elk
#

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

spare dome
old elk
#

downside is that debugging my own shit requires custom UI 😎

night harness
#

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

spare dome
#

iirc the unity 7 animator should be better

old elk
#

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

last island
old elk
#

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

night harness
last island
#

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.

old elk
old elk
#

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)

last island
#

You using GOAP or something?

old elk
#

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

last island
#

GOAP is fairly simple in principle.

old elk
#

basically just

"build this blueprint"
"haul this item here"
etc.

last island
#

You have a goal, the AI needs to figure out how to reach that goal given it's available actions.

old elk
#

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

cold parrot
#

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

night harness
# old elk yeah I mean I think some stuff like the skinwalker mod fit the base game concep...

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/

Reddit

Explore this post and more from the lethalcompany community

last island
cold parrot
#

GOAP adds some implementation and execution complexity that can be hard to get ROI on

old elk
last island
#

True, there is some of that at least.

old elk
#

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

old elk
#

what kind of game would you say GOAP is most appropriate for?

last island
#

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...

▶ Play video
#

Unless you are the type who needs reading material

cold parrot
old elk
#

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

cold parrot
#

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

last island
#

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

cold parrot
#

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

old elk
#

Pretty much everything here is an agent that does certain things

cold parrot
#

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

old elk
#

I suppose the exception here would be combat

cold parrot
#

but i'm mostly making colony-sim type AIs, not sure how that plays out in FPS/ARPG or strategy

old elk
#

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"

last island
#

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.

old elk
#

that's probably what I'll settle on, yeah

#

good call

cold parrot
old elk
#

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

last island
old elk
#

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

cold parrot
#

my heuristic is : BT for agent stuff that takes time, FSM for agent decisions, ActionPlanner for coordination

old elk
#

can you explain the BT part? curious what led you to that

cold parrot
#

imo a job-system is also an action planner

cold parrot
old elk
cold parrot
#

you need way too many nodes in a BT to express something like a "transition" in a FSM

cold parrot
#

the decision to enter such states comes from an FSM, the BT 'executes' them or models what happen while in that state

old elk
#

I think I get what you mean now

dim cairn
#

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

last island
#

Different tools for different things

last island
old elk
#

I've kinda got both lumped together at present

old elk
#

if programming, I wouldn't suggest trying to make one yourself

cold parrot
dim cairn
last island
old elk
#

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

dim cairn
#

also are the navmesh components within unity incompatible with 2d?

cold parrot
#

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

dim cairn
#

been trying to get it to work for a bit now and still cant seem to figure out why it's not working

old elk
#

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

rigid island
old elk
#

I don't know what you're using for your game though (tilemap, etc)

#

or that

#

that looks promising actually

rigid island
cold parrot
#

A*PP does 2D pathfinding in the free version

#

just no runtime mesh generation

old elk
#

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

rigid island
#

its good to know whats going on behind the premade solutions especially appreciated when building a not so good system in comparison

old elk
#

right, but they want to make a game

cold parrot
#

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

old elk
#

not sure if they wanna spend time learning the fundamentals of a pathfinding system, it's really up to them lol

#

it's not as if the concept of A* has fundamentally changed

dim cairn
#

alright thanks, i'll learn it if I have spare time or in a few years when I need to for some reason lol

old elk
rigid island
#

main benefit is that if something goes wrong or needs fixing you know what to do

old elk
#

if so then yeah I agree

#

working with third party systems can get a little confusing at times lmao

rigid island
#

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

cold parrot
old elk
#

I mean it literally uses Action but I don't know if that's a C# Action

cold parrot
#

doesnt matter, it jumps around in memory, just by design, so its not "optimizable"

#

but that might not even matter, depends on scale

old elk
#

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

cold parrot
#

looks like a basic implementation, should be fine for ~100-200 agents

old elk
cold parrot
#

yes, but these things can be fixed, my issue is with the entire execution model and graph structure

old elk
#

oh yeah if your issue is structural then my bad

cold parrot
#

its basically a linked list, lots of nested lists, zero shits given about data locality

old elk
#

mm nested lists

cold parrot
#

(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 😄

old elk
#

as a C++ developer, not using pointers makes me anxious

#

but I rarely see them used in C#

#

what are you using them for?

cold parrot
#

well, if you use pointers to effectively create self-rewriting code, you might get anxious for other reasons

old elk
#

pointers to me primarily represent the distinction between "this object is located elsewhere" and "this object is located here"

last island
#

If you wanna play with pointers in C# you can.
But then you'd really need a use case that warrants it

cold parrot
old elk
#

(elsewhere including the heap)

#

it's mostly a syntax thing

#

like yes i know how C# refs work lmao

cold parrot
#

also it sounds cooler to say "pointer" than "reference type"

old elk
#

well you see in C++ those are distinctly different

cold parrot
#

all these things, at the end of the day, are pointers

old elk
#

typing in C++ is an illusion though

cold parrot
#

you can wrap them and rename them, but it stays a pointer

old elk
#

just use reinterpret_cast and you can make everyone miserable at no cost

cold parrot
#

thats the nice thing in C#, it makes it progressively more difficult the dumber the idea you have is

old elk
#

this is true. C# forces you to behave to some extent.

last island
#

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.

old elk
#

C++ will let you just reinterpret_cast<byte*>(&literally fucking anything)

cold parrot
#

you need to come to C++ from C, then its much easier

old elk
#

i came to C++ from Java

#

threw me off pretty hard lol

cold parrot
#

if you come from C# you just wonder "why the fuck do i need to worry about this"

old elk
#

had to reevaluate how i look at programming

last island
#

I had formal education in programming. I understand the why.

#

I don't understand the when because it's never explained.

old elk
#

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

last island
#

I wasn't 17 when I learned this

old elk
#

I was

cold parrot
#

also in C++ it matters a lot who your peers are, your trash is anothers treasure code

old elk
#

I was talking about myself lol

#

maybe I was 18 actually, either way I was even dumber than I am now

last island
#

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.

old elk
#

C++ is one of those things where there are no real standards. Look at production C++ in game dev, then look at Unreal C++.

cold parrot
old elk
#

yep

last island
#

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.

old elk
#

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

cold parrot
#

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

old elk
#

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#

cold parrot
last island
cold parrot
#

i'm not saying you shouldn't learn it

#

it has its uses

old elk
cold parrot
#

its just not the productive choice for small team indie dev

old elk
#

100% not useful for indie

#

best tools for indie dev all use C# honestly

#

not just unity, monogame is very solid for 2d

cold parrot
old elk
#

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

cold parrot
#

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)

cold parrot
last island
#

People writing unsafe code in C# can get some amazing performance boosts, without having to go full C++.
That is nice.

cold parrot
#

or array initializers

old elk
#

that is true. unsafe code is fun

#

i use unsafe code lmfao

#

it's a nice middle ground

last island
#

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.

cold parrot
#

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

last island
#

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.

old elk
#

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

cold parrot
old elk
#

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

last island
#

We already tricked a rock into doing math for us, I'm sure others have written "how to deceive the rock"

cold parrot
#

you can get absrud performance, orders of magnitude beyond what you see in rimworld, if you just deal intelligently with gameobjects

old elk
#

rimworld's issue isn't even gameobject related, comically enough

cold parrot
#

actually in U, gameobjects used wrong are the reason why the engine is seen as slow

last island
#

GameObjects are also a legacy object that has tons of overhead to be fair.

cold parrot
last island
#

So it's not hard to do it wrong with gameobjects

old elk
#

maybe years ago, but their current architecture is uh

cold parrot
old elk
#

it ain't much better

last island
old elk
#

what's the common perf pitfall with gameobjects?

last island
#

They are heavy

old elk
#

just intrinsically?

cold parrot
spare dome
#

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

cold parrot
#

also they offer no data locality

#

but all that can be made irrelevant without abandoning them

#

GOs are fantastic for iteration speed and debugging

last island
#

Sure. But performance wise they suck.

cold parrot
#

so you can work with them

last island
#

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

cold parrot
#

no need to vilify or hate them

old elk
#

which isn't Unity Update

last island
#

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.

old elk
late lion
old elk
#

yeah?

cold parrot
last island
cold parrot
last island
#

I don't have to go with any flow that I don't agree with? Who put you in charge?

old elk
#

is that what you intended to do?

last island
#

I even agreed that you can workaround the shortcomings of GameObjects, but that apparently is also "hate" and "villifying".

sonic sandal
#

I hate all objects equally

last island
old elk
#

if not, literally just raycast prior to computing Dir.

spare dome
#

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

old elk
#

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

spare dome
#

the raycast is as far up as it can go without it not being able to access Distance (ignore depth)

old elk
#

uh, i don't get it

#

what would be wrong if you just put it at the top of the loop, exactly?

spare dome
#

above Distance?

#

direction

#

mb

#

Direction

old elk
#

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

spare dome
#

I'm not using that though so it wouldnt do anything

#

I also deleted it because I realized thats not going anywhere

old elk
#

wait did you move the raycast above where you declared Dir? i missed that mb

spare dome
#

Yes

old elk
#

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

spare dome
#

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

old elk
#

right, okay

spare dome
#

Not sure why Debug.drawray is making flickering and non flickering lines

old elk
#

something seems to be inconsistent between updates

#

or i'm wrong entirely, which happens often. what does it look like at the moment?

spare dome
#

The flickering lines are doing what I want now although I need to reverse them

#

but the solid lines shouldn't even be rendering

zinc flax
#

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 ???

old elk
# spare dome

i assume what you want is for the rays to hit the cover and stop

spare dome
#

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

old elk
#

seems to me like that's not exactly happening in any case

spare dome
#

yeah I just need to reverse them

old elk
#

just a thought, but you're doing hit = Physics2D.Raycast(Seeker.position, Direction, Direction.magnitude); and that's going to hit whatever comes first

spare dome
#

yes

old elk
#

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

spare dome
#

probably

#

I would have to fix that but not today

#

my brain is fried

old elk
#

understandable lmao

#

same boat tbh, but i told myself i'd get item transport working today

night harness
#

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

cosmic rain
last island
cosmic rain
#

Other than that you could do something like:

BaseClass
{
  public void MustCallMethod()
  {
    MethodForOverride();
    //other necessary logic
  }
  protected virtual MethodForOverride(){}
}
last island
#

But you cannot make it auto-call. Some class has to call the MustCall method at some point

night harness
last island
#

What do you mean?

#

MonoBehaviour gives you a mechanism that makes it quite viable

night harness
#

with constructors?

cosmic rain
last island
#

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

night harness
#

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

last island
#

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

night harness
#

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

last island
#

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.

night harness
#

Heard chef. Will think about this 🙏

hushed field
#

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

hushed field
#

@rigid island

vestal arch
#

!code

tawny elkBOT
hushed field
#

sorry

#

did i do it right

vestal arch
#

no, see the "large code blocks" section

wintry crescent
#

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();
    }
wintry crescent
wintry crescent
#

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

cosmic rain
wintry crescent
#

so not abstract classes

cosmic rain
#

I don't see any edits

wintry crescent
#

I specified lists of children of this class, rather than lists of this class

#

doesn't matter

cosmic rain
#

Oh, you mean extending classes

wintry crescent
#

yes

cosmic rain
#

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

wintry crescent
#

even just a list of PuzzleStyleConfig where

[Serializable]
    [CreateAssetMenu(menuName = "Puzzles/Puzzle Style Config")]
    public class PuzzleStyleConfig : IdentifiableScriptableObject
    {
        // stuff
    }

is affected by this bug

late lion
#

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.

wintry crescent
#

the drawer definitely got applied since I can no longer reorder the elements, but no - the issue persists

cosmic rain
#

I think the issue is with the generic class that contains the list

wintry crescent
#

adding an empty element (actually empty, double-checked in the .asset file) to the list still results in a broken element displayed