#archived-code-general

1 messages · Page 201 of 1

heady iris
#

transform.TransformDirection(Vector3.forward) is equivalent to transform.forward

silk edge
#

Oh so rather than Vector3.foward, I use transform.forward?

heady iris
#

transform.forward tells you which direction is "forward" for that transform

silk edge
#

Yep that did it! Thanks

heady iris
#

and transform.InverseTransformDirection(transform.forward) is equivalent to Vector3.forward (:

hard viper
#

Apparently some people use [serializefield, HideInInspector] private component, then use GetComponent in OnValidate

#

i don’t understand. what’s the problem with that

heady iris
#

I've never liked doing stuff in OnValidate

#

I know I've had issues with objects not actually existing during it

#

(that's very vague)

rigid island
waxen burrow
heady iris
#

well, you wouldn't use it if the component wasn't in a known location :p

hard viper
#

this is mostly for GetComponent calls in Awake

heady iris
#

It lets you automatically set stuff up before the game runs

#

although it also means that your'e doing a lot of work every time OnValidate gets called for any reason

rigid island
#

which is everytime you save/change something in inspector iirc

hard viper
#

I currently call GetComponent on every collision callback

rigid island
#

just seems like an over-convoluted thing to solve something that isn't broken

hard viper
#

maybe I’ll make a big dictionary to speed that method up

rigid island
late lion
waxen burrow
hard viper
#

yeah. I’ll think about optimizing some other time.

rigid island
#

are you using assembly def

waxen burrow
lean sail
rigid island
hard viper
#

it’s fine, and every so often people say it’s really slow, but i don’t think that’s the issue

heady iris
#

do you have compile errors

rigid island
# waxen burrow

🤷 only thing I can think of is you have maybe assembly def files or compile errors

waxen burrow
heady iris
#

assembly definitions group your code into DLLs. Code in assembly A can only reference code in assembly B if A references B (and you can't have cycles)

#

You often give library code an asmdef, since it can't possibly know about the rest of your code anyway

#

assemblies speed up compilation

#

If you have never created an asmdef of your own, then your code is in the default assembly, which automatically references every other assembly

#

so it wouldn't be an issue

waxen burrow
rigid island
#

you dont create one

silk edge
#

Do I add the collision detection in the character controller?

rigid island
#

since you're new this doubt you created one so it shouldn't apply to your case

heady iris
rigid island
heady iris
silk edge
#

Yes

heady iris
#

That gets sent to every component on the same object as the character controller

#

Any of them can receive it.

#

It makes sense to put it in the same component that's responsible for moving the controller

rigid island
#

its just a callback for collision, it doesn't actually make it collide or anything

silk edge
#

Just a collision that allows the player cube to push the others

rigid island
#

did you try it

waxen burrow
#

well it seems to work now... Must have needed to recompile and didnt do it automatically

#

idk

#

Thank yall for the help

silk edge
rigid island
#

there should be none since its code from Unity example lol

late lion
heady iris
#

oh right, I had it the wrong way around

#

it's about things have Auto Referenced enabled on them

silk edge
#

Oh i forgot a ; on the float variable

rigid island
#

!vscode

tawny elkBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

heady iris
#

assuming your code editor isn't working, yes

rigid island
silk edge
#

So it compiled now lol, but nothing is being pushed

rigid island
silk edge
#

2.0f

rigid island
#

play around with different values see if it helps

#

are u sure those boxes are Rigidbody and not static/Kinematic

silk edge
#

No 100 doesnt move it either

#

Nevermind it had kinematic

#

It does move after all thanks!

rigid island
silk edge
#

Yeah thats what Im working on next

rigid island
#

you dont want to be swimming with sharks without cage, sure you can do it but not a very good idea 😛

hard viper
#

yeah, you really want VisualStudio to guide you to the exact variable names, or you will go insane

rigid island
#

GPT's version of analogy

Having a configured IDE for coding in C# is like having a well-equipped kitchen when cooking a complex meal

#

lol

heady iris
#

It significantly reduces the amount of typing you have to do.

#

so you spend less time converting ideas into code

#

so you have more time to bikeshed pointless things, like I am right now

#

(I'm overdesigning something that I have no use-case for yet)

rigid island
#

Interesting, almost what GPT said on that point:

Focus on Creativity: With a configured IDE, you can focus on the creative aspects of coding and problem-solving, much like a well-configured kitchen allows you to focus on creating delicious dishes.

waxen burrow
heady iris
#

an important characteristic of code completion is that it reduces the amount of typing you have to do without generating patent nonsense

hard viper
#

It just makes programming less obnoxious

heady iris
#

me when I'm in a garbage generation competition and my opponent is GitHub Copilot:

waxen burrow
#

90% of the time it spews nonsense

rigid island
#

intellicode for vscode has entered the chat

heady iris
#

i had to turn that off immediately

#

it kept suggesting nonsense names and generating lines of code that made zero sense

#

actively getting in the way of writing anything

rigid island
#

i don't get how they can make it work so well on windows but so shite on vscode

#

i thought they used the same intellicode

heady iris
#

on visual studio, you mean?

waxen burrow
#

Yup, the non consensual auto fill is crazy too

heady iris
#

"intellicode" is not "intellisense"

heady iris
#

intellicode is some kind of AI vomit

rigid island
#

whichever likes to autocompletes or w/e

heady iris
#

in lieu of actual static analysis

#

boing

#

maybe we should add a footnote to the VSCode instructions about how to turn that off

hard viper
#

int x =
did you mean:
int x = GetComponent<RigidBody2D>().position.x?

heady iris
#

genuinely frustrating to do any work with it on

rigid island
#

If they want us to switch to VSCode for mac they better make this shit work soon

heady iris
#

well, you make it work by turning it off

#

intellisense is still there

rigid island
#

intellicode works well on VS tho why can't they make that good

hard viper
#

this is why we don’t let ChatGPT code for us

rigid island
#

so it offers actual useful stuff saving typing 2X

#

"oh you were gonna write a loop with this, here you go"
..writes whole loop

#

ok maybe a loop is bad example because you can tab for twice

#

but you get what I mean

#

its good /useful when it works

hard viper
#

i’m just happy that I can block visual studio from automatically putting { on their own lines

#

so many unnecessary blank lines makes it hard to read

hard viper
#

yeah

#

easy setting

rigid island
#

I see lots of people prefer the java style

#

I may convert soon

hard viper
#

which style

rigid island
#

to style java

#
public void Method(){
//stuff
}```
hard viper
#

that is what I do

rigid island
#

its very popular on java and javascript i noticed

hard viper
#

it is vastly superior to making a whole line for {

orchid bane
#

I can an array of a type which can return an array. How would I easily get an array which contains all elements of all the arrays I get when I call the method on each element of the array?

rigid island
#

after a while I dont even notice the { on the new line tbh

#

it starts to look like python to me xD

hard viper
#

or an array of areays

orchid bane
hard viper
#

int[][]. Just loop through and get all the elements

orchid bane
#

I need to return T[]

lean sail
hard viper
#

you mean T[][] to T[]?

#

then you might want a struct

orchid bane
#

Yep. But would be preferrable if T[][] didn't exist in the first palce

simple egret
#

Tip, you can make VS export an .editorconfig file that follows your code style, that will be put in the solution folder. Now everyone that clones the project will receive the editor config, and VS will override its settings to enforce the rules in the editorconfig file. Good when working with a team! EditorConfig is a standard and will work across most IDEs.
Braces on newlines is still the convention for C# though.

hard viper
#

struct MyStruct<T> {
public T[][] myarray;
….
}

rigid island
orchid bane
hard viper
#

you can even make your struct IEnumerable to loop through all of them

#

then just make an array of lists of colliders

#

i do not understand what us making this difficult tbh

orchid bane
#

What I posted is already an answer to what I asked

cold parrot
rigid island
hard viper
#

i have long names, and if I have to give my function declaration multiple lines, I can just give it its own newline manually

rigid island
#

its like having an essay being double spaced vs not
former being more legible

hard viper
#

while my IDE doesn’t fight me to insert a one line { for small methods

cold parrot
hard viper
#

i don’t try to read the {

#

I read the indentation

#

i read the shape

#

i look at it, and it makes sense to me

cold parrot
#

That (indent) fails with complicated signatures

hard viper
#

I don’t have a problem, even with 3 line function declaration

#

I just want the default to be almost no whitespace, so I can add as much whitespace as I want

cold parrot
#

VS and Rider have limits to what they can do format wise procedurally and often a separate line for brackets and braces saves the day

cold parrot
hard viper
#

i find both very important

cold parrot
#

Yes but if you have to chose, favor consistency

hard viper
#

i go through regulatory documents for work, and some countries put the same information that fits in 2 pages into 10-15. It actively makes my job way more difficult. Even if the 10-15 pages is extremely consistent

#

you just need to scroll and scroll for what you’re looking for, and it drives me mad

cold parrot
#

That’s an anecdote that doesn’t relate

rigid island
#

second one deff more legible even with vars on same line

hard viper
#

it does relate. If you totally forsake tersity for consistency, you get a clusterfuck

rigid island
#

but yeah at the end of the day is just preferences 😛

hard viper
#

you need to balance

cold parrot
rigid island
#

its like arguing:" I prefer to put a line in my 7 where some dont"

hard viper
#

realistically, you are going to have a mix of many small function signatures, and a small number of giant ones. That is fact. You need to weigh both.

cold parrot
#

the only sane thing to do is to stick to the most widely used standard. It makes everything easier.

simple egret
#

This, especially when multiple people work on the same code base

#

Your PR was rejected
Code does not comply to naming conventions

hard viper
#

you know you can change { to your preferences by just pressing ctrl i, right?

#

if you have multiple people on a project, you will have different preferences

simple egret
#

Hence why you must unite them into one

cold parrot
hard viper
#

naming conventions are more important than newline standards

simple egret
#

Else you'll have commits from other team members with the description: "fixed formatting of XYZ"

hard viper
#

newline standards can be extremely quickly redone by computer

#

naming cannot

cold parrot
#

Naming conventions are impossible to establish

simple egret
#

You didn't use Git with a team did you

hard viper
#

i mean naming for variables

#

conventions like camelcase, pascalcase, screamcase for consts…

cold parrot
#

to get good names you have to teach people a hundred things about patterns and what readable code looks like, which is very difficult

rigid island
#

yeah you dont' wanna be the one doing private string sum

hard viper
#

tfw you have a function name that is 60 characters long

rigid island
#

at least we're not in the dark ages of character limit for vars

#

hence why abbrevation is ugly now days

#

I cringe when I see that still

cold parrot
#

Most overly long names are a sign or symptom of the author not structuring their code/module or not thinking about what they are doing.

heady iris
#

i'm having some trouble with that right now

#

I have lots of state machines with unique states

#

LinearBossLocomotionMoveState is a mouthful:

  • It's for the LinearBossLocomotion locomotion system
  • It's for a move command, so Move
  • It's a state, so State
rigid island
heady iris
#

I considered using namespaces

#

so that it's just be MoveState

#

but then I'd have 20 IdleState classes

cold parrot
heady iris
#

although, I do rarely reference specific state classes outside of the context of sibling states

#

I mostly just reference EntityState everywhere

#

so maybe I will go back to namespaces again

cold parrot
#

Defeats the purpose

heady iris
#

and instead trigger all state changes from within the FSM's states?

cold parrot
#

Ie you separate transitions logic from state implementation

floral coral
#

I have a manager that puts an icon over a planet on the screen, and it needs that planet's position. The planets have a PlanetController MonoBehaviour, and a PlanetData ScriptableObject. Should the icon manager script address the PlanetController script directly to get the position, or should it talk to the PlanetData scriptable object, which would have a function to get the planet's position from the MonoBehaviour and return it to the icon manager script?

spark yew
#

i'm trying to follow a couple of tutorials for making an inventory system rn and they all seem to be based on drag and drop icons

does anybody know how i can make it into a sort of list system instead (where you'd just pick an item from a list, no crafting and no drag and drop), i can't seem to find any resources and i kinda need a nudge in the right direction

lean sail
spark yew
#

but mostly displaying data

#

like i said a lot of the tutorials spawn the items in a drag and drop system with a lot of icons already there

#

i want the items to just show up when you get them

orchid bane
#

Can I serialize non-primitive types like Vector3 in Sql when they are inside other types like Transform?

#

So I want to have a structure with position but I don't want to break it into 3 separate floats

knotty sun
orchid bane
knotty sun
#

of course

lean sail
knotty sun
orchid bane
knotty sun
#

it can do, it supports the Blob data type which can take any binary data

#

but you should not need that, the system creates C# classes for you from the table definitions, you can extend these to do what you wish

languid saddle
#

hey, when i change a color the color sets to white, and if i just change a bit in the inspector it sets to the wanted color

lean sail
elder flint
#

Hey guys, I need a bit of help. I posted this in the wrong channel, #archived-game-design , but that's my issue so i don't double post it

languid saddle
#

example of playerpref recived (RGBA(0.349, 0.229, 0.104, 1.000))

simple egret
#

For example, on a system that use a comma as a decimal separator, you will write (RGBA(0,349, 0,229, 0,104, 1,000)) and attempt to read it, leading in a failure if you split the string by a comma. You'll get 8 elements instead of 4.

brisk plaza
#

Hi

#

Hi I need to make the SDK read-only:

waxen burrow
#

would someone be able to offer an explanation as to why unity is destroying my serialized properties?
I have a few classes, most importantly a serialized class named Item (which is a POCO with the children Armor and Weapon which each have various children of their own) and a pickup class (mono-behavior put onto the player) which holds a reference to one of the children of Item.

The reference to item inside pickup is marked as [serializedRefrence, RefrenceDropdown] using this plugin: https://github.com/vertxxyz/Vertx.SerializeReferenceDropdown

Whenever I set the reference and start the game, I get this error:

#

any ideas?

#

Here is the code from pickup:

    [SerializeReference, ReferenceDropdown]
    public Item itemInstance;

    private void OnTriggerEnter(Collider other) {
        if (other.CompareTag("Player")) {
            InventoryManager.Instance.Add(itemInstance);
            Destroy(gameObject);
        }
    }
}```
leaden ice
#

This looks like an editor only issue, e.g. an issue with rendering the inspector

#

I imagine it shouldn't have any impact on gameplay itself

scarlet kindle
#

I am having slightly inconsistent results using a conditional to check

    if  (transform.hasChanged)
    { // checking faces of die }
    else { 
           if(deltaTimeElapsed > 0.2) {
                    //assume die is finished
           }
     }

for a dice roll event, to make sure the die has stopped moving before getting it's side

#

in the else statement, that is where I consider it finished

#

Is there a better approach?

#

it works like 9/10 times or more, but sometimes the else's inner conditional just doesn't get reached at all

#

i guess if the roll was super quick, that would be the only situation that could happen so maybe i just need to make the time window a bit smaller, like 0.05s or something

#

doing that didnt fix it either 😦

knotty briar
#

dont really understand the problem in your code, can you give more context

waxen burrow
scarlet kindle
knotty briar
#

yes but why are you doing it like this

scarlet kindle
#

idk is there a better way?

#

oh its probably due to my face detection algo

#

as to the why im doing it this way I mean

#

im checking the normals with dot products and stuff, not using any raycasts. its a pretty cool algo I borrowed from a youtuber

#

but because of this, i need to wait til the die stops moving

#

I mean, i'd think you need to do that with any solution to detecting the faces, but shrug

devout solstice
#

so on my school computer right it was talking about how i had the old event system or some shit and there was a button to import the new one, but on my computer its not saying that and the event system here is not the same as the one on my school computer

neon plank
#

Why Rigidbody.sleepThreshold is not shown in the inspector?

devout solstice
#

what kind of variable is it

#

and is it public

neon plank
#

float?

devout solstice
#

is it public

#

is it a global variable or a local variable

neon plank
#

I'm talking about the Rigidbody component

#

The 2D version has in the inspector field to configure its sleep behaviour

#

But the 3D version doesn't

devout solstice
#

huh

orchid bane
#

How can I do this? It says either parameter or return type has to be the type I write it in

public static implicit operator Vector3((float x, float y, float z) tuple) => new Vector3(tuple.x, tuple.y, tuple.z);```
neon plank
orchid bane
neon plank
#

Ohh,

#

I see

oblique spoke
neon plank
#

You can only make operator for clases you made

#

You didn't write neither Vector3 nor (float x, float y, float z)

#

@orchid bane

orchid bane
#

Isn't there a way around this?

neon plank
#

If you want something more immediate I would do an extension method instead

orchid bane
#

For the tuple?

neon plank
#

Yes

orchid bane
#

Thanks

solid laurel
#

Trying to make a lightning strike spell when an enemy enters a trigger and the player hits a button, but it doesn't seem to instantiate the lightning strike at all

    {
        if (Input.GetKeyDown(KeyCode.F))
        {
            ButtonPressed = true;
        }
    }

    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Enemy")
        {
            enemyPos = collision.transform.position;
            if (ButtonPressed == true)
            {
                Debug.Log("Spell Pressed");
                ButtonPressed = false;
                if (LightningStrike == false)
                {
                    Debug.Log("Lightning Strike initiated");
                    LightningStrikeInstance(enemyPos);
                }
            }
        }
    }

    private void OnEnable()
    {
        playerControls.Enable();
    }

    private void LightningStrikeInstance(Vector3 enemyPosition)
    {
        LightningStrike = true;
        instanceLightning = (GameObject) Instantiate(lightningStrikePrefab, enemyPosition, Quaternion.identity);
        Debug.Log("SPAWNED");

        StartCoroutine(WaitTime(2f));
        LightningStrike = false;
        Destroy(instanceLightning);
        Debug.Log("DESTROYED");
    }

    public IEnumerator WaitTime(float waitTime)
    {
        yield return new WaitForSeconds(waitTime);
    }
lean sail
cosmic rain
solid laurel
#

Ohh ok that makes more sense

#

Holy cow that actually worked thank you guys!

#

How could I also make the lightning spawn a few increments above on the y?

lean sail
solid laurel
#

ah ok

restive canopy
#

Not exactly code, but:

Whenever I open a script on visual studio on my microsoft surface (windows 11) the filename is listed as "miscellaneous files" and not "assembly c#"

And the project is listed as having 0 solutions

Also the top doesn't have "attach to unity"

I have tried uninstalling and reinstalling visual studio and checking to see if I modified visual studio with the unity game design thing

tawny elkBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

rigid island
#

follow this

restive canopy
#

👍

rigid island
#

esp the workloads

restive canopy
#

it works now i just needed to put visual studio in the external script editor

#

thank you

proud arrow
#

I've been playing the the Graphical Stata Machine, and I got it to Invoke() Methods in an seperate C# script. Now I'm trying to get the C# script to access as Script Machine Variable. Does anyone have an example on how that's done?

#

I have 'using Unity.VisualScripting' and a have a bool boolName in the Variables component in the Game Object. But when I try to access it with 'scriptBool = (bool)Variables.Saved.Get("boolName") I get a Variable Not Found error.

#

Whoop. Found the answer. Instead of 'Variables.Saved.' it should be 'Variables.Object(this).' That works.

loud wharf
thin aurora
#

Though you should not do these micro managed pieces of code. It brings no quality.

swift falcon
#

What is the best way to handle this cast data.floor = newData as FloorData;
Classes are FloorData : BaseData, IConstructable NewData : StackableData, IConstructable
StackableData is BaseData though
StackableData : BaseData
So the data is compatible but I'm just not sure how to handle the casting? For context the reason NewData isn't base is that some building data can be stacked

Other classes

ColumnData : BaseData, IConstructable
PropData : StackableData```
fervent furnace
#

It may fails in down cast: basedata to floor data

#

Newdata can be safely cast to stackable and stackable can be safely cast to basedata, but not all basedata are floordata so it may fail

swift falcon
#

Maybe for the time being I can do

PropData propData = (PropData)(newData as StackableData);
propData.buildStage = newData.buildStage;```
oblique spoke
#

Aren't you basically asking for duck typing here?

swift falcon
#

not sure what duck typing is?

#

All I know is that I control the cast because it's a switch depending on the kind of job I'm doing

So it's like... I know that A will always fit into B, but it can't cast so I'm not sure how I cast it then

#

Looking into the duck thing and yes probably? I'll look into it more

oblique spoke
#

C# doesn't determine type compatibility by their contents, but by actual types they implement

swift falcon
#

Yeh and because Stackable inherits from Base and the floor Inherits Base... I thought that'd make it compatible

oblique spoke
#

NewData doesn't implement FloorData

#

(still referring to your original question)

swift falcon
#

So I can't cast unless it directly inherits from FloorData at some point, it doesn't matter if they both inherit from the same root Class?

#

I guess Inside the FloorData class I can just write my own implicit casting

oblique spoke
fervent furnace
#

You can safely cast to base class (move to root) but down cast (move to leaf) may fail (not must fail)
Inheritance is tree structure

oblique spoke
#

Well you could do terrible things with dynamic and/or reflection, but it's probably best to revise your design

swift falcon
#

Yeh the only issue I'll have is losing the interface data though?

#

I tried to design this to be flexible but it seems my design in general for things these days is just bad

#

Reached the point where I can have an idea and get it to function but it's been a bane because it doesn't mean I'm achieving anything well

#

I keep refactoring things because it's a mess and it just ends up a different kind of mess lol

oblique spoke
#

Yea inheritance just tends to break down when you try to model these sort of complex trees.

swift falcon
#

So the data types was just a way I designed save data, all my tiles use it and it's been easy because I get the type of data and process it according to the type and can gurantee they have the data I need. That was the original design

#

Now I'm working on a job system which is tons of things that need doing like building walls, floors and etc and it's now crossing that over that seems to be causing this mess

#

I wanted to just be able to pass it to a cell and that just handle it accordingly, it was meant to be a clean design but I duno what's good or bad design anymore

#
public void Execute()
{
  // Restore our preview back into a functional objects
  PreviewManager.EnableColliders(newData.gameObject);
  PreviewManager.RestoreMats(newData);
  PreviewManager.ClearCollisionDetection(newData);
        
  cell.InsertObject(newData, owner.placementID);
}```
Like this was meant to be good but I duno if I'm doing things right or wrong anymore and it's really messing with me

(It's a function in a Job class) which is 1 per thing that needs doing
#

Sorry.. Guess I'm just ranting at this point

#

Thanks for the help, I'll try and think of ways to improve on this

slate pulsar
#

Hey, when I add a terrain to a gameobject like so: var terrain = island.AddComponent<UnityEngine.Terrain>(); and apply a terrain material and an alphamap, it works but the normals for the terrain layers don't show until I re-select the material in the inspector manually and I can't figure out why.

I have tried terrain.Flush() but without success.

swift falcon
#

If you are making changes to parts of a HD Material in unity (Like normals) it isn't actually updated manually, when you press it in the inspector the Editor reloads it

To update a material in runtime you use

"HDMaterial.ValidateMaterial(newMaterial);"

#

If you're using premade materials and not changing them, then I wouldn't know sorry

knotty briar
#

and get the reference like that

swift falcon
#

Depends if you're dynamically updating materials or not

#

By that I mean like properties in the material itself

old plinth
#

I hope the line renderer is perpendicular to the y-axis without looking at the camera. However, the lin renderer always looks at the camera. I tried to modify the alignment, but the child line is not displayed when I modify it from View to Transform-Z. How can I solve it?

steady valley
#

Hi, is it normal that serializeField in my property drawer doesn't appear in the editor ?
I would like to avoid hard coded reference

slate pulsar
swift falcon
slate pulsar
#

No I am changing the normals on the terrain layer at runtime

quaint escarp
#

hello! Does anyone know the behaviour of "is" or "as" for an Unity object when it's destroyed? Is it going to cast to null and/or return false or is it going to return the type?

swift falcon
#

I sadly don't know then sorry Ziptie sad

slate pulsar
#

hm ok

swift falcon
#

When it's destroyed then the type of what you get should be null in general

late lion
swift falcon
#

I think it can sometimes still return GameObject when destroyed though

#

If you do

Destroy(targetGameObject);
if (targetGameObject is null){}```Then targetGameObject is GameObject

if you destroy and then do
```csharp
if (oldGameObject is null){}```Then oldGameObject should be null... I think?
#

I could honestly be wrong though

lean sail
quaint escarp
# swift falcon Do you have an example of how you use it?

my game's interactive objects are called SimObject, which are derived from MonoBehaviour, and when they are active characters, they are SimActor, derived from SimObject; there's a function that removes a SimActor from a spawned Dictionary by its id, but I check if it's a SimActor:

if(despawn.Value is SimActor simActor){
 SimsMachine.singleton.OnActorDespawn(simActor);
}

"despawn.Value" is a SimObject
for some reason, sometimes "SimsMachine.singleton.OnActorDespawn(simActor)" is not called, so I thought it could be that "despawn.Value is SimActor simActor" evaluates to false because this function is called when the game reloads and the objects are actually Destroyed (which is done in an unordered way by Unity), but other stuff that happens outside the if clause still function normally.

My objects are not destroyed during normal gameplay, though, so the function is being called as it should; they are pooled.

lean sail
#

But also just use == null

swift falcon
oblique spoke
lean sail
oblique spoke
#

Unity's destroyed check relies on overloaded operators, so you can generally check C# documentation whether a specific feature uses overloaded operators

quaint escarp
#

thanks, I found the problem while analysing deeper because of your help. So the sim actor removal wasn't being called when the object was releasing its id, just when it was being unloaded. (There are two types of despawn in the game)

loud zenith
#

Generally, which is better to use - Coroutines or Asnyc methods?

fervent furnace
#

some time they are not interchangable

#

if you can use coroutine then use coroutine, since some unity (async) api is designed based on it

thick terrace
#

coroutines can also do unity-specific stuff like waiting for the end of the frame etc that async methods can't (without some extra code)

fervent furnace
#

coroutine stops if gameobject destroyed but not async (i got NRE because of that)

uncut vapor
#

How would you go about making a terrain system (2d)? I'm using squares for materials, but I'd assume it'd be inefficient to place each block one by one and it should use a mesh instead
But how do I do that so that both the shape and texture is right?
Or is it fine to use singular squares?

cosmic rain
uncut vapor
#

Oh I forgot that existed
And how do I add a texture to it? Like when a different material is placed

radiant badge
#

Can someone give me feedback on my devlog?

uncut vapor
#

Yeh

cosmic rain
#

You don't add materials to a tilemap. You have different tiles with different sprites.

latent latch
#

How many c# laws do I break if I use new to hide variables/override in a derived class?

latent latch
#

:(

rain minnow
#

naw, i think i did that before . . .

latent latch
#

I can't use any more generic constraints, I'm digging this hole way too deep

rain minnow
#

i was going to say is it bcuz of generics?

grave quarry
#

I'm using OnEnable to load in a scene. i'm aslso trying to load specific scenes by referencing a JSON file with another class. The issue is that by doing this it causes a loop where when I load in a scene from the scenemanagement class it also loads in the datapersistence manager (with the onenable) in the second pic which causes an infinite loop. I suppose my question is that is there ether a different system I could use instead of OnEnable for scene loading or is there a known method to stop this infinite loop.

knotty sun
latent latch
#

Generic slots, with generic storable types, with generic interfaces (which include their specific SO type)

#

I was using covariance but it's too much to work with

#

Basically, I had eliminated a lot of type checking, but it started created complications as I kept expanding the project.

rain minnow
#

a complete generic structure (architecture) to eliminate type comparison it seems . . .

#

do you need to check if the storable type is the same as the slot type?

latent latch
#

I wanted to do like some MMO hotbar kind of thing, and it works pretty well, but I think I can eliminate a lot of code if I just type check a little instead.

#

it's not like I've that many types in general to make full use of covariance

rain minnow
#

are you using SOs to check the type? that's what i usally do . . .

latent latch
#

I do have to type check currently if it's something more derived, but I think I could have optimised it a bit more

#

So the idea probably is something like this:

public interface IStorable
{
    StorableSO SO { get; }
}

public interface IItem : IStorable
{
    new ItemSO SO { get; }
}

public interface IEquippableItem : IItem
{
    new EquippableItemSO SO { get; }
}```

It would eliminate a layer of my constraints and I can always expect an at least derived type
knotty sun
#

Why not use inheritance on the SO side and elimate the need for this?

latent latch
#

Yeah, I got all the inheritance in parallel with each other. It's just when you have three layers of generics, you have to be quite type specific on everything.

rain minnow
#

can't each class implement the corresponding interface so they're not derived from each other?

knotty sun
#

no, that wont work

#

you need the consistency of SO for the compiler

rain minnow
#

so it has to be done on both ends?

latent latch
#
public abstract class Slot<S> : where S : IStorable<IStorableSO>{}
public class ItemSlot : Slot<IItem<IItemSO>> {}
public class EquipmentSlot : Slot<IEquippableItem<IEquippableItemSO>> {}

public abstract class Storable<SO> : IStorable<SO> where SO : IStorableSO {}
public class Item<SO> : Storable<SO>, IItem<SO> where SO : IItemSO {}
public abstract class EquippableItem<SO> : Item<SO>, IEquippableItem<SO> where SO : IEquippableItemSO {}

public interface IStorable<out SO> where SO : IStorableSO {}
public interface IItem<out SO> : IStorable<SO> where SO : IItemSO {}
public interface IEquippableItem<out SO> : IItem<SO>, IUsable<SO> where SO : IEquippableItemSO {}```
#

This mess of a system

knotty sun
#

yes
@latent latch I thinks it's a good solution, looks unorthodox but does the job

latent latch
#

If you like covariance, hey it works

rain minnow
latent latch
#

interfaces are required for the covariance, but without covariance I can remove the generic binding here which is something I want to do

knotty sun
#

It looks like a mess but it saves you from a lot of redundant type casting which can only lead to cleaner logic code

scarlet viper
#

Gizmos.DrawLine works in build ?

knotty sun
#

no

hard viper
latent latch
#

but you cant override its return type

#

which is my problem for my crappy solution there haha

hard viper
#

why can’t you just make it a different function?

latent latch
#

As in multiple getters for each derived type?

hard viper
#

if the return type is different, that feels like just a totally different thing

#

so why are you trying to override

latent latch
#

The getter should always return the most derived type of the SO is what I'm trying to accomplish

#

easily done with some generic constraints, but the complexity of adding more constraints upon it makes the compiler mad at me

#

I'm just not that proficient with generics

hard viper
#

i feel like there should be an easy way to do that

#

maybe ask the C# discord

#

a generic is probably the way to go

#

i’m pretty sure you need something like: ChildClass : ParentClass<ChildClass>

#

Then ParentClass<TChild> {
and your getter returns a TChild

#

If you need multiple children accessible along the way, you probably need to define a non generic version for unity to workwith

latent latch
#

The overall problem is how the slot itself is generic, and it contains a bunch of these generic types. The idea is if I can reduce a lot of the constraints that the slot is containing, then I'd have to be less type specific (but I'll have to cast more often).

#

But I'm trying to go half-way here and trying to figure out the best way to expect an 'atleast' derived type of an item contained in the slots

hard viper
#

——Parent
ParentBase<TParent> { property returns TParent}

Parent : ParentBase<Parent> {}

—— Child
ChildBase<TChild> : ParentBase<TChild> { childimplementation}

Child : ChildBase<Child> {}

—-Grandchild
GrandchildBase<TGrandchild> : ChildBase<Tgrandchild> { grandchild implementation}

Grandchild : GrandchildBase<Grandchild>{}

#

something like that could work

#

just because Unity hates generics

#

under normal circumstances, those non base classes would not be necessary.

hard viper
#

@latent latch let me know if that helped or not

#

This should also not change anything in the SOs that exist for the matching type

latent latch
#

Currently messing around with other implementations but I do understand what you're accomplishing there

#

There's just a lot more extra stuff going on with what I got which is making it trickier to implement something clean

hard viper
#

out of curiosity, could you use a generic interface?

latent latch
#

I am

hard viper
#

does that not work?

latent latch
#

It does work alright, but it turns a lot of my functionality very type specific. It's not awful, but it's such a headache to work with,

thick socket
#
        RaycastHit2D hit = Physics2D.Raycast(transform.position,transform.right, 1, mask);

vs

        RaycastHit2D hit = Physics2D.Raycast(transform.position,Vector2.right, 1, mask);
#

not sure which I should be using

#

or even there is even a difference

hard viper
latent latch
#

I pretty sure there's ways to do this in java, but it probably does something similar to redeclaring the type of the derive.

#

OOP is hard

latent latch
#

Well, I guess if you don't rotate your transform it wouldnt matter, and it's in the same system composition as world

thick socket
latent latch
#

Try debugging it and see if the values change

#

then rotate your transform and do it again

thick socket
#

from my limited understanding, you can get the point of contact

#

from there you can probably determine that

#

collision.GetContact(0)

#

from private void OnCollisionEnter2D(Collision2D collision)

rain minnow
#

like Hawk mentioned, you can get the contact point, then use a direction from the center of the circle (as the reference of angle 0) to determine the angle of the contact point . . .

thick socket
#

instead of rotation 😄

latent latch
#

If you dont rotate your transform then you're probably already aligned to world coordinates so yeah, it wouldn't matter then

thick socket
#

so need to flip the way it faces depending which direction my "enemy" is facing 😄

#

EDIT: nvm I forgot that the ray stays for 0.2s so its just where enemy is moving from 🤦‍♂️

heady bronze
#

I'm hoping someone can help - I'm building a scene into an asset bundle, there's nothing in the scene except a room made out of simple cubes with a standard shader, some simple seats and a single spot light that's using baked lighting.

I bake the lighting then export the asset bundle and then download it in a different project and open the scene.

Once I do this I can see that the lighting is completely different - I can't for the life of me understand why!

graceful flume
#

Hi guys. I want to create a leaderboard that the player can enter their own name for a new high score. Any tutorial for that ?

graceful flume
rigid island
#

A file can work just fine as well

#

simple json or som

thick socket
#

I would probably just make an object that holds name/score

#

a list of highscores

#

and then a simple json to save it to

rigid island
#

just make sure you obfuscate the file extention to keep the common folk from prying the file and changing values

thick socket
#

I mean

#

if its singleplayer

#

I wouldn't care if they did that

graceful flume
#

i can get my head around displaying the names and scores, but how can i get the input for players name ?

#

like when people want to type their own name

thick socket
#

likely achievements/rewards wouldn't be based on that but on the score that would be sent

#

so all they could change is the visual score

#

If I do Debug.DrawRay

#

that only effects performance when Im in scene view right?

#

or do I need to "disable" that code before doing play normally/building project

rigid island
rigid island
warm stratus
#

Hey i wan't to change the scene after a certain amount of time but starting to load it before so i used LoadSceneAsync but how can i change the scene after the X seconds?

AsyncOperation sceneLoadingOperation = SceneManager.LoadSceneAsync(sceneName);
yield return new WaitForSeconds(minimumLoadingTime);
//SceneManager.LoadScene(sceneName);
steady moat
whole yew
#

I'm making my own rigidbody fps controller, and my player collider has a physics material with 0 friction, but when i stop running on the ground, my speed slowly decreases. Why? If i have no drag and friction, I should be sliding with constant speed forever

rigid island
dusky lake
whole yew
gray mural
#

Hello, is there any way to add a field directly on transform? E.g. myGameObject.transform.myField

warm stratus
somber nacelle
rigid island
#

!code

tawny elkBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

whole yew
# rigid island dont make videos of code

mb, it was mainly to show the interaction that my speed is slowing down. (and I have no code that would slow me down anyway) so this problem is more of a "why is my rigidbody character getting friction or whatever"

rigid island
#

uh why is collider not on the main rigidbody

gray mural
#

I see. Maybe that was a XY problem. I have to create an "ultimate name" for my gameObjects, I'll access them using that name. Also the player is able to change names of gameObjects that they've spawned already. Those are gameObject.name. What should my "ultimate name" be? A tag? Guess it's weird to create a new tag for every gameObject. Also it's not that good to access the name using their class ItemBehaviour.itemName ?

somber nacelle
#

wtf is an "ultimate name"

heady iris
#

like, a unique identifier?

gray mural
gray mural
heady iris
#

you need a key.

knotty sun
#

sounds like you need a GUID

heady iris
#

I suppose you could attach an Identifier component to objects that need such an ID

rain minnow
#

a guid?

heady iris
#

and then store a GUID or something similar in it

gray mural
#

so Zombie is a "unique name" and Larry is a name (that is changed by the player)

heady iris
#

explain what you will use this name for

rigid island
gray mural
heady iris
#

You said you will "access them" using this name

gray mural
#

oh, I see

somber nacelle
heady iris
#

but then you said that an object's "unique name" will be Zombie

#

That doesn't sound like a very unique name...

#

Do you mean that this name is supposed to tell you what kind of object it is?

#

so every zombie has that Zombie name

rain minnow
whole yew
rain minnow
#

sounds like you want to set up prefixed and suffixed names for objects . . .

gray mural
#

(well, it's Component.name for now, that's what I have to change)

heady iris
#

So each item in your game will have a specific "kind", like "knife" or "bomb"

#

even if you renamed it to "stabby object" or "mcbomb"

gray mural
heady iris
#

a "unique name" would be different for every single object

#

hence why a few of us brought up things like GUIDs

rain minnow
whole yew
rain minnow
heady iris
#

sounds like every item should have an Item component on it that holds the category

gray mural
heady iris
#

if you have two things named "zombie", then "zombie" is not a unique name

hard viper
#

yeah, it sounds like you’d want a unique identifier

gray mural
rain minnow
heady iris
#

i don't see a clear meaning for "ultimate name"

#

that's why I suggested "kind"

#

"zombie" is a kind of thing. You can have lots of zombies.

somber nacelle
#

yeah seems like they just want a default name that matches the category of the thing

gray mural
hard viper
#

what I do is I have a singleton EntityLedger. Whenever I spawn something new, I entityLedger.RegisterNewEntity(newGameobject).

#

I also call entityLedger.LogDestroyedEntity(object) whenever a logged object is destroyed

gray mural
rain minnow
hard viper
#

RegisterNewEntity adds the entity to a giant list of all spawned entities, asks to issue a new serial number, maintains a dictionary of SerialDict[gameobject] = its serial#, and returns that new serial number

#

this way, every entity can have a unique serialnumber tied to it.

gray mural
#

before it wasn't an issue, as they all had names like Zombie, Knight, Wall 1, Ground 2

hard viper
#

name given by player should be decoupled from gameobject name

#

gameobject name can depend on player’s name, but not the other way around, or you will run into issues

stark ginkgo
#

Anyone know if I can use c# reflection in webgl?

gray mural
rain minnow
stark ginkgo
#

considering using your sql package for an mmp

knotty sun
stark ginkgo
#

mmo*

hard viper
whole yew
gray mural
whole yew
#

how did i skip that 😂

hard viper
#

because if the player names 2 zombies larry, you can’t return larry. You need to return a list of zombies named larry

whole yew
gray mural
#

sounds not as complicated either?

hard viper
#

that’s kind of what I do

somber nacelle
hard viper
rain minnow
heady iris
#

I think you should first figure out what defines an item.

#

what makes a knife different from a spoon?

hard viper
#

do you want to allow multiple Larry, or allow finding a unique zombie named larry? The two are mutually exclusive

heady iris
#

do you have a ScriptableObject class that each item holds a reference to?

gray mural
# hard viper you need to decide what you want it to do before we can help you do it
public TResult SpawnItemByName<TResult, TData>(TData data) where TResult : ItemBehaviour where TData : ItemData
{
    TResult itemBehaviour = GameManager.instance.GetItemByName<TResult>(data.name);

    TResult result = Instantiate(itemBehaviour.gameObject, data.position, itemBehaviour.transform.rotation, environment).GetComponent<TResult>();
    result.name = data.name;

    return result;
}
hard viper
#

i don’t need code

#

i need you to explain what you want the code to do

gray mural
gray mural
hard viper
#

so the name is just a key to find a reference to prefab?

hard viper
#

so the key needs to be unique?

gray mural
hard viper
#

can’t you just make a dictionary then lol

gray mural
#

no multiple Ground -> Ground 1, Ground 2 instead

hard viper
#

Dictionary[key string] outputs prefab object

gray mural
hard viper
#

What I do for this is I have an SO named BuildingObjectBase. This SO has a field for the prefab it is tied to. BuildingObjectBase also has a field for TileBase, which is a tile in game it is tied to.
At the start, I have TileDirectory go through all the BuildingObjectBase to make a dictionary where tilebase goes in (the key), and BuildingObjectBase comes out.

#

During runtime, I go through all the tiles in a tilemap with GetTile(). I look in the TileDirectory dictionary for that tile, which gives me its BuildingObjectBase. I do some logic to know if I need to instantiate the prefab, and if yes, then I access the BuildingObjectBase’s field with its associated prefab

#

The difference here is you use a string instead of a TileBase. The difference doesn’t really matter

gray mural
#

I see, I go through children of #Environment GameObject

hard viper
#

But you absolutely want to organize those intermediate SOs.

gray mural
#

does it solve an issue with naming gameObjects?

#

to their names don't matter this way?

hard viper
#

It depends on what you are going for

#

My BuildingObjectBase also has a field for saveName, which is a string I can use to search for it.

hard viper
#

When TileDirectory makes its big dictionary at the start, it also Debug.Asserts that all names are unique. If I accidentally gave 2 things the same name, it will give an error.

gray mural
#

and getting it through item.GetComponent<ItemBehaviour>.itemField

#

this'll the a unique way then

hard viper
#

it is similar, but you want to protect that SO

#

my whole BuildingObjectBase is basically immutable. Nothing should be allowed to fuck with it.

gray mural
#

yeah, but it's more logic to implement, and it can be bad of performance guess ??

hard viper
#

nope

#

you do not want to store super immutable data in a behaviour

#

you want an SO

gray mural
#

well, I just have to make sure that I won't call'em the same way

hard viper
#

my entities all have a SpawnedEntityHandler, and that SpawnedEntityHandler has a field for the BuildingObjectBase it is tied to

hard viper
gray mural
#

ain't it too much for a simple logic ? 🤔

hard viper
#

no

#

it is the bare minimum

gray mural
hard viper
#

assuming you are going to have a very large number of items in the game

#

if you have like 4, it doesn’t really matter

#

but if you actually have a full game system that revolves around it, you want the error checking

gray mural
#

I see, yes, I can check it in the start, for sure

hard viper
#

debug.assert string is not already in dictionary, right before you add the string to the dictionary

gray mural
#

Still guess just an itemName field for the parent class of all items'll be enough.

#

enough until everything crashes down, right?

#

problems should be solved when they appear.

hard viper
#

If you have a very large number of unique items, you will want to make an intermediate SO to hold them

#

this way you can just drag and drop the whole list or whatever, without ruining everything accidentally

#

I have BuildingWheels, which mostly just have a List of BuildingObjectBase. I can make my TileDirectory take in a list of BuildingWheels, and then search in each of them

#

This way, instead of my inspector having one list with 300 different entries, I have like 10 SOs, each having like 30 entries each, and the TileDirectory having a list of those 10 SOs.

#

Otherwise, you will never find anything in that gigantic list when going manually

hard viper
#

i don’t mean in file directory

#

I mean my TileDirectory object.

#

It is a function of BuilderWheels, and just loops through every builder wheel, for every item in the wheel…

gray mural
hard viper
#

yes

#

My TileDirectory is an SO

#

With a different Singleton monobehaviour that sets it up. Although, I could have made it a regular behaviour, maybe. That is do not destroy on load

#

My tiledirectory SO has like 3 fields that I load in inspector which are effectively immutable during runtime. It then populates a bunch of dictionary fields based on that input. Could have used a monobehaviour, tho

gray mural
#

yes, you could've...

hard viper
#

but the intermediate wheels should be SOs

#

it’s a lot easier to reuse an SO than a behaviour. Especially as an inmutable container

gray mural
#

by SO you mean ScriptableObject, right?

hard viper
#

yes

gray mural
#

guess it's redundant in my case, as Items are just behaviours with their own scripts

hard viper
#

I did a lot of that while I was still learning, so I had to wrestle with a bunch of nonsense with SO fields changing differences between build and editor

#

in retrospect, I should have made TileDirectory a singleton monobehaviour

#

it’s very quick and easy to make SOs that just store a collection of other SOs anyway

rain minnow
#

so basically, create a CategorySO that holds a list. each CategorySO can be a different category of objects. place your individual SOs into the list of their respective CategorySO . now create a DirectorySO that holds a list of CategorySOs and place each CategorySO into the list. the DirectorySO will have a method to iterate each CategorySOs list to add their items to the main dictionary . . .

hard viper
#

exactly

thick socket
#

If I just want an Enemy to change the Ondestroy in EnemyBase do I have to make a new class to inherit from EnemyBase just to override that one function?

#

or is there a better way to do that 😄

latent latch
#

use overrides

#

if you can

heady iris
#

well, if you want to write custom code, then yes, you need to write it somewhere

hard viper
#

Everything in my game depended on my DirectorySO, so I had to make a monobehaviour singleton to hold quick access to that SO, have it set up the directory on Awake, and give it super high priority in script execution order.

thick socket
heady iris
#

You could add a UnityEvent to EnemyBase that's invoked when the enemy is destroyed

thick socket
#

or do I have to inherit

latent latch
#

Oh, you're using Unity's functions

thick socket
heady iris
thick socket
#

always forget events are a thing 😄

latent latch
#

Can't you make OnDestroy virtual though and override it?

deft kindle
#

Hi how do i fix that my player can move diagonal its a 2D Topdown

    void Update()
    {
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");

        //Animations is here
    }

    void FixedUpdate()
    {
        rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
    }
hard viper
thick socket
heady iris
thick socket
#

would rather add 1 small additional script to the object

heady iris
#

When a Unity message is sent, it invokes the method with the matching name on the component

#

So if EnemyDerived declares a method named OnDestroy, it doesn't really matter if it's an override or marked new or neither

#

That method is getting called.

#

What you might wind up doing is declare a HandleDestroy method that's virtual

#

and then override it in child classes

hard viper
#

the alternative is to put a bool you can check to change the behaviour of OnDestroy

heady iris
#

call it from OnDestroy in EnemyBase

#

EnemyDerived.HandleDestroy would be invoked, and you could call base.HandleDestroy() to let the original EnemyBase.HandleDestroy method run

thick socket
#

just adding event and new class entirely is much cleaner

hard viper
#

how many different options do you have for OnDestroy

heady iris
thick socket
#

atm 1-2

#

but Im adding like 20 more enemy types after this

lethal vigil
#

Are there any resources to better understand how to read the profiler. I have parts of my game that drops frames but I have so many objects doing their own thing I'm not sure what I need to try and optimise, going through them one by one will take ages.

thick socket
#

and ik of at least 2-3 of them that will be different ondestroy stuff also

#

whether its spawn 2 of a smaller enemy on death

#

or 7

deft kindle
heady iris
#

compare the x and y values and set the one with a lower magnitude to zero

hard viper
#

and the OnDestroy is not on a derived class, but a separate component?

heady iris
#

Mathf.Abs(foo) < Mathf.Abs(bar) tells you if foo's magnitude is lower than bar's

thick socket
#

no Ima add another class that basically just waits for an event that fires "OnDestroy"

#

then do logic there

heady iris
#

foo and bar are names I made up

#

replace them with your code's names

hard viper
#

yeah, it sounds like you need dependency injection there

heady iris
#

maybe movement.x

#

if x is -0.6 and y is 0.4, you want to set y to zero.

hard viper
#

because you aren’t trying to do something ondestroy. You’re trying to do something else

deft kindle
heady iris
heady iris
#

what? it will move diagonally.

deft kindle
dusk plume
#

how do we detect if a child is added in unity?

#

i would like to know if there is a function about that

leaden ice
hard viper
hard viper
#

That is probably a much cleaner solution to Hawk’s problem.

heady iris
#

Consult the docs.

heady iris
#

didn't know about that

hard viper
#

In my game, I have a class called SpawnedEntityHandler, which handles anything that is supposed to be super generic for anything that can be spawned. That sort of Monobehaviour is where I might put that sort of gating thing

thick socket
#
public class Spawn2Minis : MonoBehaviour
{
    EnemyCharacter enemy;
    private void Start()
    {
        enemy = GetComponent<EnemyCharacter>();
        enemy.EnemyDeath += SpawnMinis;
    }

    private void SpawnMinis(EnemyCharacter character)
    {

    }
}
dusk plume
#

and detect the name of the child?

thick socket
#

with ```cs
public event Action<EnemyCharacter> EnemyDeath;
.....
EnemyDeath?.Invoke(this);

hard viper
#

that’s another way to do it. Depends on how generic the behaviour is, and if it is on all your enemies or not. or just on enemies of a certain type

deft kindle
hard viper
#

i think your EnemyCharacter monobehaviour is the same as my SpawnedEntityHandler

gray mural
gray mural
#

thank you both your help and explanations, I really appreciate this 😄❤️

leaden ice
hard viper
#

A CategorySO will help you not get lost in your own files

gray mural
hard viper
#

If you have 300 items, you will

gray mural
hard viper
#

if all your enemy SOs are in one category, and all the items in another, and players in another, it will make it a lot easier to find everything.
This is assuming you have 1 entry for every individual little thing you add

deft kindle
#

Where do i ask for tilemap help

rigid island
#

unless its code related

thick socket
#

Is there a debug.ray but for boxcasts?

#

thinking boxcast is best for determining if my "feet" are touching ground

hard viper
#

i made my own static class to draw several lines to make boxes, and Xs, and triangles…

dusk plume
#

i am using mirror but i found the is a function in the networkmanager that detect when a player join

hard viper
#

also you should try using Gizmos, becsuse DebugDraw has some oddities because of how many frames it shows and all that.

leaden ice
thick socket
#

if not it wont take me long to make anyway

heady iris
#

Is there a way I can tell the compiler that a virtual method MUST be called by overriding methods? I just switched something from abstract to virtual (because I realized there was a common use-case). It was easy enough to add the base calls, but it'd be nice if the compiler had my back there

#

Obviously, you don't always need to call the base method, but it'd make sense as an attribute or something for when you do

leaden ice
heady iris
#

Ah, that's a good idea.

#

I've done exactly that in a few other places.

#

Although, that's a bit awkward if C derives B derives A

#

I guess B would define its own abstract method and call that

#

The use-case here is an "init" method. The base class just needs to store a parameter into a field. Deriving classes want to do actual setup work in there.

leaden ice
#

Yeah that should fit with the pattern

heady iris
#

(if only i could do this in a constructor)

thick socket
#

boxcast2d

#

when doing that it starts with a point

#

is that point the middle of the box

#

or the topleft?

heady iris
#

I'd expect so.

thick socket
#

or top-middle?

heady iris
#

The first argument is called center

#

wait, that's 3D physics

thick socket
#

yeah 3d version is nice

#

the 2d is confusing 😄

heady iris
#

origin is more ambiguous

thick socket
#

The point in 2D space where the box originates.

#

just as bad lol

heady iris
#

It would be very awkward if it wasn't the center.

leaden ice
#

It's the center

thick socket
#

if its the center?

leaden ice
heady iris
#

that's the direction the box flies in

leaden ice
#

a "cast" is like throwing the box through the scene

thick socket
#

interesting

leaden ice
#

(in a straight line)

heady iris
#

It's not like you're doing a box-select

thick socket
#

I though raycast just drew the line from start->fin and its the same for boxcast

heady iris
#

where you draw a big rectangle enclosing the start and end points

leaden ice
#

note the difference between this and OverlapBox/CHeckBox which just checks a single box shaped area in the scne

heady iris
#

it moves the box's center from start to end

leaden ice
heady iris
thick socket
#

and by box it means a square?

leaden ice
#

no

#

rectangle

#

dimensions are determined by Vector2 size

heady iris
#

RayCast sweeps a 0D object (a point) through the scene
LineCast sweeps a 1D object (a line) through the scene
BoxCast sweeps a 2D object (a rectangle) through the scene

leaden ice
heady iris
#

oh, it's Linecast, not LineCast

#

dies

#

oh dammit I got that mixed up again

#

It's so plausible sounding

#

I don't actually do 2D, see... idontfeelsogood

leaden ice
#

the only difference between linecast and raycast is whether the second param is a direction vs a position

thick socket
#

if I just want to determine if Im standing on a platform

#

is boxcast the way to go?

heady iris
#

Casts a line segment against Colliders in the Scene.

leaden ice
#

it's a way to go

heady iris
#

It sounds right, too!

thick socket
#

would require multiple raycasts so thought boxcast might be better

heady iris
#

I'll get this right eventually

thick socket
#

from what I've found is the way you recommend is typically better than what I think would work best lol

#

would you just do 2 raycasts "down" at the "edge" of feet?

leaden ice
thick socket
#

was originally just doing a collider...but that doesn't seem to be working great because of ontrigger enter/exit

leaden ice
#

boxcast is generally pretty good

thick socket
#

so boxcast is like sending a box through space down

leaden ice
#

in whatever direction you specify

thick socket
#

would a "linecast" where I draw a line thats the length of the feet

#

be better to "send down"

leaden ice
#

linecast is the same as raycast

#

it's just a different way to provide the parameters

heady iris
#

yeah, it's not actually sweeping a line. I was mistaken.

thick socket
#

for boxcast I understand choosing the "length" to be the size you want to collide

leaden ice
#

e.g. "i want to cast a ray from point A in direction D with a length of L" is a raycast
For a linecast it's
"I want to cast a ray from point A to point B"

heady iris
#

(that sounds really useful, though)

thick socket
#

how do you want to pick the "height" of the box though?

leaden ice
thick socket
#

I mean for the "size" of the box

leaden ice
thick socket
#

length x height box size and then send it down a little to see if grounded

#

so like I might want 2 length, 0.00001 height and send it down 0.2 to see if it hits ground

heady iris
#

BoxCast has:

origin: where the box's center starts
size: the width and height of the box
angle: the rotation of the box
direction: which way the box moves
distance: how far the box travels in that directions

thick socket
#

yep, Im confused on the height of the box

#

since it moves in distance

heady iris
#

size is the only thing that decides how big the box is

#

you still sound confused by what the boxcast is actually doing

rigid island
heady iris
#

Here is what a box cast looks like.

#

It sweeps that rectangle between two points.

thick socket
#

makes sense for 3d

heady iris
#

size determines how big the rectangle is

thick socket
#

for like 2d

rigid island
#

are you doing a platformer?

#

boxcast is pretty good

#

or checkbox

thick socket
#

dont see how this would be any different

#

aka why the height matters

heady iris
#

I'm not sure how this works in 2D. In 3D, casts with volume (e.g. SphereCast) will ignore colliders they start inside of

#

That's the main thing that comes to mind.

thick socket
#

regular rectangle vs simple compact rectangle

leaden ice
# thick socket

A couple reasons:

  • if you move it in a diagonal, or with a rotated box, the box corners make a difference.
  • 2D casts can hit things at the start of the cast.
thick socket
#

but hadn't thought about the first part

#

figured that wouldn't change much vs just rotating your "line"

thick socket
#

is using that as a trigger vs checkbox much different?

#

might just use boxcollider2d still and iterate through all the "contacts" instead of "ontrigger"

leaden ice
#

with a trigger collider and OnTriggerEnter2D you have to wait until the physics callback

#

you also don't get any contacts

#

physics queries can be used immediately

thick socket
#

👍

rigid island
#

var grounded = Physics2D.OverlapBox(groundedCheckCenter.position, groundedBox.size, 0, ~ignoredGroundedLayers);

thick socket
rigid island
#

dont mind, i use overlapbox

#

but works same

rigid island
thick socket
#

tbf its all I need so it works nicely also

#

~ignoredGroundedLayers whats this mean? never seen ~ used before

rigid island
#

it ignores that layer

thick socket
#

ah cool...why ignore a layer vs find only the ones you want?

thick socket
rigid island
#

idk if it would throw nre

#

havent touched this project in ages(it was for jam so was non-issue optimizing wise) 😅

thick socket
#

Im seeing "Collider2D" doesn't have a .size

rigid island
#

you need box because different colliders have diff props

#

like circle has no size

#

but radius

thick socket
#

maybe I shouldn't be using a capsuleCollider lol

rigid island
thick socket
#

cause the size might be slightly different using OverlapBox and a capsulecollider as the thing that shows size 😄

rigid island
#

not sure why its shaking in scene view sry

thick socket
rigid island
#

a circle would probably fit a capsule bottom better but box was sufficent for me

thick socket
rigid island
#

as long as its referenced iirc you can still use disabled component props ig not 100 on it

#

the checkmark only disables the unity events iirc

thick socket
#

you sadly can't see it in the debug screen if its disabled

#

guess I'll disable in code lol

rigid island
#

draw a gizmos to view my box

#
   private void OnDrawGizmos()
    {
        if(!Application.isPlaying) return;
        Gizmos.color = IsGrounded() ? Color.green : Color.red;
        Gizmos.DrawCube(groundedCheckCenter.position, groundedBox.size);
    }```
thick socket
rigid island
#

yeah i used the gizmo only for debugging visually if my Grounded worked

rigid island
# thick socket

collider looks fine, althought your .right seems to be off, unless you're in world pivot mode

thick socket
#

collider should be centered...it wasn't before lol

#

but only because its not on a child that gets flipped

rigid island
#

😅 that too

thick socket
#

darn

#

still doesn't work after "fixing" that lol

#

what did I break now 😄

rigid island
thick socket
#

I should be "bouncing" off this wall with raycast

#

and its not 😄

rigid island
thick socket
#

moving too fast and missed the collider I guess lol

heady iris
#

i have no idea what's going on in this image

thick socket
#

its a photo of you Fen 😄

#

basically raycast in front so right before they hit a wall they switch direction and run other way

rigid island
#

and which part isn't working

thick socket
#

and a raycast down so if they are about to "fall" off a platform they dont

heady iris
#

is that short red horizontal line the raycast?

#

it looks like it's starting inside the wall

thick socket
thick socket
#

should have been moved back a little so if it "misses" the wall first time around it will hit even when collider is against wall(the nose/wolf is running into wall)

thick socket
rigid island
#

why not Update?

#

make it more accurate

thick socket
#

figured bad performance and no real differnce other than switching frames a few frames earlier

rigid island
#

makes a pretty big difference trust. also raycasts are pretty cheap, you'll be fine

heady iris
#

well, it turns out the "real difference" is that your game breaks...

rigid island
#

what if something not static jumps infront of it

#

it will intersect stuff and seem poor reaction, probably not good Ux

thick socket
rigid island
#

you don't have moving obstacles or doors that open/close ?

thick socket
#

granted yeah its only a few fps differnet running each frame vs 30fps

#

so might as well use it max fps

rigid island
#

you should see the 14 raycast my ML Agent had 😅

#

and still didn't feel enough

thick socket
spring creek
#

If you're gonna go with every other fixedupdate, at least make the raycast longer

thick socket
#

so many raycasts now lol

spring creek
#

I had hundreds of objects with 3 raycasts and it was fine

But that was a test and not much else going on!

rigid island
thick socket
thick socket
rigid island
#

looks like barcode scanner

thick socket
#

yep lol

#

just changed a ton of colliders to raycasts

#

wish that was something I knew I should be using earlier

#

surprised none of the youtube videos used them when I was first learning

#

moved almost everything over except my bullets

#

not totally sure how to calculate how far forward my raycast should be so I dont miss a collision while also making sure it blows up in the right location

#

since my bullets aren't slow but aren't super speed

craggy crest
#

I don't know if it is the right place to ask the question so sorry beforehands 😅

thick socket
craggy crest
#

Ok, I will post it there 🙂