#💻┃code-beginner

1 messages · Page 394 of 1

carmine sierra
#

alr ill rewatch the vid

swift crag
#

no, you'll stop what you're doing and use !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

silver flicker
#

hey quick question - how would I go about using loops like a for loop to iterate raycasts at varying angles. For example, this red line represents the ray cast. I would like to duplicate this every 15 degrees around the entire circle

swift crag
#

I'd use Quaternion.AngleAxis to calculate a rotation

#
Quaternion.AngleAxis(angle, vector3.forward) * Vector3.right;
#

This will spin the right vector by angle

silver flicker
#

Ok

swift crag
#

You can calculate angle based on your for loop's variable

silver flicker
#

I'll research that a bit

carmine sierra
swift crag
carmine sierra
#

true

#

ill come back then when i secure most of that down

swift crag
#

it is better to get a foundation from a single coherent source before you try to start learning things on the fly

carmine sierra
#

boxfriends a hater though damn

#

yh you right

silver flicker
naive pawn
carmine sierra
#

more general question, since unity has alot of built in features which arent c# exclusive, is it a good idea to use making games on unity as a means to progress into software engineering?

naive pawn
#

doing is a supplement to reading, not a replacement

swift crag
#

wait, that doesn't exist lol

#

i'm thinking of the shader graph node

silver flicker
#

lol

naive pawn
silver flicker
#

too much knowledge

swift crag
#
float progress = Mathf.InverseLerp(0, raycastCount, i);
float angle = Mathf.Lerp(0, 360, progress);
#

That's basically what a remap does

rich adder
silver flicker
#

i see ok

carmine sierra
#

like all the methods aand components you need to understand

naive pawn
rich adder
#

thats what the manual is for

naive pawn
#

but the concepts will take you much further

summer stump
carmine sierra
#

yeah but i feel like the concepts are what take up much less time to learn

naive pawn
#

you haven't learnt either at this point

#

you need to learn both together

#

if you just learn the concepts, you can't apply that to actual code

carmine sierra
#

ive learned a bit of c#

rich adder
#

a bit is not enough

naive pawn
#

if you learn just the specifics for unity, you can never adapt and improve and apply that knowledge to other scenarios

#

you need both

naive pawn
rich adder
#

learning c# without any big frameworks is the best service you will do to yourself, everything else will make way more sense

carmine sierra
#

just unity stuff

rich adder
#

I can name 3 just by looking at your posts lol

naive pawn
#

haven't you been asking about c# stuff this entire time

carmine sierra
#

i dont think so

#

just unity methods i dont understaand

summer stump
#

The "unity things" you had issues with were actually c# issues

naive pawn
#

any question about scripting in unity is a question about coding, and unity uses c# for its textual scripting

summer stump
#

Understanding c# would have made you able to resolve them

sonic dome
#

why is this my moment now working properly?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move : MonoBehaviour
{
    public Animator body;
    private Rigidbody2D rb;
    private SpriteRenderer sr;
    public float speed;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        sr = GetComponent<SpriteRenderer>();
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)){
            rb.velocity = Vector2.right * speed;
            sr.flipX = true;
            body.SetBool("Walk",true);
        }
        if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)){
            rb.velocity = -Vector2.right * speed;
            sr.flipX = false;
            body.SetBool("Walk",true);
        }
        if(rb.velocity == new Vector2(0,0)){
            body.SetBool("Walk",false);
        }
    }
}

this is the code

carmine sierra
#

could you tell me please cause then i can go to learn c#

summer stump
naive pawn
#

your problems are not unity-specific

carmine sierra
naive pawn
#

you don't have the fundamental skills for programming, yet
go get them

carmine sierra
#

if that makes sense

swift crag
#

well, you also have problems with understanding how positions and directions work

rich adder
swift crag
#

the documentation talks about these

carmine sierra
#

thing is it?

#

c#

naive pawn
summer stump
#

It is a math thing

naive pawn
carmine sierra
summer stump
#

Basic logic that applies to all programming

carmine sierra
#

direction vs vector?

naive pawn
rich adder
#

knowing c# wont magically teach you about vector3s but you will understand how to use in the code once you do..

swift crag
#

you currently don't know what you don't know

carmine sierra
#

alr if everyone thinks so ill do thaat

summer stump
#

Yes, knowing vector mathematics is not unique to c# or unity or even programming

carmine sierra
#

but should i do that before even movving to the unity learn course

summer stump
#

But it IS very common in programming (especially game dev) of course

sonic dome
#

🥹 i got burried

rich adder
summer stump
carmine sierra
#

creaate with code

carmine sierra
#

okay thanks

rich adder
summer stump
#

This is pinned in my clipboard haha

rich adder
#

they should pin the w3schools one here its decent

sonic dome
sonic dome
summer stump
summer stump
#

Try not using a box, instead a capsule

naive pawn
sonic dome
rich adder
#

are you using tilemap ?

#

try also using a composite collider on it
oh dang my discord just updated lol 🦥

silver flicker
#

Hello again, im trying to iterate raycasts at intervals of 15 degrees around a circle, but this code doesn't seem to work,

sonic dome
silver flicker
#

how do you paste small blocks of code in the code format

naive pawn
#

!code

eternal falconBOT
silver flicker
#
        {
            RaycastHit2D hit = Physics2D.Raycast(transform.position, new Vector3(0, 0, i*15), distance, includedLayers);
            Debug.DrawRay(transform.position, new Vector3(0, 0, i * 15) * distance, Color.red);
        } ```
#

Thats it

rich adder
silver flicker
#

im trying to iterate raycasts at intervals of 15 degrees around a circle, but this code doesn't seem to work

#

oh ok

naive pawn
silver flicker
#

I was wondering about that, how do you translate that to rotation?

naive pawn
#

you aren't rotating anything there

naive pawn
#

then you could rotate that or use trig

silver flicker
#

Ok, I'll look up some more stuff. Thanks

naive pawn
#

just use trig

#

cos = x, sin = y

silver flicker
#

thats what I was looking up lol

naive pawn
#

keep in mind they use radians

rich adder
#

you could do

   for (int i = 0; i < 360; i += degreeIncrement)
   {
       float angle = i * Mathf.Deg2Rad;
       Vector2 direction = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
       Debug.DrawRay(transform.position, direction * radius, Color.green);

   }```
#

I think

silver flicker
#

I think Ive used some method like rad2deg or something

#

that'd be the method

#

Ok, I think I understand that

#

Math time, thanks guys

naive pawn
#

