#💻┃code-beginner

1 messages · Page 400 of 1

polar acorn
#

Unity sends messages to all MonoBehaviours to run functions that match the message signatures, such as void Update() or void OnCollisionEnter(Collision other)

serene acorn
#

Like, they are the base components for unity; you can download extra components from the store but they ate made by other guys

serene acorn
wooden socket
#

this is 2 different lines right

serene acorn
#

It was weird to me that's all

polar acorn
#

It's just a normal function

#

You can freely call someBehaviour.Update() just like any other function

serene acorn
summer stump
#

Especially if you make it an overload

polar acorn
summer stump
#

You likely do not WANT to though, if you expect it to act differently

wooden socket
#

are the blanks all ToString?

serene acorn
polar acorn
#

Every Update is a custom function for that script. It's not calling anything. It gets called

serene acorn
#

If I wrote BizarroUpdate it wouldn't work the same

polar acorn
summer stump
rich adder
summer stump
#

It checks the actual name of the method

polar acorn
#

It's nothing "special" that Unity does. It's a thing that anyone could do

serene acorn
#

But what's what I'm saying, nevermind

long jacinth
#

my whole game started rotating lol

serene acorn
raw token
serene acorn
#

Like I don't have to setup anything for it to detect "update"

wooden socket
#

okay ill put it in an update field

summer stump
polar acorn
rich adder
serene acorn
#

Yeah yeah I get it

polar acorn
#

but they're completely ordinary functions, that are called via reflection by a script that is run by Unity

long jacinth
#

i think i messed up one second

serene acorn
#

It's logic already made by monoBehavior

rich adder
#

there is no logic in it

wooden socket
#

i filled out the blanks and it still didnt work

ivory bobcat
summer stump
rich adder
#

it just calls the C++ backend

wooden socket
#
int score = ScoreManager.instance.score.ToString();

    displayText.text = Score.ToString();
polar acorn
#

There's no "ur-Update" function that everything's "inheriting" from. It's not defined anywhere. It's simply checking the name, and executing the function, whatever it does

serene acorn
#

i suppose I could in theory do a bizarroMonobehaviour script, copypaste the code and would also work

#

When si inherit from it

wooden socket
polar acorn
#

Does it make sens to store a string value in a variable that can hold an integer?

long jacinth
#

but unfortunately when i try it doesnt work

wooden socket
#

i thought it was 2 lines

eager spindle
#

either works but pretty close

polar acorn
eager spindle
#

for int score you're not using an int anymore though

#

change it accordingly

wooden socket
#

and this all goes in an update

#

okayuu

serene acorn
#

That's what I quite don't get

#

Like for example

rich adder
eager spindle
eager spindle
#

save us sanity

serene acorn
#

Let's say with boxcollider2d

wooden socket
#

no it goes in awake

rich adder
serene acorn
wooden socket
#

okay it doesng go in awake

rich adder
#

make your decision

eager spindle
wooden socket
#

wait but it didnt work in Awake

#

i still get errors

eager spindle
polar acorn
polar acorn
rich adder
wooden socket
serene acorn
#

Pffff I'm not getting it, let me make up my mind...

rich adder
#

we need to see what u wrote

polar acorn
wooden socket
#

its my other script

#

and a class i made

#

that houses the public static ScoreManager instance

rich adder
#

yes but that script doesn't know what it is

wooden socket
#

but i already have a public static score manager instance in my scoreManager script

rich adder
#

so why do you have scoreManager still in there in UI script if you already have ScoreManager.instnace

polar acorn
wooden socket
rich adder
wooden socket
#

yes

rich adder
#

why is it complaining scoreManagement.cs but your class is called ScoreManager

wooden socket
#

managment is the name of the file

rich adder
#

you should keep your names the same as class with filename

wooden socket
#

ok

summer stump
# serene acorn That's what I quite don't get

You said you are not a developer, right? How much handson experience do you have with coding? I feel like all of this would be very confusing in abstract, but make much more sense when actually implementing it.
I am simply not sure how to explain it in a way it makes sense. Other than repeating that these are magic methods and used via reflection.
Sorry

polar acorn
serene acorn
#

i mean im junior but yeah

#

brb let me write a long message about what confuses me

wooden socket
#

public class ScoreManager
{
public static ScoreManager instance;
public int score;
}

long jacinth
eager spindle
rich adder
wooden socket
rich adder
#

get rid of scoreManager

#

capitlization matters

eager spindle
# wooden socket

you dont need to set scoreManager's score. in fact scoreManager doesnt exist. only ScoreManager.instance

polar acorn
wooden socket
#

okay so nwo there are two scores

eager spindle
#

MY UNITY CRASHED

#

MY SCENE NOO

rich adder
polar acorn
wooden socket
#

heres whaht I got

#

wait

rich adder
wooden socket
#

shit i made mistake

#

score should be whats in Awake

rich adder
#

get rid of start completely

wooden socket
#

none

#

did it

eager spindle
rich adder
#

what happen to text

eager spindle
#

you dont need score either

wooden socket
rich adder
#

stop showing ScoreManager

wooden socket
#

ykw gimme a sec

rich adder
#

we dont care about ScoreManager

polar acorn
#

this is fine

#

that's not the issue

wooden socket
rich adder
#

oh lord

#

why is this defined in here..