also note that this starts at the right and goes counterclockwise (like polar coords)

#

if you need it to do something else then you have to apply an offset or a factor

silver flicker
#

Ok, any orientation should work

little forge
#

how does terrain pixel error work

#

if you get from 5 to 15, you won't rly notice the difference, but the triangle amount will go down ALOT

#

but as you increase it to like 25-30, terrain becomes less curvry but only far from player

#

and as you set it to 200, the entire terrain turns low-poly

eternal needle
#

Could construct the quaternion with Quaternion.Euler then apply that to the current direction vector

naive pawn
#

that was what i was thinking of

#

but yes quaternions are a thing im aware i just don't know how to use them lol

swift crag
#

so it is a vector that points forward

swift crag
naive pawn
swift crag
#

ah, fair enough

summer stump
naive pawn
#

noooo im not ready

summer stump
#

Ah, that was how it was explained to me. I dunno I guess

swift crag
#

consider this 90 degree rotation I made in Blender, followed by another 90 degree rotation (both around the Z axes)

swift crag
naive pawn
#

oh what the hell....

swift crag
#

fortunately, quaternion math is completely irrelevant here

#

it should have just been called Rotation

summer stump
#

So, x, y, z are colinear with the axis of rotation; w describes how much rotation around that axis in a non-linear fashion. The constraint here is that the total has to have a 4d length of 1, so as the amount of rotation changes, the length of x, y, z have to change inversely.

Yeah, I simplified what I was told incorrectly

#

And misremembered. This was from a while ago

magic panther
swift crag
timid oriole
#

When creating a scriptable object do you guys use enums?

magic panther
slender nymph
swift crag
#

line 44 is particularly bogus

#
Vector3 worldCenterPoint = transform.TransformPoint(centerPoint);

centerPoint is a world-space position, since it uses firePoint.position.y

magic panther
#

yeah, that's the chatgpt code

swift crag
#

so throw all of that hallucinated code out and just do...

#
Vector3 origin = firePoint.transform.position;
Vector3 dir = firePoint.forward;
magic panther
#

what do we turn this to to make it work

little forge
swift crag
#

Make sure that your firePoint transform is rotated properly.

magic panther
#

also I'm guessing I delete centerpoint?

timid oriole
willow scroll
swift crag
#

It looks like this code is trying to figure out a "forward" direction without actually using the rotation of firePoint

#

by instead using worldFirePoint - worldCenterPoint

#

this is completely unnecessary

slender nymph
magic panther
#

this is where firepoint is

#

inside the gun, so it has a tiny offset from 0,0,0

timid oriole
magic panther
#

I'm guessing .forward since the gun is aimed in the Z direction from the start

#

but what about the rotation

slender nymph
willow scroll
magic panther
#

rotate by gun rotation and we're good?

timid oriole
#

Just junk?

little forge
#

if you have a firepoint, you can do this then