#
public class ScoreManager
{
    public static ScoreManager instance;
    public int score;
}```
wooden socket
#

okay ill remove it and put it in the other script

rich adder
#

who told you to put it

eager spindle
#

put it in seperate scripts

wooden socket
#

so I make a new one

#

or put it in scoreManagment

rich adder
#

dont touch anything on the ScoreManager everything was fine on how you had it

wooden socket
#

okay new script

#

like entirely new

eager spindle
#

is it spoonfeeding if i make a whole video tutorial on this right now

rich adder
wooden socket
#

OKAY

rich adder
#

no "new script"

wooden socket
#

ok

rich adder
#

if you're struggling with simple following instructions might wanna give another hobby a try

wooden socket
#

i put public class ScoreManager
{
public static ScoreManager instance;
public int score;
} in the displayScore script

polar acorn
# wooden socket https://gdl.space/ahotowisic.cpp

Okay, I am going to say some pretty harsh things but you are going to need to hear it.

If you are incapable of basic logical reasoning, you will never be able to code anything at all. You need to actually think through what you are doing. These lines all have meaning. They say things. You need to be able to hold multiple statements and draw conclusions from them. This is not something we can teach. This is not something anyone can really teach. If you are incapable of logical reasoning, this is not the hobby you should be pursuing. You will not create any programs by randomly bashing words into various places until they stop yelling at you

wooden socket
#

dude what the hell

#

im sorry

#

im just very tired

#

im trying really hard

#

im really sorry

rich adder
#

My dad used to say "Dont be sorry just do it correctly"

polar acorn
#

I don't intend to be mean, I just want to warn you

#

This seems like a failure to connect cause and effect

#

which is going to make this very very hard for you

wooden socket
#

okay ykw besides the point

rich adder
wooden socket
#

in diisplay score I put

public class ScoreManager
{
public static ScoreManager instance;
public int score;
}

ivory bobcat
#

I'm just going to provide a solution as this is likely a guessing game that isn't really productive for the server channel cs private void Update() { scoreText.text = ScoreManager.instance.score.ToString(); }Which will likely not work properly if they do not have an appropriate Singleton object instance in the scene.

eager spindle
#

you can try hard but without the foundational knowledge you wont be able to get far. learn object oriented programming first and develop stuff with it. learn what static variables are, what types in c# are, and learn unity's quirks. what MonoBehaviour is, what Start, Awake, Update and LateUpdate do

rich adder
#

this isn't a coding this at this point, you arent even following our instructions correctly

wooden socket
rich adder
#

you're just guessing and writing stuff that dont' need to be written in code

summer stump
# serene acorn brb let me write a long message about what confuses me

I think the steps of operation may help? so Physx or Box2d checks the position of every collider every physics update.
If some overlap, it will tell unity.
Unity will iterate all monobehaviours with those colliders and check if conditions are right for the physics message to be sent. Then it sends the message to the methods providing data for you to use in your code. Because of course the only place you COULD use it is in your own code (ie, a MonoBehaviour)

wooden socket
#

you are very confusing

eager spindle
polar acorn
wooden socket
#

they are

rich adder
#

and write something completely different than what was said or shown

polar acorn
#

"I need ScoreManager to exist" and "ScoreManager should not be in the same file as DisplayScore" should lead to the conclusion "ScoreManager should be in a different script" without having to be directly told that

eager spindle
#

and ScoreManager isnt a monobehaviour either, based on what you showed us. Because ScoreManager is not a monobehaviour, you couldnt set public static ScoreManager instance to the ScoreManager because there's no start function.

#

Because of that, theres a null reference. And thus your code didnt work out

#

That's not factoring in you having difficulty converting an int to a string.

serene acorn
#

https://docs.unity3d.com/ScriptReference/Collider2D.html

for example, here, this is a component, a collider. It has properties, and it has functions, something like


void Start()
{

    mycollider = GetComponent<Collider2D>();

    mycollider.enabled = false;
    mycollider.enabled = true;
    mycollider.IsTouching(mycollider);
}```
here it has functions exclusive to that component, like "Istouching" and it has properties/functions that are common through all components, like "enabled" (all ccomponents can be enabled/disabled)


My question is, why doesnt it have something like```mycollider.OnCollisionEnter();``` because if I put this I get an error. 

I suppose many collider components have a common parent, component, called "collider" it seems, for what I'm seeing here on the docs. But my question remains, why cant I get the "check if it has collided" function directly from the collision component?
#

@summer stump

#

@polar acorn

rich adder
serene acorn
#

dunno If I explained it right

eager spindle
#

Overall, you should understand that unity requires knowledge of object oriented programming, and the ability to search online for what you need to do

polar acorn
#

That is not a member of that class

summer stump
polar acorn
#

it is a message function that is called by collisions

wooden socket
#

damn it man

#

just tell me where this ONE thing goews

#

goes

ivory bobcat
wooden socket
#

its the final thing

rich adder
wooden socket
#

we are so close please just

#

tell me

wooden socket
#

no, you just told me to fill in blanks and after I did i was very close apparently

polar acorn
#

They wrote the whole damn class for you

eager spindle
rich adder
#

thats whats even more frustrating we didnt even hide behind the bush or hint at it. We literally give you lines of code to copy
and you still copied wrong

wooden socket
#

oh i didnt see that

serene acorn
polar acorn
polar acorn
wooden socket
#

this is in scoreManagment

summer stump
serene acorn
wooden socket
#

oh wait

#

hold the phone

polar acorn
serene acorn
summer stump
wooden socket
#

well

#

lemme test it now and see if it works

polar acorn
wooden socket
#

i fixed the errors

serene acorn
#

like, start, update, on collision enter... all of those are functions right?

summer stump
serene acorn
wooden socket
#

okay it works

polar acorn
#

they are called by unity. Not made by unity

raw token
#

They're more like event handlers

eager spindle
# serene acorn isnt that what we want?

the way messages work is that youre calling a function by the function name. it quite literally looks for all objects with the function named "OnCollisionEnter`. you're not overriding a function. youre just hoping the physics engine finds your gameobject with the OnCollisionEnter function,

thus you need to define the OnCollisionEnter in your gameobject first.

wooden socket
#

everything works

#

okay wel

#

well

#

im gonna take a break for 2 days

#

goodbye

eager spindle
eager spindle
summer stump
serene acorn
serene acorn
#

let me think how to say it

eager spindle
polar acorn
#

It wouldn't make sense for it to be a function you call on a collider

summer stump
#

Defining OnCollisionEnter is like that!

polar acorn
#

Because you don't know when a collision happens

summer stump
#

Not calling it. Just to be clear

polar acorn
#

Unity does

#

Unity needs to tell you when a collision happens. So you define a method that runs when Unity says "Hey, you hit this thing"

serene acorn
#

yeah I get that unity is checking the monobehaviour scripts and looking for those keywords and act uppon it. What I dont get is why cant oncollisionenter be exclusively inside the collision components

#

and not something outside of it

serene acorn
eager spindle
#

or rather, the physics engine

polar acorn
serene acorn
#

so it all falls down to the physics engine?

summer stump
eager spindle
summer stump
#

It is a completely separate engine

serene acorn
#

ok I think im starting to get it now

polar acorn
#

You absolutely can do the math yourself in update and keep track of what is intersecting with what. In which case, you don't need colliders at all

verbal dome
rich adder
polar acorn
#

But, since you're using colliders, you probably want to know when that collider has collided

summer stump
verbal dome
#

I dont think that page should exist lol

serene acorn
#

ok so because collision is physics and are complicated operations, is not enough to have a check inside a component, you need unity, the engine, to act and thats why iOnCollisionEnter has to be separated

eager spindle
#

the library unity uses is called PhysX. for physics engines the overall procedure is

  • add a bunch of physics objects to a scene(cube, sphere, mesh)
  • keep calling Physics.Simulate(delta) to update the positions of your physics objects
  • keep changing the position of your GameObjects to the position of your physics objects
verbal dome
rich adder
#

all the ones with colliders become part of that separate "physics scene"

polar acorn
raw token
serene acorn
#

so basically when you do "oncollisionenter"iS the unity phisics engine what is managing all of that

polar acorn
serene acorn
#

and it can't be something outside of it, like a component

polar acorn
eager spindle
rich adder
eager spindle
#

we wont know what happens inside unity core

raw token
polar acorn
rich adder
eager spindle
serene acorn
#

I dont understand then why something like box colliders or rigidbodys are optional components then if the operations are made by the physics, why arent the same as the "transform" like all components have?

polar acorn
summer stump
eager spindle
polar acorn
serene acorn
#

because for example sometimes I have components that I dont need them to be in a specific position in the map, something like a background song

verbal dome
serene acorn
polar acorn
#

An object might represent, for example, TurnManager, an object that knows whose turn it is and who's next and so on. This object doesn't really "exist" in a physical sense. It would not need a collider

eager spindle
rich adder
#

and vice versa

summer stump
eager spindle
#

maybe if you work in a corp that has unity source code youll get to see it all

summer stump
#

How can a gameobject not have a position (and scale and rotation)
It is not physics

polar acorn
serene acorn
polar acorn
#

An object could define a coordinate space but not physically exist, such as the canvas

rich adder
#

its in a physical world, so it needs to have position. Unity is Gameobject / component based

eager spindle
#

cant gameobjects exist without transforms in ECS?

serene acorn
#

I suppose its the basis of how unity made teh components

verbal dome
polar acorn
#

Canvas objects are massive so that their coordinate space is in pixels instead of meters, but they cannot have physics on them

eager spindle
#

for me I have a Manager gameobject that has every manager script

serene acorn
eager spindle
#

a lot of gameobjects do it that way too

polar acorn
#

So, a canvas does have a scale and position, because it's important where other objects are in relation to it, but it's not a physical object that can collide or be moved by physics

eager spindle
#

its better than changing your background music in the project settings

serene acorn
serene acorn
polar acorn
rich adder
eager spindle
#

its easier to extend monobehaviour to do your things rather than add directly to engine code

summer stump
eager spindle
#

you do not want to spend 12 hours compiling unity

serene acorn
#

so basically collisions, physics and stuff like that are handled by unity directly and thats why it is on monobehaviour instead of inside a component

ivory bobcat
# serene acorn thats what I dont get

The common patterns are:

  • You iterate through every object, validate them and do what you've defined them to do
  • You'd just define and subscribe them (the magic portion)
    Unity (and many other frameworks and libraries) will likely opt for the second behavior as the first is less flexible (subscribe/unsubscribe), puts the burden on the person implementing/defining the function (manage-less) and requires the library to expose members. The purpose of events is to have users be able to subscribe/unsubscribe to stuff without knowing or being able to modify the stuff. The user shouldn't need to know or modify whatever's calling their code - decouples implementation.
eager spindle
#

monobehaviour is a component but better

serene acorn
summer stump
rich adder
untold bear
#

I have this scene which works fine in the editor but when building I get this parsing error , I went to look at the file in code and it looks just fine at those lines

eager spindle
serene acorn
eager spindle
#

monobehaviour comes from behaviour coming from component

summer stump
serene acorn
eager spindle
rich adder
ivory bobcat
serene acorn
#

come on @eager spindle @rich adder you cant just put those two comments together

rich adder
#

Rigidbody is a Component but not a behavior iirc

eager spindle
rich adder
#

hence why it cannot be disabled

verbal dome
serene acorn
#

will not think about it at the moment then

eager spindle
#

some days I just want to disable rigidbody

#

but no i have to set iskinematic

serene acorn
#

just I should know that everything comes from monobehaviour

#

like oncollisionenter, start, update

#

and that unity determines which one goes first

eager spindle
rich adder
rich adder
ivory bobcat
serene acorn
#

another thing, would it be possible that components didnt have transform as their base? like if you wanted an ephemeral component like music

verbal dome
serene acorn
#

like I suppose itsa just how unity made things, im just asking if its possible

rich adder
serene acorn
eager spindle
#

thats a tongue twister

ivory bobcat
eager spindle
rich adder
ivory bobcat
eager spindle
#

yuh

serene acorn
#

like how does unity detect which update goes first

#

from one gameobject or another

eager spindle
rich adder
eager spindle
#

you can go to Project Settings to change that

serene acorn
#

you read my mind

ivory bobcat
eager spindle
#

fun stuff

#

wait whats monomanager why is the page called that

rich adder
#