int maxRayDistance = 150; // 150 unity units
if (!Physics.Raycast(firePoint.transform.position, gun.transform.forward, out RaycastHit hit, maxRayDistance)) return;
Debug.Log(hit.collider.gameObject.name);```
slender nymph
timid oriole
#

I will

willow scroll
summer stump
magic panther
#

I just need a raycast forwards of firepoint relative to the gun that logs the first thing it detects

timid oriole
#

🔴 Learn why you should NOT use Strings https://www.youtube.com/watch?v=0_UiF-4-7xM
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
Quick Tips Playlist: https://www.youtube.com/playlist?list=PLzDRvYVwl53vjCLV83wb7ZF2mYNLC_wQZ
Always use Enums for State handling inst...

▶ Play video
#

he implies it is bad practice to use strings

slender nymph
# timid oriole I will

i'm calling it now before i watch the video that the tutorial was actually telling you to use an enum because it was the most appropriate data type for the information you are trying to store as a variable and had literally nothing at all to do with the variable being on a scriptable object

swift crag
#

notably, he's not writing a ScriptableObject here

little forge
swift crag
#

he's demonstrating that you should use enums, not string constants

timid oriole
willow scroll
swift crag
magic panther
#

it says cube

little forge
swift crag
#

It's going to rain tomorrow. What color are my pants?

timid oriole
#

it was the video I was watching before to get an understanding of what enums were in the first place

little forge
#

which might be above or sideways from guns position

naive pawn
magic panther
#

because it's inside it, right?

swift crag
#

close: shorts

slender nymph
naive pawn
swift crag
#

please show us the actual video, not another unrelated video that doesn't say what you said it did

little forge
#

don't forget that raycast won't return the collider which is bounding the start point

swift crag
#

yeah, a 3D raycast will ignore those

magic panther
little forge
#

so if you start shooting from inside a cube, cube will be ignored

magic panther
willow scroll
slender nymph
magic panther
eager spindle
#

cant you just get a list of raycasted objects and also check which objet the gun is colliding with

remote osprey
#

Hello, everyone

magic panther
#

eliminating the ability to fire from inside or very close to walls

magic panther
eager spindle
eager spindle
#

to enforce the start collision

magic panther
#

like, for the raycast to recognize the start collision instead of omitting it

rocky canyon
#

u said the same thing twice

remote osprey
#

If I create an instance using a prefab, does that mean that two instances of this prefab will have the same identity as each other?

magic panther
willow scroll
swift crag
#

I need to go test that carefully.

remote osprey
#

Thank goodness!

#

Thanks for the reply!

eager spindle
swift crag
slender nymph
magic panther
#

btw @little forge what's the return for? Won't this cancel the update function?

eager spindle
#

so do you want the object inside the gun to be omitted?

#

or do you want the object inside the gun to stop the gun

magic panther
rocky canyon
magic panther
#

I'd like it to recognize that

timid oriole
#

I can't find the video anymore damn

rocky canyon
#

!Physics.Raycast

timid oriole
#

It was a codemonkey tutorial I was following though but thats besides the point I guess if it doesn't make sense it doesn't make sense

#

And anthestiosity mentioned codeMonkey is bad why is that?

#

If brackeys is bad and code monkey is bad that's like 90% of the tutorials

eager spindle
rocky canyon
#

he's not necessarily bad.. he writes in a really condensed complex way.. doesn't explain some basic things he assumes u would know..

willow scroll
# remote osprey Thank goodness!

When you have a class, which your prefab is, simply assigning another class to it will make them both have the same reference

yourObject = yourPrefab;
yourObject == yourPrefab; // true

When you simply instantiate a prefab, it will create its instance, and removing the instance won't do anything to the prefab

yourObject = Instantiate(yourPrefab);
yourObject == yourPrefab; // false

Destroy(yourObject);
// yourPrefab is fine
rocky canyon
#

and plugs a utility library that he uses all the time

magic panther
slender nymph
magic panther
#

except from the library part, yeah

summer stump
#

Code Monkey is bad for BEGINNERS imo

timid oriole
eager spindle
timid oriole
#

fucking annoying

eager spindle
#

executing third party code on your pc while not knowing how they got started

summer stump
#

He has OK code for intermediate and "advanced"

eager spindle
#

im making a tutorial series right now for C#, Raylib and Unity

#

no libraries other than in the base

remote osprey
timid oriole
eager spindle
rocky canyon
#

cool.

eager spindle
#

ill publish the full thing

#

its a bucket list thing

#

right now im making like 2 projects simultaneously so im gonna perish

remote osprey
#

Please do'nt perish just yet

#

You got 2 projects to finish!

summer stump
#

Learn.unity is always gonna be the best place to start, and codemonkey, brackeys, and others have clickbait channels that generally give bad practices to just get out content. Which is pushed by youtube itself of course

magic panther
willow scroll
eager spindle
#

you're using raycast right now right?

remote osprey
rocky canyon
eager spindle
#

RaycastAll returns all the objects that are hit by the line, not just one

#

very fun stuff

#

so take the first object in this array returned by RaycastAll

timid oriole
eager spindle
#

I plan to teach unity basics then do guided projects

rocky canyon
#

it does plenty to make u learn the processes

eager spindle
#

for art assets ill prob plug kenney all in one assets

magic panther
rocky canyon
#

once u get the basics its up to you to research specific topics

timid oriole
#

I mean what do we define as basics though?

eager spindle
rocky canyon
timid oriole
rocky canyon
#

once you learn that.. no not really

#

but im not saying don't finish em

#

b/c its structured in a way to work ur way up

magic panther
rocky canyon
#

i never even did the learn route.. wish i had of

timid oriole
#

so how did you learn

summer stump
rocky canyon
#

self taught.. and reverse engineering assets

eager spindle
# timid oriole I mean what do we define as basics though?
  • c#, if/else, while, for, switch, classes and OOP, interfaces, preferably worked on other coding projects
  • know how to use the editor(right click to move around, right click + wasdeq to move)
  • know how to create gameobjects
  • know how to move around game objects in the scene
  • the concept of parenting gameobjects in the scene
  • what a transform is
  • what a component is
  • attaching components to a gameobject
  • how to make your own components
  • how to use SerializeField and link your components together
  • abusing static variables and making singletons
rocky canyon
timid oriole
#

I know everything there besides static and singletones and interfaces

rocky canyon
#

once you know how to search the internet.. and u know how to write code.. and read errors ur golden

magic panther
rocky canyon
#

i find it hard to do stuff like state machines and behavioural trees

#

but everything else. is pretty simplified.. u dont have to write pretty code.. just code that works tbh

#

unless ur working in a team.. then write prettty code

summer stump
#

Singletons are usually not recommended in non-game dev, at least not much, but they are very common and useful in games, especially in engines which consume Main

willow scroll
timid oriole
#

damn I should learn then

rocky canyon
#

yes

#

u should 🙂

summer stump
#

Yes, you should

eager spindle
# timid oriole I know everything there besides static and singletones and interfaces

you are in a good direction

class GameManager {
public static bool canMove;
public static GameManager instance;

void StartGame() {
  instance = this
}
}

...
class PlayerController {

  void Update() {
    if(GameManager.canMove) ...
  }

}

first variable in GameManager is canMove. you dont actually need to make a GameManager to use canMove. you can get it from the class name.

#

very fun stuff

lone hamlet
#

how to create an ocean using code (with high vfx)

eager spindle
#

then if you do decide to make a GameManager you dont have to use serializefield

magic panther
eager spindle
swift crag
eager spindle
#

looks correct

#

your object might not have a collider

#

or might not be the exact same collider

timid oriole
magic panther
#

you mean the gun or the firePoint

summer stump
swift crag
magic panther
#

the gun has no collider so it doesn't break the player and all the other things

eager spindle
eager spindle
#

they still need to be public but you dont need to getcomponent or serializefield

#

its because its public static

#

public static GameManager instance lets me use GameManager.instance without a serializefield

swift crag
#

you are mixing some important concepts up here...

willow scroll
lone hamlet
rocky canyon
#

TheClass.instance.Function();

timid oriole
swift crag
rocky canyon
#

GameManager.instance.canMove == true;

swift crag
#

It's true that this means you don't need to be given a reference to a GameManager

summer stump
summer stump
#

You are accessing the type via a static VARIABLE

magic panther
#

also just a general question, because this applies to web development, but will I get good at C# by just making different stuff every day?

timid oriole
eager spindle
summer stump
eager spindle
#

like making a skibidi toilet fan game

swift crag
#

get well soon 🙏

willow scroll
timid oriole
#

brain fart

magic panther
magic panther
eager spindle
summer stump
rocky canyon
#

erm, it depends on your routine. and what ur chosing to learn.. when

#

i can't say.. its different for everyone

old rivet
#

Anyone here who can help me with object pooling?

magic panther
eager spindle
# magic panther how do we change better to good

when you work in the game industry you'll join a lot of companies with their own solutions for things, or you might even make your own solution yourself.
by solution it could mean making your own engine or unity extension

#

this is how people go from better to good

magic panther
eager spindle
#

because it challenges what you've learned and makes you google a lot of stuff

#

a lot more than just staying indie

#

I learned how to make unity extensions and unity GUI because Ineeded some stuff automated for my team

rocky canyon
timid oriole
#

What exactly is static is a method static or a class? What does that even do exactly?

queen adder
#

hello would anyone be able to help me out with coding i am fairly new :3

old rivet
#

Ok so
I'm making a simple space game
Where 3 sizes of asteroid spawn
And when player shoot them
Larger one split into medium
While medium into small
And small one destroy

I'm destroying when using destroy(gameobject); but I heard game pooling is way better for massive spawn and despawn

So I'm wondering how I will able to achieve it

I can send my asteroid and asteroid manageer script (spawn asteroid randomly) here

magic panther
queen adder
#

3d

#

where u can like fly fighter jets

#

fight others

#

yk

eager spindle
rocky canyon
#

please make coherent and full sentences

eager spindle
#

once that happens, when the asteroid gets shot, instantiate two more objects.

languid spire
eager spindle
magic panther
timid oriole
slender nymph
#

there are beginner c# courses pinned in this channel. start there if you do not understand how the language works

old rivet
willow scroll
summer stump
queen adder
languid spire
timid oriole
#

My brother knows C & JAva would he be able help me or is c# to different

naive pawn
#

static in class and static in members is slightly different;
a static class can only hold static members, that's all it does
static on members actually has an affect
a static member is accessed through the class directly rather than through an instance

little forge
willow scroll
timid oriole
naive pawn
swift crag
old rivet
willow scroll
swift crag
little forge
eager spindle
# timid oriole this line here "Use the static modifier to declare a static member, which belong...

doing it without static

public class GameManager {
  public bool canMove;
}

public class Enemy {
  [SerializeField] GameManager manager; // drag gamemanager here!
  public void Start() {
    if(manager.canMove) ...
  }
}

doing it with static

public class GameManager {
  public static GameManager instance;
  void Start() {
    GameManager.instance = this;
  }
}

public class Player {
  void Start() {
    if(GameManager.instance.canMove) ...
  }
}

static variables explanation. GameManager has a static variable called instance, which keeps track of the one and only GameManager. the static variable instance is not depending on anything, so you dont need to create a GameManager to access instance.
lets say you have 100 players in the game. its not good practice to drag Gamemanager into every player if it were a serializefield, so you can use a static variable

timid oriole
eager spindle
#

apologies for big block

eager spindle
swift crag
#

If you don't know any of the words you're going to have a miserable time of it

#

that's what Unity Learn is there for

willow scroll
eager spindle
little forge
#

he means you can't add non-static methods or variables into a static class ig

eager spindle
#

which will get you a lot of practice

naive pawn
old rivet
#

@eager spindle ```cs
using UnityEngine;