yeah if you're messing with executions order your design is probably flawed

serene acorn
#

ok so

eager spindle
serene acorn
eager spindle
#

but other than that nothing else

serene acorn
#

collider is an abstract class then?

eager spindle
rich adder
ivory bobcat
summer stump
eager spindle
serene acorn
#

and I suppose these were made as default by unity devs

#

so these are tied to the physics engine in the end

eager spindle
summer stump
rich adder
eager spindle
#

well you cant do anything on a collider with no shape

ivory bobcat
# serene acorn

What I see is that Collider is where On Collision Enter is defined.

#

Like if you decide to define an enum in your class.

serene acorn
eager spindle
#

you can GetComponent<Collider> but unity will tell you its outdated

verbal dome
long jacinth
serene acorn
eager spindle
#

you cant make a new collider since the constructor is probably protected, youll need to talk to the phys engine instead. which is what unity does when you add a collider component

eager spindle
serene acorn
eager spindle
#

what does it mean to add the recoil and angle together

serene acorn
#

is just that they wont have the unity things

long jacinth
eager spindle
#

yuh

long jacinth
#

well it unfortunately doesnt work

serene acorn
#

so here messages arent quite right functions

eager spindle
#

why

#

well it rotates the gun which is expected

serene acorn
#

they are like "checkers"

eager spindle
#

did you mean to rotate the camera instead?

long jacinth
ivory bobcat
long jacinth
#

theres a problem

#

its because the gun will always point to the mouse

#

i see it rotating for a millisecond

serene acorn
#

and I dont have to worry how the calling logic works because thats what unity is for, to manage that right?

#

are these all the messages unity has or are there some extra ones outside of monobehaviour?

summer stump
eager spindle
long jacinth
eager spindle
#

or do you just want the gun to be offset?

long jacinth
#

the cursor will anyways be invisible

eager spindle
serene acorn
#

I suppose the collider one is residual

long jacinth
verbal dome
ivory bobcat
eager spindle
long jacinth
#

void FaceMouse()
{
Gun.transform.right = direction + OffSet;
}

eager spindle
#

its been > 10 years though

ivory bobcat
#

You'd just work with the docs

serene acorn
long jacinth
verbal dome
#

Yeah it doesn't help that the Collider one is the first one that pops up on google

serene acorn
eager spindle
#

"unity things"

verbal dome
verbal dome
#

It's a weird decision from whoever documented it

dusty shell
#

RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, 0.05f);

this casts the ray from the player position down but i'm worried if the distance is too small, also how do I use this to check if the player is colliding with the ground

verbal dome
dusty shell
#

I put this in the update?

ivory bobcat
verbal dome
#

For the ground part, it's common to use the LayerMask parameter in Raycast where you pass the layers that you want to be checked. So the layers that "ground" objects use

#

But yeah, plenty of resources online about ground checks

verbal dome
dusty shell
verbal dome
#

Physics don't necessarily update between Updates, but they always do between FixedUpdates

spare mountain
eager spindle
#

maybe not after

#

but every 0.02 seconds

#

so updates can happen very frequently or very slowly, but fixedupdates happen every 0.02 seconds

summer stump
verbal dome
#

Yeah just before:

#

It's in sync with the physics update loop

ivory bobcat
spare mountain
spare mountain
verbal dome
#

I often use FixedUpdate for AI too, since I don't want it to be dependent on framerate

spare mountain
#

Fixed Update -> internal physics update

verbal dome
#

Although I very very rarely have to think if it's "after" or "before"

ivory bobcat
bleak glacier
#

I'm currently trying to work out how to make an inventory system. I already have my grid of buttons so that's covered. That was the easy part though.

I'm trying to reason my way through this to figure out what I need to do to make the buttons functional though. Here's what I have so far:

Assign sprites and other info to items
Slots must be accessible in item script - probably with GetComponent right?
When item is obtained set button image to item sprite
Set value in button that indicates slot is filled
If a slot is filled make item fill the next slot instead

This isn't quite as simple as I had hoped for though and I'm concerned that my C#/Unity knowledge isn't going to cut it here. But will this general plan get me somewhere?

eager spindle
#

make an array with all the items? like a list of all the items in game?

long jacinth
eager spindle
#

what I had in my inv manager is a List<Item>. Item is a ```class Item {
string name; Sprite icon; string description;
}

verbal dome
#

(If you still have an issue?)

eager spindle
bleak glacier
#

But it would probably be easier for my smooth brain to figure out. Ik I can already do that

eternal needle
#

Your inventory system should exist completely independent of UI, but maybe describe more of what you're doing. Why do you even have buttons in the first place?

eager spindle
#

forgor

#

I'm on mobile now

spare mountain
ivory bobcat
bleak glacier
ivory bobcat
#

Just lookup some stuff on google
There should be plenty of discussions or videos about them.

verbal dome
#

ScriptableObjects are generally used to make your own custom assets.
A lot of the unity settings assets are actually SO's too

eager spindle
ivory bobcat
#

They're useful if you need instances that are not deeply associated with game objects and the scene.

eager spindle
#

Besides being able to transfer data between scenes you can also make workflows for your artists and story writers that don't involve code

bleak glacier
eager spindle
dusty shell
eternal needle
eager spindle
#

yea I don't really do that, I see a lot of tutorials quote it though

eternal needle
#

And those tutorials are dumb

#

I've seen it used in many ways, even as an "event relay" basically because the people didnt know how to properly setup events. It is simply a data container, you can try to turn it into more but theres usually better options

dusty shell
#

how do i paste short code snippets without pastebin?

swift crag
#

triple backticks

raw token
#

```cs
yourCode.here()
```
Note that those are backticks, not apostraphes

queen thicket
#

how do i make a simple respawn point and check points system in my 2d sidescrolling platformer i can vc if it would help

swift crag
#

or when you try to store any state in the ScriptableObject and it happens to get unloaded

dusty shell
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TouchingDirections : MonoBehaviour
{
    // Attributes
    private CapsuleCollider2D col;
    [SerializeField] private LayerMask platformLayerMask;
    public bool isGrounded;
    public bool touchingLeftWall;
    public bool touchingRightWall;
    // Methods
    private void Awake() {
        col = GetComponent<CapsuleCollider2D>();
    }
    private bool CheckCollision(Vector2 direction, float distance){
        RaycastHit2D hit = Physics2D.Raycast(col.bounds.center, direction, distance, platformLayerMask);
        Debug.DrawRay(col.bounds.center, direction * distance, hit.collider != null ? Color.green : Color.red);
        return hit.collider != null;
    }
    private void FixedUpdate() {
        isGrounded = CheckCollision(Vector2.down, col.bounds.extents.y + 0.01f);
        touchingLeftWall = CheckCollision(Vector2.left, col.bounds.extents.x + 0.01f);
        touchingRightWall = CheckCollision(Vector2.right, col.bounds.extents.x + 0.01f);
    }
}

is this implementation the most efficient way?

bleak glacier
queen thicket
bleak glacier
queen thicket
#

and what about for detecting whern my player hits like the spikes or wtever

bleak glacier
#

Alright. Is there a better way to get components for all of these buttons other than copying and pasting this 27 times? GameObject.Find("Button1").GetComponent<Image>().sprite = newItem1;

wintry quarry
#

Put them in an array

#

Image[]

sage nest
#

Is there a way to set the dimensions of an object rather than it's scale?

#

To easily set everything to have the same dimensions

rich adder
#

doing it this way is over convoluted

#

but either way you normally want the PPU to be correct that 1 box = 1 unity unit

stuck palm
#

how can i get the date as a string?

#

like 2024-06-27_23-00 or whatever

rich adder
#

why not just use ToString?

summer stump
stuck palm
rich adder
#

DateTime can easily read it back

summer stump
stuck palm
rich adder
#

you can easily just store it as a string with ToString() then remake the object with DateTime class

summer stump
rich adder
stuck palm
#

i didnt know how to get the time

stuck palm
rich adder
#
string dateString = "2024-06-26 14:30";
DateTime parsedDate = DateTime.Parse(dateString);
Debug.Log(parsedDate);```
stuck palm
#

can you sort by datetime?

#

using linq or whatever

rich adder
#

indeed

stuck palm
#

although i guess it would be sorted kind of if you were grabbing them in file order?

rich adder
#

btw list also has a Sort method which would work

stuck palm
#

oh awesome

#

okay, thanks!

#

im trying to save multiple replays now, until now i've just been reloading and loading the same file which is annoying if i want to look at multiple replays

rich adder
stuck palm
#

easy enough to make

rich adder
#

gotcha. makes sense

wooden socket
#

hey guys, im back. this time with a smaller issue. Im getting this error: input string is not the correct format. I think its due to the way im doing this invoke.

#

this wont be as bad

#

im more rested now lol

#

whats weird is that its a unity only error and not VScode

#

im using int.Parse too

verbal dome
#

Maybe show us the code

wooden socket
#

okay

verbal dome
#

So you are passing a string into int.Parse that is not in the correct format, as the error says

wooden socket
#

is there a ToInt() like there is for ToString()?

verbal dome
#

int.Parse is pretty much that

#

What is this script doing anyway? Are you storing the score in a text...?

wooden socket
#

im sending the score to a script that sends it to a leaderboard

#

the name the player inputs

jagged abyss
#

tbh i think i'll start this alll

#

over again, with making the code

#

because anything i have tried so far hasn't worked, and so far my issue seems to get worse

verbal dome
late verge
#

Well, if you don't know what to do no point starting over

verbal dome
#

Consider storing it in an actual int

late verge
wooden socket
jagged abyss
verbal dome
wooden socket
#

wait okay

#

nvm i found it

#

hold up lemme rephrase

verbal dome
#

I see a TMP_InputField which is an input field

wooden socket
#

its not on the input box

eternal falconBOT
wooden socket
late verge
wooden socket
#

wait

#

what could the problem be?

verbal dome
#

Lol

jagged abyss
#