public class Asteroid : MonoBehaviour
{
public float minSpeed = 1f;
public float maxSpeed = 3f;
public GameObject mediumAsteroidPrefab;
public GameObject smallAsteroidPrefab;
private Rigidbody2D rb;
private ScoreManager scoreManager;
void Start()
{
rb = GetComponent<Rigidbody2D>();
float speed = Random.Range(minSpeed, maxSpeed);
float angle = Random.Range(0f, 360f);
Vector2 direction = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
rb.velocity = direction * speed;
scoreManager = GameObject.FindObjectOfType<ScoreManager>();
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Bullet"))
{
if (gameObject.CompareTag("LargeAsteroid"))
{
SplitAsteroid(mediumAsteroidPrefab);
}
else if (gameObject.CompareTag("MediumAsteroid"))
{
SplitAsteroid(smallAsteroidPrefab);
}
Destroy(collision.gameObject); // Destroy the bullet
Destroy(gameObject); // Destroy the current asteroid
}
else if (collision.gameObject.CompareTag("SmallAsteroid")) // Check if collided with a SmallAsteroid
{
// Update the score using the ScoreManager only when a SmallAsteroid is destroyed
scoreManager.UpdateScore(10); // Add 10 points for destroying a SmallAsteroid
Destroy(gameObject);
}
}

void SplitAsteroid(GameObject smallerAsteroidPrefab)
{
    for (int i = 0; i < 2; i++)
    {
        GameObject newAsteroid = Instantiate(smallerAsteroidPrefab, transform.position, transform.rotation);
        Rigidbody2D asteroidRb = newAsteroid.GetComponent<Rigidbody2D>();
        asteroidRb.velocity = Random.insideUnitCircle * Random.Range(minSpeed, maxSpeed);
    }
}

}

swift crag
# willow scroll Not quire sure what you mean

When you add static to a member, you're fundamentally changing how you can access the member. It lets you access the member from the type itself, instead of from an instance.

When you add static to a type, you're not adding any new capabilities to it. You're just saying "no instances may be created".

eager spindle
naive pawn
swift crag
#

bingo

old rivet
languid spire
eternal falconBOT
naive pawn
willow scroll
naive pawn
#

this server is open 24/7, im sure you aren't

eager spindle
#

i got this

timid oriole
#

I'm off to practice c# thank you everybody for the help it seems all my issues stem from my lack of understanding from the fundamentals I'll be back with more questions once I get those out of the way so my questions are more unity specific rather than coding

naive pawn
#

aight, your responsibility then

naive pawn
willow scroll
old rivet
summer stump
eternal falconBOT
summer stump
eager spindle
summer stump
#

Especially the large code blocks section

summer stump
eager spindle
#

here's a backtick to get started `

summer stump
#

They need to use the large codeblocks part

eager spindle
#

not to be confused with the apostrophe '

languid spire
old rivet
#
using UnityEngine;

public class Asteroid : MonoBehaviour
{
    public float minSpeed = 1f;
    public float maxSpeed = 3f;
    public GameObject mediumAsteroidPrefab;
    public GameObject smallAsteroidPrefab; 
    private Rigidbody2D rb;
    private ScoreManager scoreManager;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        float speed = Random.Range(minSpeed, maxSpeed);
        float angle = Random.Range(0f, 360f);
        Vector2 direction = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
        rb.velocity = direction * speed;
        scoreManager = GameObject.FindObjectOfType<ScoreManager>();
    }
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Bullet"))
        {
            if (gameObject.CompareTag("LargeAsteroid"))
            {
                SplitAsteroid(mediumAsteroidPrefab);
            }
            else if (gameObject.CompareTag("MediumAsteroid"))
            {
                SplitAsteroid(smallAsteroidPrefab);
            }
            Destroy(collision.gameObject); // Destroy the bullet
            Destroy(gameObject); // Destroy the current asteroid
        }
        else if (collision.gameObject.CompareTag("SmallAsteroid")) // Check if collided with a SmallAsteroid
        {
            // Update the score using the ScoreManager only when a SmallAsteroid is destroyed
            scoreManager.UpdateScore(10); // Add 10 points for destroying a SmallAsteroid
            Destroy(gameObject);
        }
    }

    void SplitAsteroid(GameObject smallerAsteroidPrefab)
    {
        for (int i = 0; i < 2; i++)
        {
            GameObject newAsteroid = Instantiate(smallerAsteroidPrefab, transform.position, transform.rotation);
            Rigidbody2D asteroidRb = newAsteroid.GetComponent<Rigidbody2D>();
            asteroidRb.velocity = Random.insideUnitCircle * Random.Range(minSpeed, maxSpeed);
        }
    }
}```
summer stump
#

Do not do cod- op. NO, use a paste site

willow scroll
eager spindle
#

you can upload a message.txt

#

not a site

naive pawn
eager spindle
#

site is sus

languid spire
summer stump
#

No, absolutely do not do .txt

eager spindle
#

oh y'all do it the other way round here?

#

on desktop you can expand the message

summer stump
#

It is the rules of the server

naive pawn
summer stump
#

Mobile need to download it for one

naive pawn
willow scroll
summer stump
#

But it still requires download on mobile.

#

There is a reason paste sites are the rule

eager spindle
#

make a screenshot of the code A_BigBrainTao

willow scroll
summer stump
#

!screenshots

eternal falconBOT
#

mad No

Be mindful, if someone requests your code as text, don't send a screenshot!

willow scroll
slender nymph
languid spire
summer stump
eager spindle
#

personally im not fond of paste sites especially now when you can fake links

summer stump
old rivet
summer stump
willow scroll
summer stump
#

Use a paste site, as you were told a bunch of times

#

!code

eternal falconBOT
naive pawn
summer stump
eager spindle
#

very dumb that people are falling to those in 2024

naive pawn
summer stump
slender nymph
fickle plume
#

@eager spindle Stop derailing the conversation.

eager spindle
#

is the asteroid not splitting

willow scroll
naive pawn
#

isn't that all sites (user-agent http header)

summer stump
old rivet
willow scroll
summer stump
#

Yes 🎉

old rivet
summer stump
#

Ok, I don't see any object pooling happening.
What did you try so far?

#

Have you looked into the ObjectPool type that unity provides?

eager spindle
#

for object pooling you'll need an array of gameObjects first.
GameObject[] largeAsteroidPool = new GameObject[10]

under start, set all elements of the largeAsteroidPool to a new large asteroid. set this asteroid to be inactive.
when you need an asteroid, set the asteroid to be active and set the position of the asteroid. when you dont need the asteroid, set it to be inactive.

languid spire
old rivet
#

i mean i know problem i face is when , 2 medium asteroid spawn from large asteroid destruction

naive pawn
eager spindle
#

to do this for the small and medium asteroid pool make 2 other arrays

eager spindle
#

ok so small problem this is a List

#

i guess you can use a list

old rivet
eager spindle
#

but dont add or remove from this list

#

or itll defeat the purpose of an object pool

slender nymph
#

why not use unity's built in object pooling class?

naive pawn
eager spindle
summer stump
eager spindle
#

and choose a good starting number so it doesnt change too often

languid spire
eager spindle
#

personally I havent used it before, unity's object pooling system

naive pawn
slender nymph
naive pawn
old rivet
#

i m on version 2021.3.29

naive pawn
#

going into a community support server to find a personal tutor just nullifies the benefit of asking in a community to begin with

old rivet
#

i have these 3 scripsts to change to succesfully apply object pooling i will share

languid spire
eager spindle
#

teaching the user the basics of object pooling rather than just directing them straight to the library

naive pawn
#

basics ≠ internals

languid spire
#

but you said yourself you've never used it so how much do you expect to teach?

eager spindle
#

im talking about making a normal object pool rather than using unity's internal object pool

naive pawn
#

teaching to implement isn't the same as teaching to utilize

slender nymph
eager spindle
#

up to them

#

i havent had the need to expand my object pool before

#

just choose a good fixed number at the start

slender nymph
#

if you want to make a proper object pool, you'd be using a queue not an array anyway 🤷‍♂️

old rivet
eager spindle
#

not very fun for them

elder osprey
#

How would I make it to where multiple scripts can reference the same instance of a script across scenes? I have a settings menu in the main scene of my game, each slider and toggle has its own script that handles its functionality. Currently I am trying to make a main menu, and my idea for applying the settings across scenes is to use a script which holds the values of each of the settings. I am unsure of how to make a single instance of the script accessible across different scripts.

eager spindle
old rivet
#

😦😔

elder osprey
#

for example

modest dust
slender nymph
languid spire
slender nymph
naive pawn
elder osprey
slender nymph
#

there is no "instance" because the class is static

#

a static class can only contain static members

languid spire
naive pawn
eager spindle
#

this is a static class

eternal needle
eager spindle
old rivet
naive pawn
#

changes to achieve what

eager spindle
#

commit to where, the repository?

#

what do you want to achieve

elder osprey
eternal needle
#

You'll get much better responses if you actually can ask something.

languid spire
eager spindle
#

the ms docs use a lot of terms unfamiliar to new programmers, while it is correct it doesnt teach beginners

naive pawn
eager spindle
#

I understand the docs now but not 4 years ago when I started unity and programming

old rivet
#

why istead of using the pool its creating new objects?

naive pawn
eager spindle
elder osprey
# naive pawn *by name*

Previously, I was unaware of what the static modifier did, I understand now. I have understood since uldynia provided an example.

naive pawn
#

static on a class doesn't really change anything

eager spindle
naive pawn
eager spindle
naive pawn
eager spindle
#

yea it only affects your teams who want to inherit the class

willow scroll
eager spindle
#

im willing to do that

old rivet
eager spindle
#
public static class Settings {
  public static int volume
}
public class Settings {
  public static int volume
}

are the exact same thing. however,

public static class Settings {
  public int volume
}

is invalid because you try to put a variable that's not static, into a class that is static

summer stump
eager spindle
#

most of my work is indie so i dont bother making static classes, only static variables
but if you want to force someone to only use static variables then go ahead use static class

summer stump
eager spindle
#

so in future if someone wants to

public static class MoreSettings : Settings {
}

they must keep everything static

eager spindle
willow scroll
# eager spindle im willing to do that

What I also not like about many tutorials is providing 200-line code blocks for the methods, which can easily be explained in much less lines, and, perhaps, several examples. You then have to find the explained method in this huge snippet and check out all the methods related to it. So, please, make sure to note that when doing yours!

naive pawn
summer stump
eager spindle
elder osprey
#

Alright, just to confirm. If I were to say: Settings.leftHanded = true; in a script. Then I did Debug.Log(Settings.leftHanded) from a different script, it would log "true" in the console?

eager spindle
#

yep

elder osprey
#

Bet

willow scroll
#
public bool leftHanded
{
    get => _leftHanded;
    set => _leftHanded = !value;
}
#

||Naming violation||

eager spindle
#

rare case but yes that's true

elder osprey
#

Also, if the script is static, do I need to initialize the script at runtime. And if so, how could I do this? This is what I have currently ```cs
public static class Settings
{
public static bool fullscreen = false;
public static bool leftHanded = false;
public static bool highContrast = false;

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
public static void RuntimeInitializeBeforeLoad()
{

}

}```

eager spindle
#

nope you dont

naive pawn
eager spindle
#

thats the first time ive seen that macro

naive pawn
#

your Settings doesn't interact with unity at all

#

it doesn't need unity to tell it to load

willow scroll
#

Static classes just exist always..

#

And so they are not related to Unity at all

elder osprey
brave robin
#

[RuntimeInitializeOnLoadMethod] is very useful if you want your static to have methods that immediately run, like Awake or Start does. I use it often, when I need that

naive pawn
brave robin
#

But to be safe I use the option for 'after scene load'

brave robin
elder osprey
strong wren
#

how do i fix this?

#
        {
            ReloadAR();
        }
    }

    public void ReloadAR(float ReloadAmmount)
    {
        ReloadAmmount = ARMagSize -= ARAmmo;
    }```