'''cs

verbal dome
#

Don't grab the score from the scoreText, grab it from an int variable instead

wooden socket
#

okay

jagged abyss
#

i am so confused

verbal dome
verbal dome
wooden socket
#

lemme change it rn

teal viper
wooden socket
verbal dome
#

Yes

wooden socket
#

lemme do that

verbal dome
#

I will let you do that

wooden socket
#

scoreText doesnt exist in the current context btw

rich adder
dense plume
jagged abyss
#

it's all just crashed and gone

#

i love unity sometimes

rich adder
#

why are you using the string from the text to get number...instead of just using the score from the ScoreManager instance

dense plume
#

This is...the same class you linked earlier

wooden socket
#

true, lemme pass it

dense plume
#

What exactly are you trying to accomplish?

wooden socket
#

i just want to pass it

dense plume
#

Pass what? To what? From what? Why?

wooden socket
#

i want to pass the score value to this script. its for a leaderboard

dense plume
#

How is this score created in the first place?

wooden socket
#

scoreManager gets the score from stuff in gameplay

rich adder
dense plume
#

Alright, good. The score is tracked in ScoreManager. THAT class would be more suited to contain the code in this "LeaderScore" class. Is this a singleplayer game you are trying to create a high score system for?

#

If so, score manager should handle this from start to finish. When your game reaches an end condition, the score manager should send the high score to whatever container is tracking high scores, be that a file, PlayerPrefs, etc.

#

On the other side, if you want to then display those high scores later, a Leaderboard class can retrieve that container and read scores from it to display.

#

Does this make sense to you?

wooden socket
#

yea, im just stuck at how to pass the value

#

its public and then like

#

scoreManager score?

olive fractal
#

having an absolutely agonizing time where using a dont destroy on load manager im trying to create a sprite on screen and it literally does not show up on screen when i instantiate the object. do i have to instantiate it as a child of the canvas or what? it says its instantiating but then the sprite itself doesnt show up

rich adder
#

you access it the same way you have accessed it in the UI text display

wooden socket
#

looking to that now

rich adder
#

nothing changes in c# how you access values in other objects

dense plume
wooden socket
#

i have that alreadyu

dense plume
#

And the scoremanager listens

#

and increments

wooden socket
#

ykw lemme send scoreManager

dense plume
#

So the score value can be private

wooden socket
rich adder
wooden socket
dense plume
#

Alright presumably you are calling this function directly from somewhere else?

wooden socket
dense plume
#

Method AddPoint()

rich adder
dense plume
wooden socket
#

im not purposefully ignoring. I TOLD you i was overtired from working on this game for over 18 hours. You ALSO flat out told me to "pick up a new hobby" that isnt extremely disrespectful??

rich adder
olive fractal
#

(should i... use another channel?)

wooden socket
#

also, this type of passing of values IS NOT the same from what I can tell, as its in an invoke

rich adder
#

.

wooden socket
#

TRUE

#

well wait so

olive fractal
wooden socket
#

it already says scoreText.text, but it SHOULD say scoreManager.score

olive fractal
#

would it be better for me to put this in general? its a weirdly trivial error

rich adder
verbal dome
#

I don't mind, it's just hypocritical

#

@wooden socket Did you do any C# beginner courses yet?

rich adder
wooden socket
#

well now the object reference is required for the non static field

rich adder
olive fractal
verbal dome
#

You need to reference the instance

wooden socket
olive fractal
#

like, ive never had anything like this happen before so my immediate thought was. i am missing something trivial and im stupid

rich adder
#

You did this is with the display text thats what Im saying , its nothing new here. The process is the same

wooden socket
#

okay so at the top I say public scoreManager right?

#

or public class scoreManager

verbal dome
rich adder
#

there is a static instance

dense plume
olive fractal
#

before jumping into a project solo with no experience

rich adder
#

it has been suggested multiple times

olive fractal
#

you can literally always come back to this when you have some knowledge of fundamentals

wooden socket
#

please just tell me this ONE small part of how to do this

#

this is the last error i have

dense plume
wooden socket
#

@rich adder what the hell is wrong with you fr

#

im just trying to learn and you are being a jerk

rich adder
rich adder
wooden socket
#

I AM

rich adder
#

remember earlier you said "i got this working now i go learn c#"

wooden socket
#

i want to learn how to do this so fucking badly man

polar acorn
rich adder
#

yet here we are

wooden socket
#

its just discouraging and rude

olive fractal
polar acorn
wooden socket
#

thats really rude

polar acorn
#

This is a gigantic waste of everyone's time

dense plume
polar acorn
#

If you are, by your own admission, unable to learn anything

#

why should we waste time trying to teach

wooden socket
#

im not unable to learn

#

i am saying

olive fractal
wooden socket
#

i dont know how to do this one specific thing

rich adder
#

this one thing relates to what was explained to you earlier..

polar acorn
wooden socket
#

i looked at the display text thing

#

and from what I can understand

#

and what you said I need to use a .

rich adder
#

do know what the . does ?

wooden socket
#

but im asking what I put on the left and right ends of it

wooden socket
rich adder
#

I'm geniunly asking and not even trying to be an ass.

olive fractal
#

oh girl you can not be asking character by character help

rich adder
wooden socket
#

because it didnt wpork

#

look

wooden socket
rich adder
wooden socket
#

well, I want to make it a string

rich adder
#

also you're not using the static instance

wooden socket
#

and when I do this

rich adder
dense plume
wooden socket
summer stump
dense plume
#

lel

rich adder
#

to display score as text

wooden socket
#

but its different

#

because look

rich adder
#

no its not

dense plume
#

🍿

wooden socket
polar acorn
#

just do that again

dense plume
#

Hey I am all down to help you, but we gotta focus here and stop arguing

polar acorn
#

you already know this

#

You did it already

summer stump
wooden socket
frosty hound
# dense plume 🍿

If you're not actively participating in anything productive, please don't comment.

wooden socket
#

i have been asking for help and multiple times its been you guys just being rude

#

its very discouraging and unhelpful

dense plume
summer stump
frosty hound
#

Make a thread then, and anyone who wants to sit through teaching the basics, can. Everyone else can choose to stay out of it.

summer stump
#

You need to stop and learn the basics

wooden socket
#

im trying to

summer stump
rich adder
#

"I just need this one thing"

wooden socket
#

and at the same time, you being rude REALLY isnt helpful

rich adder
#

yet we spoon fed you for 3 hours until it worked

summer stump
wooden socket
#

i know you think im stupid and as @rich adder said "pick up another hobby"

polar acorn
verbal dome
wooden socket
#

my only confusion is the parenthesis

dense plume
wooden socket
#

dude cmon

#

the error now is different

#

its about object referenes are required for the non static field

summer stump
#

You really, truly need to just take a basics course.
Have you done the w3schools or microsoft courses that have been linked? What about the !learn course?

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich adder
#

the error wont change if you don't do it properly 🤷‍♂️

summer stump
#

This is not rude. It is all that will help

wooden socket
#

and at the top, I tried putting public scoreManager score and it didnt work

summer stump
rich adder
summer stump
#

Also, score is a very misleading name for ScoreManager. Keep in mind that it is not the score itself. Just be careful

dense plume
#

You are trying to declare a class reference without initializing it if that's what you've written

#

Did you assign this field in the inspector?

rich adder
wooden socket
#

doing that now

rich adder
#

the static instance exist

wooden socket
#

well it is

#

it is static

rich adder
#

look the dam UI score..the syntax is there.

wooden socket
#

I DID

stuck palm
#

why isnt this screenshot working?

polar acorn
rich adder
stuck palm
# rich adder is that the path ?
if (frameIndex == 1200)
        {
            string fileName = Application.dataPath + "/ReplayScreenshots/Replay" + DateTime.Now + ".png";
            ScreenCapture.CaptureScreenshot(fileName);
            _replay.screenshotFileLocation = fileName;
            GameManager.Instance.SendNotification(MessageType.Info, "Screenshot taken");
        }
#

this is how i've done it

rich adder
#

you can't use : in a path

#

I don't think

dense plume
stuck palm
#

ah

wooden socket
polar acorn
#

it's right in front of you

#

you can just, like, read it

wooden socket
#

may have figured it out

stuck palm
#

changed it and it still doesnt work. is it because i havent created /replayscreenshots/ yet/

rich adder
dense plume
#

worth creating the directory first to see

stuck palm
rich adder
#

nah this is a .net/c# thing

#

unity has no control

alpine valve
#

I have a question about generating a graph for A* pathfinding in a 2D platformer.

My game world will not be represented purely by tiles. So Instead of having a "grid" of nodes and connections where a node is placed above each walkable tile in my scene, could I just generate nodes at the "start" and end of platforms? Like over their corners/vertices or something?

dense plume
# wooden socket may have figured it out

It seems by the sound of it...that the structure of your project is perhaps a little off. You should have a player object that does things. If it does a thing that earns a point, it should raise an event. This event should be listened to by the Score Manager class, where it will increment an integer. This integer can then be stored somewhere as a high score (file, playerprefs)

wooden socket
#

ykw im gonna be back later

rich adder
dense plume
#

Can you describe the current structure, the current logic flow of your game

wooden socket
#

what some of you did was very rude. i didnt like that at all and was very discouraged. sorry for not understanding, but there is no need to be rude

rich adder
#

everything everyone says is rude, are you 12?

dense plume
#

A professor in college would perhaps roast you even worse for this, tbh

wooden socket
wooden socket
#

ykw goodbye. im astonished at how unwelcoming this waas

dense plume
#

Can you answer the question I asked that will assist your issue?

polar acorn
wooden socket
#

i fixed it already

#

however

polar acorn
wooden socket
#

you didnt have to be dicks about it

rich adder
#

you're the rude one tbh you're projecting

frosty hound
#

@wooden socket You finally fixed it, move on.

stuck palm
#

when i do the ScreenCapture.TakeScreenshot thing, the game freezes for a split second. is it possible to avoid this by putting it in a coroutine or async or something

frosty hound
#

And now go do your promise of learning C# basics before your next question.

wooden socket
frosty hound
#

If you find yourself asking one, make a thread so we can avoid all this.

dense plume
frosty hound
#

I told you twice to make a thread, so you can deal with people only interested in holding your hand. You chose not to.

alpine valve
rich adder
dense plume
#

True

stuck palm
dense plume
#

@olive fractal did you fix your sprite issue?

rich adder
olive fractal
#

Okay, updated, shorter video, and I'll try to explain the bug this time.

Once again, please turn off audio before watching this, I'm working with some buggy audio files that are kind of painful to hear.

So, I'm just trying to instantiate a Sprite on the screen, using one of my managers (it's dontdestroyonload). The object is initializing properly but for whatever reason, it doesn't seem to have a sprite inside of it?

olive fractal
stuck palm
dense plume
#

Ehh it can also be Unity being slow about it, I like navarone's solution.

olive fractal
rich adder
stuck palm
#

only coroutines

#

no idea how it works

rich adder
#

if you used coroutine the concept is the same

#

except this is true async

olive fractal
rich adder
#

you should have no hiccups anyway you should be able to save file during play np

stuck palm
stuck palm
rich adder
dense plume
rich adder
#

you ideally want to avoid void as async method return type

#

oh comment went poof

dense plume
#

Yes I realized the brain fart there

rich adder
#

You can't use some event that uses Actions without using void 😛

olive fractal
#

😭

dense plume
olive fractal
dense plume
#

Yes

olive fractal
#

Okay, where I kept getting tripped up was, just feeding it a transform works? Feels weird syntactically

dense plume
#

Yeah or set the parent when you instantiate

#

Thats an overload

olive fractal
olive fractal
#

Ah, thanks!

dense plume
#

Object comma parent transform i think

stuck palm
# rich adder gotcha. makes sense

turned out pretty well 😄 i tend to write a lot of code before testing anything, for better or for worse, which makes it more satisfying when it all works first try

olive fractal
#

(I'll get back to you guys in like five...)

olive fractal
olive fractal
#

Are you writing a fighter?

stuck palm
stuck palm
#

the past week has been making my replay system actually work to begin with

stuck palm
olive fractal
#

Now you just gotta check if the videos turn out right when you watch 'em

stuck palm
olive fractal
olive fractal
stuck palm
dense plume
#

Does the class that instantiates the prefab know about the canvas?

stuck palm
#

yes i've accounted for that, each replay saves the seed of randomness so any RNG plays out exactly the same

olive fractal
stuck palm
#

thanks to @swift crag's suggestions im getting very close 😄

olive fractal
# dense plume Lets see some code

Right, this is a prefab...

public class EncounterManager : MonoBehaviour
{
    [SerializeField] List<GameObject> monData;
    public static EncounterManager instance = null;                //Static instance of GameManager which allows it to be accessed by any other script.
    public MonData enemy = null;
    [SerializeField] Transform canvas;

    void Awake()
    {
        //Check if instance already exists
        if (instance == null)

            //if not, set instance to this
            instance = this;

        //If instance already exists and it's not this:
        else if (instance != this)

            //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
            Destroy(gameObject);    
        
        //Sets this to not be destroyed when reloading scene
        DontDestroyOnLoad(gameObject);
    }

    public void ChooseEncounter(){
        enemy = null;
        GameObject m = monData[Random.Range(0, monData.Count)];
        MonData data = m.GetComponent<MonData>();
        if (data != null && m != null)
        {
            enemy = data;
            StartCoroutine(StartBattle(m,0.1f));
        }
        else
        {
            Debug.LogError("The selected game object does not have the specified script attached.");
        }

    }

    private IEnumerator StartBattle(GameObject m, float delay){
        yield return new WaitForSeconds(delay);
        secondBattleStart(m);
    }

    public void secondBattleStart(GameObject m){
        SoundManager.instance.efxSource.clip = enemy.cry;
        SoundManager.instance.efxSource.Play ();
        Instantiate(m, canvas);
    }
    
}
dense plume
#

And what exactly does the error say? You've got a console message?

olive fractal
#

No error, just that the image doesn't appear (see video)

dense plume
#

You said it gave a type mismatch?

olive fractal
#

I at least know it IS instantiating, but there's clearly an image visible in the prefab and then it's not visible after 😐

alpine valve
# rich adder nah this one https://github.com/h8man/NavMeshPlus

I could be misunderstanding something important here, but I think the problem with this solution is in a platformer game context it would create a mesh where the whole scene (-any obstacles) is a big walkable mesh. So it would only work for flying enemies? That's why I came up with my original proposal of nodes on the "start" and "end" of platforms like this. (greatest diagram ever lmao)

olive fractal
dense plume
#

Oh, don't do that

#

attach the gameobject that the canvas is on

#

it will pull the transform

#

What you're assigning is a transform

rich adder
dense plume
#

not the canvas component itself

olive fractal
#

No, I attempted that

#

It won't even pull the transform on this 😐

dense plume
#

ooooh

#

You can't assign a scene object to a prefab field

#

These things exist in different contexts

#

You'll need some way to find this canvas transform when you spawn the encounter manager

olive fractal
#

oh god, what's the workaround, then? Should I like

find_object_of_type<Canvas>()
parent = canvas

#

because theres only one canvas in scene ever

dense plume
#

Yes, it's kind of...bad, but yeah

olive fractal
#

its certainly special. lets see if it cooks, haha

dense plume
#

Why can't you have the encounter manager already in the scene?

alpine valve
olive fractal
#

im really early in dev, so honestly, yeah, its not like im going to have to use it outside of here. ill just spawn one every time i change to the battle scene

#

wait i literally dont even have to, nvm

dense plume
#

oh, don't do that, make it dontdestroyonload and make sure you use a "zero" scene

#

Singletons being created an destroyed for each scene will make hell for you later

#

or, just use the same battle scene for every battle and spawn what you need, but have the encounter manager already in there

queen adder
#

yo I needa cook something up on unity (in the next 22h) for a college assignment, Ive never used unity before and I got no idea what tf im doin I just downloaded unity. Please someone tell me where to start 😭 🙏

dense plume
#

Oh dear

olive fractal
queen adder
dense plume
#

It's great fun really

queen adder
#

I needa make like a top down 2d racing game kinda thing I guess 🤔

dense plume
olive fractal
olive fractal
rich adder
#

now you got a car

olive fractal
dense plume
#

Nice I do like what I see in the video there very classic looking

olive fractal
dense plume
#

Yeah definitely have a battle scene with all the "scaffolding" already in place

olive fractal
#

its got some nice 2d movement. very smooth

dense plume
#

then fill in the blanks with context for the battle

#

Anything that will be there every time should be in the scene

placid flax
#

hey, I'm trying to make a shooter game but I can't firgue out how to make the ammo count on my HUD work, does anyone got some methods I can use?

dense plume
#

Well, what have you tried?

placid flax
#

I tried a bunch of different functions for getting the ammo count from my gun script to mu hud script but none of them have worked and I can't find any videos on it for the life of me that work

olive fractal
#

thanks snif

dense plume
#

Easiest way is to reference this "gun script" in the hud script

olive fractal
dense plume
queen adder
#

Hey say I wanted to make something like this - https://youtu.be/vF9R7dhHJCw?si=HnbWRz3wHFSgFbpt

What's up guys !

In this video, we are going to make a car racing 2d game which we used to play in our childhood.

Download Game from Playstore: https://play.google.com/store/apps/details?id=com.SanitTech.StreetRacing2D

Road Sprite: https://sanittechcodes.blogspot.com/2022/08/street-runner-2d-in-unity.html

Playlist Link: https://www.youtube....

▶ Play video
#

^ which one of these would I use 😭

placid flax
queen adder
#

so idk

dense plume
#

Hud script should have something like public GunScript gunScript; near the top, inside the class braces, then assign this in the inspector. Make sense?

queen adder
placid flax
#

so I can just make a var?

olive fractal
#

and then in the code, hudText.text = gunScript.bulletVariable

dense plume
placid flax
#

jeeze, ight thanks man 🙂

dense plume
#

You should be able to follow the tutorial regardless. Those are render pipelines and dictate how the game is rendered under the hood. Not something you should be concerned with as a beginner

rich adder
queen adder
rich adder
#

also URP is prob overkill in 2D unless you need lights

astral basin
#

i have an android project and when the resolution is 18:9 everything works well but when i set it to my phone resolution only one image gets weird, what is causing this and how can i fix it?

dense plume
#

Sorta looks like you've linked the same image twice

#

Both say 18:9

astral basin
#

oh my bad one sec

#

thanks

dense plume
#

Alright I'm not crazy, lol

#

Make sure you've got anchors and pivots set right on that image component (assuming this is all UI canvas stuff?)

astral basin
#

how do i find these anchors and pivots things

#

that you are talking about

dense plume
#

RectTransform component on the object

#

Top one, can't miss it

astral basin
#

it should beon 0.5?

dense plume
#

Alright it doesn't say it's set to stretch or anything right?

astral basin
#

someof my components are different

dark sluice
#

so i have a camera following a falling ragdoll (the player) but the camera is shaking crazy because its following a falling ragdoll, anyway to get it to shake less? (ive tried using a empty follow object that follows the ragdoll and the cam follows that but same output 😦 )

dense plume
#

screenshot the whole recttransform component

astral basin
dense plume
astral basin
#

what about it

dense plume
#

Says stretch on box axes