naive pawn
#

oh wait c# uses a different form of these, it's a static constructor instead

brave robin
naive pawn
#
class X {
  static X() {
    // run on class load
  }
}
eager spindle
#

a float

naive pawn
strong wren
eager spindle
#

yep

#

put a number

strong wren
#

oohhh

languid spire
naive pawn
#

it isn't doing anything useful

#

you're just reassigning it

brave robin
naive pawn
# strong wren wdym?

your method ReloadAR takes a parameter, then it immediately throws away that parameter

#

it isn't doing anything

strong wren
#

kk

#

ima just make a private float outisde of the paramater

frank delta
#

is there any reason why the post processing changes by script is not showned?
here is the script, it is fairly short

public class PlayerGForce : MonoBehaviour
{
    Entity.EntityFastMovers Entity;
    [SerializeField] Camera cam;
    [SerializeField] Volume volume;
    Vignette vig;

    void Start()
    {
        Entity = GetComponent<Entity.EntityFastMovers>();
        volume.profile.TryGet<Vignette>(out Vignette vignette);
        vig = vignette;
    }

    private void FixedUpdate()
    {
        vig.intensity = new ClampedFloatParameter(Entity.GetVelocity() / Entity.MovementData.maxSpeed, 0.2f, 1);
    }
}
slender nymph
#

because you are not changing any values on the settings in the profile. you output your vignette settings to a local variable then immediately assign a different object to that local variable

frank delta
#

oh right

#

thanks!

slender nymph
#

actually that last bit was wrong, you are assigning the local variable to the field

#

i misread the code

frank delta
#

what should I change then?

#

I thought vig is already a reference to the volume profile vignette component

slender nymph
#

have you confirmed that the values you are using are what you expect them to be?

frank delta
#

yes, you can see in the video that the value changes

eager spindle
#

not reliable advice but do it the dumb way and use TryGet every frame. last time I worked with volumes this is what examples online did.
vig could be a copy of vignette

slender nymph
#

if it were a copy it would need to be assigned back (it doesn't)

rich adder
#

its so much easier just to make another profile with the settings you want and just blend between the 2 Volumes with separate profiles using the weight slider

eager spindle
#

what about enabling override for vignette before starting?

frank delta
#

how so?

eager spindle
#

tick the box for vignette and try again

#

it wont change much but its probable

frank delta
#

changes nothing

eager spindle
#

things will get tricky if you're gonna use multiple volumes (> 2)

rich adder
#

just make sure the one you want to fade in has higher priority

slender nymph
slender nymph
rich adder
#

oof

long jacinth
#

copied these from my old code for an aiming system but how do i replicate this code with what i have new

slender nymph
# solar canyon My bad I didn't see it

okay well i recommend going through the basics of c# if you still don't understand what you did wrong. there are beginner courses pinned in this channel

frank delta
eternal falconBOT
#

mad No

Be mindful, if someone requests your code as text, don't send a screenshot!

long jacinth
#

ok

frank delta
solar canyon
slender nymph
#

that is one of the beginner courses that i was referring to, yes

rich adder
solar canyon
frank delta
#

ahahaha drunk driving sim!

rich adder
naive pawn
#

dear god

frank delta
#

all til that adrenaline runs out!

naive pawn
#

the flashbang though

rich adder
#

sorry. I'll take it down not to blind anyone else

frank delta
#

(someone should totally make a game about fighting people but if you stop fighting, your adrenaline drains and you pass out)

eternal needle
rich adder
tacit cypress
frank delta
#

gotta search that up rn ahaha!

rich adder
#

a little bit more rated R though 😉

#

basically if his heart stop he die so he needs constant adrenaline rushes

frank delta
#

omg, it existed

#

anyways, if we are going to talk, go to a different channel!

#

let the others have their coding help

long jacinth
#

if(Gun.transform.rotation < -90 || Gun.transform.rotation > 90)

rich adder
#

back to unity code

frank delta
long jacinth
rich adder
frank delta
#

but for short ones,

do this
eager spindle
long jacinth
rich adder
#

rotations are stored as quaternion @long jacinth

frank delta
#
(your stuff goes here)
eager spindle
#

use the backtick `, not apostrophe '

long jacinth
#

thanks

frank delta
frank delta
long jacinth
frank delta
#

but for reasons, they use Quarternion

#

to use the Vector3 version, do

Quarternion.Euler(vector3)
rich adder
eager spindle
rich adder
#

oh nvm then

eager spindle
#

read the docs for transform

#

it is very fun

frank delta
#

anyways it is like

||if(Gun.transform.rotation.eulerAngles.(youraxis) < -90 || || Gun.transform.rotation.eulerAngles.(youraxis) > 90)||
to fight certain spoon feeding allegation

eager spindle
#

if you have any questions about transform let us know.
the purpose of transform is to describe where an object is, how it's rotated and how big it is.

pastel dome
#

ayo, how does on one properly create a network behavior script? you just create a mono behavior and change those words to network behavior?

rich adder
#

those words meaning something

#

its called a parent class

#

maybe you should not be starting with networking..

pastel dome
#

ya thank you

long jacinth
#

yo guys thanks ima watch that video about quaternions

eager spindle
#

funni math stuff

frank delta
#

quaternions are hell

#

I have yet to master it

#

yaw pitch and roll bull crap 😭

eager spindle
#

in most cases on unity you can get away with using eulerangles, but if you do go ahead with your own engine youll learn to love quaternions

frank delta
rich adder
eager spindle
#

salutations

rich adder
#

just know what they're for thats it

eager spindle
#

we love opengl

long jacinth
frank delta
#

and their dumb web gpu usage

eager spindle
pastel dome
#

quaternions are hard how

rich adder
# long jacinth ok thank you

as long as you understand, what you see inside the inspector is the rotation in euler Angles which is usually what you want to work with.. but the rotation should ideally always be kept quaternion
so any method you would do rotation = Quaternion.Euler
etc

long jacinth
#

ok thanks guys

frank delta
cosmic dagger
eager spindle
#

i think edge has it off by default

pastel dome
#

bruh like pie is just a random number its not that different than regular math

frank delta
eager spindle
#

major yabai

frank delta
#

I made all the shaders run on CPU

#

in one of my older project

#

cuz of that problem

eager spindle
#

I made a unity webgl project for one of my assignments and had to guide my lecturer on how to enable webgl after complaints that it was laggy

#

it ran at the full refresh rate afterwards

eager spindle
frank delta
brazen ginkgo
#

Can someone help me with this error? im trying to load up the 2d platform microgame

naive pawn
#

please don't crosspost

frank delta
#

if you absolutely decimate your texture before using the fragment shader! everything runs kinda smooothh

eager spindle
#

idk

pastel dome
#

then again yall always tend to use cinemachine rather than figure out the camera controllers for yourselves..

eager spindle
brazen ginkgo
eager spindle
#

what happens if you click revert factory settings

eager spindle
#

ooh

#

i love the graphics style a lot

fickle plume
frank delta
#

it got scrapped though

brazen ginkgo
#

yea sorry i hadnt gotten a response and i thought it wouldnt work in that i felt this mightve been a better spot

frank delta
#

cuz of google

#

hello fogsight!

fickle plume
frank delta
#

yep sorry

#

and hello again

eager spindle
#

when multiple developers are working on a scene's UI, is it protocol to make multiple canvases? or multiple prefabs within the canvas

#

this is more of a survey than a help

#

I've been using multiple canvases until recently when one of my canvases wasn't displaying so I'm wondering how companies do it

eager spindle
#

yea, one member work on dialogue the other work on objective system

frank delta
#

if at the same time, splitting them out def works better

naive pawn
#

oh well HUD vs dialogue would probably be different canvases to begin with i feel

frank delta
#

saved us from having github conflict every hour

eager spindle
#

how would one split it out though, multiple canvases or multiple prefabs within a canvas?

eager spindle
#

i wanna know how others do it

frank delta
#

since our project arent gigantic, we just make different test scenes for everyone involved

eager spindle
#

i dont understand how a project can have hundreds of developers

frank delta
swift crag
#

100 people are definitely not 100 times more productive than 1 person

#

you get diminishing returns

#

oh right, this moved lol

#

👻

cosmic dagger
eager spindle
#

using seperate canvases has optimisation benefits? POG

cosmic dagger
#

Any GameObject or UI that updates will redraw the entire canvas . . .

swift crag
#

my ass with a MainMenu made out of one colossal canvas:

#

(I only have a small part of the menu activated at any given time)

#

so it's ok

#

If you have lots of UI that's all active at once, and you can chunk it up into separate canvases, you should definitely do that

eager spindle
cosmic dagger
#

If you have one UI element that constantly updates, say a health graphic or value, with 30 other stationary UI elements; all of them will redraw every time the health graphic or value changes . . .

cosmic dagger
remote osprey
#

Can I have multiple SOs in the same file?

swift crag
#

No, you can't define multiple MonoBehaviour or ScriptableObject classes in one file.

remote osprey
#

Also, if I do need to separate all ym SOs in multiple files, anyone know a Visual Studio shortcut haha

swift crag
#

Unity doesn't care about the name of your class -- it cares about the file it came from

remote osprey
#

Oh ok

rich adder
remote osprey
dense root
#

What's a simple way to make the NPC face the player when they are speaking to them?

cosmic dagger
rich adder
remote osprey
#

I can finaly create events through Unity's Editor 🥺

#

How come my card data has no attributes in the inspector?

#

This is the code for CardData.cs

#

It was showing before I put {get; private set;}

#

REally, before I refactored the gigs out of my code lol

cosmic dagger
#

Bruh, !code

eternal falconBOT
cosmic dagger
#

get; private set; are for properties. These are variables with the [SerializeField] attribute . . .

#

Properties do not display in the inspector unless you use an attribute . . .

#

You're trying to combine both . . .

remote osprey
#

Yup I need it for my game logic

#
  1. to create Prefabs easy to modify
#
  1. to add my game logic to it and integrate it to my architecture
cosmic dagger
remote osprey
#

Apparently, autoproperties does not work with Scriptable Objects

#

So, basically, what I understood

#

Scriptabble Objects Attributes can't be changed at run time

#

Is that correct?

#

So I should just use them as constants

vast sandal
#

Stuff like this:
inputVector.y == 1 ? playerRigidBody.AddForce(0f, 10f, 0f) : playerRigidBody.AddForce(0f, 0f, 0f);
doesn't work because i check an vector value?
Or because I try to call a function in the consequence?

remote osprey
eternal needle
#

evaluates a Boolean expression and returns the result of one of the two expressions,

vast sandal
swift crag
#

The conditional operator is none of these.

#

I'm not sure of the exact justification for that rule.

#

In Java, for example, I'm pretty sure you can freely write stuff like:

#
3;
#

C# does not permit this

#

I suppose the point is that, in most situations, there's no point to writing an expression like that, so it must have been a mistake by the programmer

eternal needle
cosmic dagger
swift crag
#

it's entirely about how Unity serialization works -- which is the same for any unity object

cosmic dagger
cosmic dagger
vast sandal
swift crag
#

Sure, it is

#

The entire conditional operator expression is not.

remote osprey
swift crag
#

What you've written is, in the eyes of the compiler, no different from:

#
true ? 1 : 2;
remote osprey
swift crag
remote osprey
cosmic dagger
remote osprey
#

Otherwise I would've tossed it

cosmic dagger
remote osprey
#

Wouldn't it be easier if SO let me do that tho

#

I wouldn't have to create another class

swift crag
#

the scriptable object contains the data

eternal needle
#

You can create instances of SO but you should dive a little deeper into the problems with doing so before actually doing it

remote osprey
#

Ok xD

cosmic dagger
remote osprey
#

So apparently SOs hates interfaces 🙂

remote osprey
#

But i'm just gonna go with my way because it's one less class babbyyy

#

Creating a new C# script has started becoming my most hated activity lately 🙂

stuck palm
#

can unity serialise a list of a list?

carmine sierra
#

is it not convention to make public variables capitalised

cosmic dagger
remote osprey
#

Exactly 🙂

#

5-10 secs to add a potential bomb to my code database 😄

#

jokes aside

#

I'll just choose the minimum amount of classes to keep the code more maintainable

#

being a solo dev has been literally hell 🙂

eternal needle
remote osprey
#

Thing is, why add one more class when I could just use my SO class to hold the same data and have the same behaviour haha

#

It makes no sense

eternal needle
stuck palm
#
public struct ReplayPlayer
{
    public CharacterEnum character;
    public int characterColor;
    public int characterID;
    public List<List<ButtonState>> _buttonRecording;
    public List<List<MoveState>> moveRecords;
    [NonSerialized] public PlayerInputController inputController;
    public bool isReplay;
}

is there a way to make the nonserialized thing show up in the inspector? i have it as [nonserialized] so the json convert doesnt try to serialise it, but i need to be able to see it in the inspector

eternal needle
stuck palm
#

nvm i found a fix

remote osprey
#

I'm literally creating SOs all the time in my game lmao

#

I designed it so that each action is an SO

eternal needle
eternal needle
# remote osprey Do you have any resources so I can look into this?

Not aware of any that goes too deep into it, but theres a difference of creating an asset in editor time and creating an instance at runtime. The most commonly brought up issue is that changes dont persist to these, and may reset back to it's original state if it's not referenced anymore in a scene. If you're creating instances, you also need to manually destroy them. It's not hard, just a pain compared to using plain c# classes, because the GC handles this for u

remote osprey
#

This seems pretty important info

#

How do I destroy a SO instance?

stuck palm
eternal needle
peak chasm
#

*eye Twitch ok im stumped here. Iv got a Sav Data script and It MAKES the files, so hurray for that, and the Inventory Section works perfectly fine, but The Player World Location part does not. Im TRYing to make it so while the update loops run Player POS updates in realtime. Player Object POS does, and I'm trying to feed that data into the other variable, but it doesnt work. I cannot figure out why, is there something really stupid about [System.Serializable] ??? When i press load all the Vector3 variable stay at 0 so saving player pos is getting hard

lavish magnet
#

I have this on all my zombies, its my function for them attacking, This if statement seems to always go through. player is the player gameobject, that the zombies target, why does this if statement go through if the prints are equal

peak chasm
#

I have NO idea what im doing wrong, this is my first time actually trying to play with JSON and i just dont get it

cosmic dagger
stuck palm
#
private void FixedUpdate()
    {
        if (!started) {return;}
        foreach (ReplayPlayer rep in _replay._replayPlayers)
        {
            rep._buttonRecording.Add(rep.inputController.buttonList);
            rep.moveRecords.Add(rep.inputController.moveList);
            print("Added " + PrintList(rep.inputController.buttonList) + "to buttonlist");
            print("Added " + PrintList(rep.inputController.moveList) + "to movelist");
            rep.frameLength++;
            rep.lastMove = rep.inputController.moveList;
            rep.lastButton = rep.inputController.buttonList;
        }
    }

I'm getting proper console logs, but when I actually go to check the Json, it doesnt actually add them to the list. why is this?

teal viper
stuck palm
#

It will probably come to me as I sleep

remote osprey
#

should i make everything inside an object null before Destroy()ing it?

remote osprey
#

I saw in a video that Unity doesn't necessarily deallocate memory after Destroy() though

#

And that references to it should be null

#

However, my thinking is that if I destroy() an object all of its properties/fields will be destroyed as well, correct?

warm condor
#

Hey guys, so I have been trying to detect a side switch (meaning detecting if the player has went from left to right and vice versa) by comparing the current position and the previous position . the problem that I am having here is that the if statement that checks if the player has side switched always returns false and thus it never executes the side switch. Here is an example of my code:

    void Update(){
        CurrentHorizontalPos = transform.position.x;
        PreviousHorizontalPos = CurrentHorizontalPos;
        Debug.Log(hasSwitchedSides); //Always returns false and not true in all cases
    }    
    private void EnabledSideSwitch(){
        if(PreviousHorizontalPos != CurrentHorizontalPos) hasSwitchedSides = true;
        else hasSwitchedSides = false;
    }

What could be the issue here?

cosmic dagger
summer stump
slender nymph
#

technically they wouldn't be destroyed at all since c# does not really have the concept of destroy. Once nothing else references that object and it gets GC'd then anything only referenced by that object will also get GC'd

remote osprey
cosmic dagger
remote osprey
#

Oh ok

#

Thanks for the explanation!

#

Are you people really thorough when it comes to memory handling?

teal viper
#

Most of your memory consumption is gonna be from texture and mesh data anyway

remote osprey
#
public class Board : MonoBehaviour, IDestroyable
{
    public static Board Instance;

    public List<LinkedList<Canvas>> summons { get; private set; }

...
    public void ClearDataAndDestroyInstance()
    {
        foreach (int i in Enumerable.Range(0,summons.Count-1))
        {
            foreach (Canvas canvas in summons[i])
            {
                Destroy(canvas);
            }
            summons[i] = null;
        }
        summons.Clear();
        summons = null;
        Destroy(Instance);
    }

Is something like this too much?

remote osprey
#

Now I'm implementing my IDestroyable on every class in my project hahaha

teal viper
#

C doesn't have a garbage collector, so you need to manage memory manually. C# and unity does, so you just need to be aware of GC rules.

teal viper
eternal needle
teal viper
remote osprey
#

Ok

#

I guess I'm only gonna be careful when around my instantiated SOs

#

Making sure to delete ALLL of them when my game session is over

eternal needle
#

you really dont need to instantiate SOs. You're doing this because you dont want to simply make another class and let the GC handle this for you

remote osprey
#

but what's the problem with this tho

#

I googgled it and ppl only told me to be careful with destroying my SOs

eternal needle
#

now you're in uncharted territory because you dont understand some downsides to it. This is just gonna take you longer than the 1 minute of setting up another class. Like "the game session is over" why does it matter what you do with your instantiated data

remote osprey
#

I dunno, It just feels right to code like this

#

Everything has been an uncharted territory so far

#

I'm just doing my best to manage my anxiety

eternal needle
#

just a note, when the game ends, everything is destroyed. its not just dangling around in memory if you dont destroy it past the lifetime of the application

remote osprey
#

What feels wrong to me is not that there will be more code, is that the extra class will be (almost) exactly the same to the SO

#

This terrifies me of the amount of times I'll confuse the two classes