#💻┃code-beginner

1 messages · Page 841 of 1

swift crag
#

Okay, so you know which way the character is moving, presumably.

#

because you're moving the character

wild fox
#

I mean, I guess?

swift crag
#

I sure hope you do!

#

given that, you can figure out if you're going left or right

naive pawn
#

you get a float, and if it's positive, that refers to the right direction, and if it's negative, it's leftwards (by convention in unity)

changing input systems only changes that very first part, getting the float

swift crag
#

show us how you are moving the character

wild fox
#
public class PlayerMovement : MonoBehaviour
{
    public float velocidadeMovimento = 20f;
    private Rigidbody2D rb; 
    private SpriteRenderer spr;
    private Vector2 direcaoMovimento;
    private InputAction iact;

    void Start() 
    {
        rb = GetComponent<Rigidbody2D>();
        spr = GetComponent<SpriteRenderer>();
        iact = InputSystem.actions.FindAction("Move");
    }

    // Update is called once per frame
    void Update() 
    {

        rb.linearVelocity = direcaoMovimento * velocidadeMovimento;
        rb.linearVelocityY = -velocidadeMovimento;

        if ()
        {
            spr.flipX = false;
        } else if ()
        {
            spr.flipX = true;
        }
    }

    public void movimento (InputAction.CallbackContext context)
    {
        direcaoMovimento = context.ReadValue<Vector2>();
    }
}
swift crag
#

a Vector2 is made of two parts: X and Y

wild fox
#

the second linearVelocity is to make the character fall, idk if it's the best way of doing that but it was the one I found

swift crag
#

e.g. direcaoMovimento.x is the horizontal part of the player's input

wild fox
#

ah

#

got it

naive pawn
wild fox
#

yea it works

#

is there a better way to make the character fall then the rb.linearVelocityY with the negative movement speed?

naive pawn
#

this being in side-scroller view?

wild fox
#

Yes

naive pawn
#

you could just have it fall with gravity

#

you would only assign the X velocity

wild fox
#

how do I do this?

naive pawn
#

well.. you would only assign the X velocity, like how you're only assigning the Y velocity on the second line there

wild fox
#

ah, okay

naive pawn
#

you might also want to change your input actions to be a 1D input, if you only use horizontal input (though there are considerations to be made there regarding how you want to control your player overall - how jumping works, what W/S do, etc)

wild fox
naive pawn
#

yes

wild fox
#

sure

wild fox
#

also, if there a way to force Unity to recompile stuff? Because most of the time it doesn't when I make a change to the code in the script

naive pawn
wild fox
wild fox
naive pawn
#

oh and make sure you aren't resetting the Y velocity to 0 in some way

#

what's your current code?

ivory bobcat
naive pawn
#

what platform are you on? i recall linux reportedly having some watch issues

wild fox
wild fox
# naive pawn what's your current code?
public class PlayerMovement : MonoBehaviour
{
    public float velocidadeMovimento = 20f;
    private Rigidbody2D rb;
    private SpriteRenderer spr;
    private Vector2 direcaoMovimento;

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

    void Update() 
    {

        rb.linearVelocity = direcaoMovimento * velocidadeMovimento;
        rb.linearVelocityY = -velocidadeMovimento;

        if (direcaoMovimento.x > 0)
        {
            spr.flipX = false;
        } else if (direcaoMovimento.x < 0)
        {
            spr.flipX = true;
        }
    }

    public void movimento (InputAction.CallbackContext context)
    {
        direcaoMovimento = context.ReadValue<Vector2>();
    }
}
naive pawn
# wild fox What you mean?

make sure they aren't like, overly big. that could cause them to appear to fall too slowly
your player character should be like, 1-2 units

naive pawn
naive pawn
# wild fox Linux

might have to disable automatic asset refresh and refresh manually

wild fox
naive pawn
#

yeah that's fine then. the issue is that you're still resetting vertical velocity

wild fox
naive pawn
naive pawn
# wild fox how exacly?

you're assigning to velocity/velocityY still. if you want it to fall according to gravity, you need to not change Y at all

wild fox
naive pawn
#

it seems like you just haven't written code that would let gravity work normally yet

wild fox
#

Maybe, I'll leave it like that for now and continue to follow the course I'm doing

naive pawn
#

ok but why not just fix it now

#

what's your current code

#

that supposedly doesn't assign to Y and needs high gravity

wild fox
naive pawn
#

ok so you don't need to make gravity absurdly high, you just need to change the code to not assign to Y like ive been saying

#
+       rb.linearVelocityX = direcaoMovimento.x * velocidadeMovimento;
-       rb.linearVelocity = direcaoMovimento * velocidadeMovimento;
-       rb.linearVelocityY = -velocidadeMovimento;
```just that change, or a little different if you changed the input to be a 1D axis
naive pawn
#

what, the code?

#

i just showed you an example...

wild fox
#

no I mean with the 1D thing

#

oh wait, I already have it like that

naive pawn
#

(though as mentioned before, you'd need to consider whether you want W/S to do anything)

wild fox
#

Eh I think it's fine this way

wild fox
keen bridge
#

Hey, I was never able to resolve this issue. Does anyone have any ideas?

teal viper
#
  1. Use logs. Or debugger + breakpoints.
  2. It doesn't help knowing that MoveTo runs as we have absolutely no idea as to what code it contains...
#

Nor what value is being passed to it.

keen bridge
#

oops, I have gotten wildly confused. MoveTo was actually the method I made. (I don't know how I forgot about that...), but I was getting it conflated with another engine I was trying out last week, which uses "MoveTo", so I thought i was calling the agents move method, but I was not haha. I've found the issue now, thanks for pointing that out lol

compact sundial
#

so im trying to set the owner of a projectile but it says type mismatch

#
GameObject Projectile = Resources.Load<GameObject>(GlobalManager.Constants.LightningBolt_VersionOne_Path);
        Projectile.SetActive(true);
        Instantiate(Projectile, handTransform.transform.position, Quaternion.identity).transform.rotation
        *= Quaternion.FromToRotation(Vector3.down, this.gameObject.transform.forward);
        LightningBoltScript script = Projectile.GetComponent<LightningBoltScript>();
        GameObject playerModel = this.gameObject;
       PlayerController controller = playerModel.GetComponentInParent<PlayerController>();
       script.owner = controller.gameObject;
slender nymph
#

!code

radiant voidBOT
compact sundial
#

I was holding shift lol

#

its been a bit since I did that

slender nymph
#

what is the exact error you are receiving

compact sundial
#

I am setting it after I create the projectile

#

but its wrong ig

slender nymph
#

sounds like you're trying to access it before you are setting it. what is the stack trace of that exception?

compact sundial
#
UnassignedReferenceException: The variable owner of LightningBoltScript has not been assigned.
You probably need to assign the owner variable of the LightningBoltScript script in the inspector.
UnityEngine.Object+MarshalledUnityObject.TryThrowEditorNullExceptionObject (UnityEngine.Object unityObj, System.String parameterName) (at <1e74f08236fb4c1791a523c0bf197e6c>:0)
UnityEngine.Bindings.ThrowHelper.ThrowNullReferenceException (System.Object obj) (at <1e74f08236fb4c1791a523c0bf197e6c>:0)
UnityEngine.GameObject.GetComponentFastPath (System.Type type, System.IntPtr oneFurtherThanResultValue) (at <1e74f08236fb4c1791a523c0bf197e6c>:0)
UnityEngine.GameObject.GetComponent[T] () (at <1e74f08236fb4c1791a523c0bf197e6c>:0)
LightningBoltScript.Awake () (at Assets/Prefab Scripts/Spell Scripts/LightningBoltScript.cs:17)
UnityEngine.Object:Instantiate(GameObject, Vector3, Quaternion)
AnimationListener:SpawnLightningBolt() (at Assets/AnimationListener.cs:86)
slender nymph
#

okay so it looks like it's actually happening in LightningBoltScript.Awake () which explains why this is happening. Awake is called before Instantiate even returns so whatever you are doing in Awake is happening before you assign to the owner variable. Best thing to do would be to extract what you are doing into another method that you call when you assign the owner variable

compact sundial
#

would start work?

slender nymph
#

i mean, sure, but the better option is still to just call a method that is doing whatever you need it to after you instantiate it

#

you can pass the reference to the method so owner can be set inside that method. this would allow you to make owner a property that has a private setter so that only that specific method can assign to it from outside that object

crystal agate
#

Hello, how do I fix this bug?

slender nymph
#

Ability[] is an array, perhaps you mean to call GetComponent<Ability> rather than GetComponent<Ability[]>

crystal agate
#

i do mean to get an array from the other script

slender nymph
#

and yet an array is not a component

crystal agate
#

this happens if I remove the []

slender nymph
#

GetComponent will return one component. if you want it to return an array of components then you must use a method that returns an array

crystal agate
#

ahhh okay thank you

slender nymph
#

and keep in mind the bit between the <> is the type of component, so it will never be an array there, even for the method that returns an array

crystal agate
#

in that case how do I get an array from a different script?

#

this happens if I do GetComponents<Ability>

slender nymph
#

does enemyUnit and/or playerUnit have one or more Ability components? or are you trying to reference some other component that happens to have an Ability array on it?

teal viper
#

The error is not from the get component

teal viper
slender nymph
#

this is not an Ability component, this is a Unit component that has an Ability array. if you're trying to get the array then you need to first use GetComponent to get that component, then you can just access the abilities array from that reference

crystal agate
slender nymph
#

since enemyUnit and playerUnit are already references to that Unit component, you just need to access the array on those properties. GetComponent is not used to access a component's variable

teal viper
crystal agate
compact sundial
#

so apparently the set in this function causes a stack overflow

private GameObject owner;
[SerializeField] public GameObject _owner 
{
    get {return owner;} 
    set
    {
        _owner = value;
        owner = _owner;
    }
}
slender nymph
#

why have you done this?
also yes, that causes an overflow because your setter calls the setter which then calls the setter

compact sundial
#

oh

#

oops

#

I have no response

slender nymph
#

you don't need that setter there at all. just use a method like i said

teal viper
# crystal agate the b1Text.text one

Great, then that's where the error is. Likely because you're accessing an index of an array that is smaller than the index number. That's literally what the error says.

#

And yeah, I recommend learning to read the errors. It tells you the exact file name and line number of the error too.

compact sundial
#

im still having trouble, idk what to do

public void SpawnLightningBolt()
    {
        GameObject Projectile = Resources.Load<GameObject>(GlobalManager.Constants.LightningBolt_VersionOne_Path);
        Projectile.SetActive(true);
        GameObject projectileInstance = Instantiate(Projectile, handTransform.transform.position, Quaternion.identity);
        LightningBoltScript script = projectileInstance.GetComponent<LightningBoltScript>();
        GameObject playerModel = this.gameObject;
        PlayerController controller = playerModel.GetComponentInParent<PlayerController>();
        Debug.Log("controller = " + controller);
        script.setOwner(controller.gameObject);
    }
slender nymph
#

are you still receiving the same error? or are you having trouble with some other part now?

compact sundial
#

wait I think I messed I see how to fix it. one sec

#

ok owner is no longer null but something else is wrong

#

I thought if owner was set I could get a reference to its mesh collider

#

but its not ignoring the collision

#
boltCollider = this.gameObject.GetComponent<BoxCollider>();
Debug.Log("owner = " + owner);
meshCollider = owner.GetComponent<MeshCollider>();
Physics.IgnoreCollision(boltCollider, meshCollider, true);
StartCoroutine(DestroyThis(5));
#

this is in start

verbal dome
compact sundial
#

yes I have the mesh collider on the owner and the box collider on my projectile prefab

verbal dome
#

Also are you using a trigger or just solid colliders

compact sundial
#

I know it works because I have ontriggerenter destroying the object once it collides with another

#

with Destroy();

verbal dome
#

Not sure if IgnoreCollision affects triggers. Likely not

compact sundial
#

oh

slender nymph
#

probably not since triggers don't collide

compact sundial
#

weird cuz I have the projectile spawning inside the player while I figure out collisions and as soon as it spawns it destroys itself

verbal dome
#

If you want to use a trigger then just check in ontriggerenter if the other object can be hit by this projectile, or use layers

slender nymph
#

well Trigger messages still happen with trigger overlaps. this is not a collision though. but if the object already has a reference to the collider it shouldn't be interacting with then a simple if statement will be enough

compact sundial
#

oh ok ill try it

slender nymph
#

also i'm curious why that code is in Start, wouldn't it make more sense to have put it inside that setOwner method?

compact sundial
#

ig so

slender nymph
#

i mean, that was the point of creating that method, no? to move the code that depends directly on setting that variable into it

verbal dome
slender nymph
#

in that case, i think it's just an oversight in naming the matrix since it does affect triggers and collisions. should have called it something like "layer collider matrix" instead

verbal dome
#

Right, thats my point - who knows if IgnoreCollision is "badly" named too, i can't test right now though

brazen oak
#

If your tryna learn code where should I start

#

i know somethings

#

but not a lot

verbal dome
#

@slender nymph Just wrote a lil test script and IgnoreCollision does affect OnTriggerEnter.
@compact sundial Seems like it being a trigger is not the issue

#

The OnTriggerEnter was probably getting called before Start, so the ignore happens too late

#

Let's just accept that unity counts trigger interactions as "collisions" in a lot of its terminology and not be pedantic about it

valid heath
#

is it possible to run a function once all of a specific type of object are done instantiating? I have a bunch of objects that need to all exist before the function is run but rn it's having a race condition because it runs before all of them are done instantiating

#

Actually wait I haven't used Awake

#

lemme try that

#

Hm that's not working for some reason

#

there are definitely alternative ways around this but its easier to see if I can do it this way

verbal dome
valid heath
#

per object

#

I need to wait until all of the objects are initialized and then call the function on all of them

verbal dome
#

Start should work here

valid heath
#

because the start method adds the object to an array in a singleton, and then calls the function after

#

and the function depends on everything being in the singleton's array

valid heath
verbal dome
#

Add to array in Awake, do other stuff in Start

#

Start won't run before all Awakes have run

valid heath
#

I tried that but it gives an error

verbal dome
#

Or whatever is instantiating them can also add them to thet array

verbal dome
valid heath
#

NullReferenceException: Object reference not set to an instance of an object
PlayerPiece.Awake () (at Assets/Scripts/PlayerPiece.cs:46)

Right now I'm not instantiating them, I just have them on the scene for testing purposes

#

if I were instantiating them that would be easier to handle this

#

but its a lot easier to test this way

verbal dome
#

So something is null in that line in Awake, or in one of the methods you call there

#

Are you sure that BoardController.Instance exists at that point?

rich adder
#

most likely setting up also in awake and this script is running first

valid heath
#

yeah

rich adder
#

so just access it in Start

valid heath
#

That doesn't work though because it needs to run after all of the other objects are instantiated (the Start method of all other objects of the same type has run)

#

is there something like Start that runs after Start?

verbal dome
#

You could set the singleton's execution order to a lower value so its Awake always runs first

#

(Or make Start an IEnumerator and wait for end of frame but that feels hacky)

#

Could be fine though

valid heath
red ivy
#

My navmesh agent path is saying its complete when it should not be what can I do about that? It seems that something is wrong because its constantly saying path complete.

#

it recalculates, path complete and thats a loop it goes into

undone rampart
#

PathComplete means that the path to your point has been successfully calculated, not that the agent has reached the destination

red ivy
red ivy
errant breach
#

Hello, i have a little question.
Whenever this part of the code is called, my gameobject stop being affected by gravity which is an issue.
I tried looking for gameobject not affected by gravity while moving unity, but i got nothing.

Can someone please help me ? Thanks !

naive pawn
#

so it stops the acceleration from gravity every frame

#

use the current Y velocity there instead to let gravity accumulate

errant breach
#

Thank you ! It was obvious i guess... How can use the current Y velocity parameter please ? I tried putting owner.y but it obviously didn't worked well..

#

Nvm i think i founded it online with the unity's website 😅

naive pawn
#

you're reading it back right after in the debug log

errant breach
#

That... Is also true... TwT

#

IT WORK ! 🥳

#

Thank you as always Chris 🫶

naive pawn
burnt vapor
#

Because FYI, Unity will track the Update method. Even if disabled it's added to the queue. It's somewhat negligible, but it still adds up and this is easily avoidable by not adding an empty body everywhere (assuming it's empty). If you keep doing this with thousands of objects it can make a difference.

#

Better to just add the Update method where needed, just like everything else.

errant breach
#

Hey @burnt vapor, thank for taking the time to ask me that.
I do it because we are doing a group project, and the best dev proposed me to use "State machine" and other thing that i never heard of before. So i have a enemy state manager like that.. And he told me to override the function (there was error before i did it)

Do you think it's not the great way of doing so ?

burnt vapor
#

Does the code actually do anything or is it all boilerplate just in case?

#

I'd feel like it's better to have a main Enemy manager that tics and then calls an update on all enemies when it matters, instead of having each enemy do their own work.

topaz gorge
# errant breach Hey <@191282187016863744>, thank for taking the time to ask me that. I do it be...

Very much depends on the variance of enemy's, how different they should be have. You can have a statemachine built into a scriptable object format that work really well for animation variants and attacks, roaming ect. While calling update constantly on these enemy's might not be the greatest idea, definitly like he said use a single update to update a enemy type, you can use more updates per enemy type or multi thread it. But also depends if this is for a multiplayer game so.

topaz gorge
burnt vapor
#

According to the blog post, a manager like I mentioned might even improve performance by itself apart from being easier to use.

grand snow
burnt vapor
#

That does make a lot of sense

#

Probably better to minimize it where you can

grand snow
errant breach
#

Alright guys, i'll go and talk with him in order to code better ! Thank for taking your time in giving observations and advices ! 😆

#

By the way, i need help with RayCast now..
So basically, i want to prevent my AI's to fall of ledges.
So ive writted this :

        {
            Debug.Log("An empty floor as been detected !");
        }```
*(note that ive put the "Walls" layer to my... Floor. Because why not)*
Yet the Debug.Log is always printed !! Do someone knows a bit about Raycats and could help me please ? :( Thank !
keen dew
#

Do the yellow lines show the raycast? If it starts inside the collider (which might happen if the character's pivot point is at the feet) it won't detect the collider

#

You could try to start the raycast a bit higher (transform.position + Vector3.up * 0.1f)

errant breach
#

Yes @keen dew it does !
I tried everything 😅 including putting the raycast wayyy above, and putting a giant floor all around... It still print :(

keen dew
#

I'm not sure what that screenshot is supposed to show? Those lines definitely look like they're completely inside the floor

errant breach
#

Exactly ! Yet Unity send the ""An empty floor as been detected !""

keen dew
#

Yes but if the raycast starts inside the collider it won't detect it

#

If the lines are completely inside the floor then it's expected that they won't detect it

topaz gorge
errant breach
# topaz gorge Explain your situation a bit better, i can definitly help

Oh, alright, thank you !

So, i want to make a RayCast that will check if there's a floor below the AI, if yes, print :

  • Debug.Log("No empty floor detected !");
    if no :
  • Debug.Log("An empty floor as been detected !");

So here's the code that manage the detection ;

Here's the line that call the function :

  • owner.Roots.GetComponent<RayCastLedge>().CheckForFall(3f, owner.layersToCollideWith);
    And here's the entire code of my Enemy. it is a state Machine :
  • https://pastes.dev/HmkR4psd0v

Im actually doing a few test because all of the sudden, it kind of seems to work. Once i'll dig more and have news, i'll let you know !

topaz gorge
errant breach
#

Hmm never heard of that. I'll check on the web then thanks !

topaz gorge
topaz gorge
#

To predetermine that kind of thing you only really need 1 raycast in there forward direction, a offset for how close they should be able to get to the ledge, and a raycast height, for if you want them to be able to drop off a certain ledge height if it finds ground.

topaz gorge
grand snow
#

ah yea thats better suited when no sweeping is required

#

best to send those links!

topaz gorge
real thunder
#
        ref int nex_spawn_time = null;
        GameObject[] mobs;
        int max_alive;
        float cd;
        if (is_boss)
        {
            max_alive = max_amount_of_bosses_alive;
            mobs = existing_bosses;
            nex_spawn_time = next_boss_spawn_time;
            cd = boss_spawn_cd;

        }
        else
        {
            max_alive = max_amount_of_normal_mobs_alive;
            mobs = existing_normal_mobs;
            nex_spawn_time = next_normal_mob_spawn_time;
            cd = mob_spawn_cd;
        }
        nex_spawn_time += cd;
//spawning code here

I hope you get it what I try to do, to make a reference int variable, but it doesn't work like that, what am I meant to do?
I can just put is_boss check later to determine what to use but I feel like that would be less clear

topaz gorge
topaz gorge
real thunder
#

next_boss_spawn_time and next_normal_mob_spawn_time
are out of scope

#

I mean they are not within method and I want to increase their value

#

I dunno maybe that would make most sense to insert all those variables as method parameters

#

still I am curious

#

what if I want to make a reference variable for a non reference type

#

I could make a property but it feels overkill

topaz gorge
real thunder
#

if it won't be ref I would change the variable inside method

#

but I want to change variable outside of the method

#

if it was a reference type variable it would work out

topaz gorge
keen dew
#

The issue is a symptom of bad code design

real thunder
#

I suspect that

topaz gorge
#

Well blunty yes

#

XD

keen dew
#

If you have variables like normal_spawn_time, boss_spawn_time etc they should be bundled into a class, then you wouldn't have any issues with references

real thunder
#

I thought that making a class if I just have 2 types of enemies excessive

#

tho I am not sure I understood what you meant

keen dew
#

Trying to get around it by changing individual int variables with references is much more excessive

topaz gorge
real thunder
#

who defines what is proper

topaz gorge
keen dew
#

If you put the variables into a class (let's say called Enemy) then you can just do

Enemy enemy = is_boss ? boss : normal;
enemy.spawn_time += cd;
#

or just pass it directly to the function

real thunder
topaz gorge
#

Proper code is typically pretty fluid and expandable without much headache.

real thunder
#

but bosses and regular mobs had different values for that

#

I just went making 2 separate but identical code pieces and it worked
now I am trying to merge

keen dew
#

Right, and the idea for merging them is to make a class that holds those values

#

and having two instances of the class, one for the bosses and one for the regular mobs

#

It could even be a ScriptableObject

topaz gorge
burnt vapor
#

There's very little reason to do this. if your concern is references then there's probably an easier way than to instantiate a reference for a value type

#

It sounds like you just need to turn it into a class-scoped variable, or at worst make it static. But it's hard to say with the example

#

A ScriptableObject sounds the most reasonable, though

real thunder
#

won't cut it but I now tried to make it a class and it looks... neat

burnt vapor
real thunder
#
    public class EnemyGroup
    {
        public WeightedItems mobs_and_weights;
        public int left_to_spawn;
        public float spawn_cooldown;
        public float nex_spawn_time;
        public GameObject[] existing_ones;
    }
#

I am not sure what state means

burnt vapor
#

So basically a ScriptableObject, lol

real thunder
#

is it?

real thunder
#

next_spawn_time is constantly changing

burnt vapor
#

That's fine, you can edit the data. It just doesn't persist when done from a script (which I'd argue is exactly what you want here)

real thunder
#

tho all of those values would be changed inbetween different setups of the game

#

script can change SO it have without affecting other SOs like it?

sonic vapor
real thunder
#

I suppose it's more of a physical problem

earnest raven
#

what the friggity diggity should I use if not RigidBody

Assets\Scripts\Enemy\EnemyBase.cs(42,13): error CS0246: The type or namespace name 'RigidBody' could not be found (are you missing a using directive or an assembly reference?)

private RigidBody rb;

#

nvm it's Rigidbody, not RigidBody

burnt vapor
frosty hound
#

What the friggity diggity indeed

burnt vapor
frosty hound
#

!ide for instructions

radiant voidBOT
earnest raven
burnt vapor
#

Your IDE can often suggest a similar word (e.g. Rigidbody) and the necessary namespace to include if needed

earnest raven
#

it didn't show as an error in the IDE, and didn't show me quick actions

#

but thanks anyway

naive pawn
real thunder
#

huh I just checked what would mine do and it just replaced RigidBody with Rigidbody without telling me

#

I can see myself forgetting wordings

ivory bobcat
hollow cradle
#

Is it ok for me to not memorize a code? I know how it works but i cant memorize it, I often look at my code screenshot when i code

naive pawn
#

it's ok to look at what you've written before, it'll take time and practice to really internalize it

#

try challenging yourself to rely on it less (not necessarily banning yourself from checking though)

hollow cradle
naive pawn
#

as in, the syntax?

hollow cradle
#

Yea

naive pawn
#

ah yeah that part will also take time in its own right

#

there will be some parts that you need to memorize, like how specific keywords are spelt or how a for is formatted
overall there will be some rules of thumb you can use though, like x() for functions and {} for groups (blocks/bodies)

real thunder
#

meanwhile I don't remember how for and foreach work because IDE autocomplete them

#

well not work, look

hollow cradle
real thunder
#

soon I ll start to feel like I am a vibecoding llm

waxen jasper
#

Guys i just started learning unity to start a game I’ve made in Python but want to convert to unity. Will a lot of my programming skill transfer and how important is programming (how much will I be using built in unity features vs coding)

naive pawn
waxen jasper
#

I’m not too worried about c# as a lang because I know around 6 languages pretty well so I’m used to learning some new syntax/concepts

#

But like how much of developing in unity is coding

#

Is it Almsot all of it

#

Is it 50/50

#

Or are you mostly using tools in the engine

waxen jasper
grand snow
solar hill
#

making a game is mostly coding

#

this is true for any engine

waxen jasper
solar hill
#

i mean the Unity API is pretty robust and comes in with certain built in things, like physics rendering etc.

#

you still need coding to access these features

waxen jasper
#

So you spend more time in a coding environment than the unity engine window?

solar hill
#

not nescessarily

waxen jasper
#

Well that’s kind of what i want to know, how often are you using the tools unity has in the window vs writing code elsewhere

#

Like let’s say you wanna put some text on the screen

solar hill
#

that also depends

waxen jasper
#

Are you doing that in the unity engine window

solar hill
#

are you using UGUI or UI toolkit for example

waxen jasper
#

Or through code

solar hill
#

both are possible

waxen jasper
solar hill
#

i mentioned them as an example

#

that the answer to your question is really just "depends"

#

but you will be in editor a lot and you will be coding a lot

#

that is certain

cosmic quail
waxen jasper
cosmic quail
waxen jasper
waxen jasper
#

Thank you

real thunder
grand snow
naive pawn
real thunder
#

yeah I mean the way for looks
for (int i = 0; i < group.existing_ones.Length; i++)
feels like there have to be ,

naive pawn
#

ah for that one, they're separate clauses

#

think about how , could be ambiguous within each individual clause

#

int i = 0, j = 0 is valid as an initializer
a < b, b < c is valid as a condition (though not particularly meaningful)
i++, j++ is valid as an increment

#

also in that, for is basically syntactic sugar for a while with some extra bits, they're all used in separate places

real thunder
#

a < b, b < c out of those 3 doesnt seem to be valid

#

other 2... first I nevers saw being actually used but makes sense, last, why does , works instead of ; while those are two separate instructions?

#

i++, j++, why

naive pawn
#

the comma operator is also used in the last one

#

it only really makes sense when the non-last expressions have side effects, hence why they aren't really meaningful in the condition part

#

something like i++, i %= 10 might be more useful

real thunder
#

I mean 2d can't compile

#

as for 2 increments with comma inbetween
it seems that comma inbetween statement expressions is inique to loop declarations

#

I never knew

naive pawn
#

other c-family/style languages do, like c/c++ and js

#

(which, C is where the for loop syntax is from)

real thunder
#

reading about it it looks kinda useless in a sense u can just call left before checking right

naive pawn
#

sometimes you want things in expression positions

stuck palm
#

How can I programmatically test multiple displays in unity? I try setting the target display for a camera in code and it doesn't work. it seems to only work if I do it manually in the inspector

stuck palm
#

unless I'm missing something

grand snow
#

I don't know if this can be done via code

stuck palm
#

in the Display.displays list

rich adder
#

oh thats odd. I guess you'd have to use built exe to test

deep bolt
#

not super familar with stuff like additive loading but is it known to fuck with cinemachine???

rich adder
#

not really but we cannot answer specifically without knowing more

swift crag
#

you might be winding up with two Cinemachine Brain components active at once (controlling two separate Cameras)

deep bolt
#

im like in scene 1 , additively load scene 2, then from scene 2 i load scene 3 & unload everything else, and once im done with scene 3, i load scene 1 and additvely load scene 2 again and i think the code works but any cinemachine gameobjects completely dissappear

#

im like spawning the player back into scene two and its working all except for the fact taht the camera just disappears but the main camera stays

#

scene 2 has no cinemachine or base camera

#

idek what could possibly cause this

crystal agate
#

Is it possible to instantiate a UI button at an x, y position?

#

I'm trying to do a turn-based RPG and currently trying to do a targeting system where, after I choose an ability, buttons appear on screen to let me choose a target

#

if it's a single target for enemies, the buttons appear over enemies, if it's aoe it's one big button, and if it's self-targeting the button appears on the player character

#

or would this be better with game objects rather than UI

rich adder
rich adder
deep bolt
#

yeah

crystal agate
solar hill
#

thats the same thing

rich adder
deep bolt
#

the game object the cinemachine component is on just completely dissappears from hierarchy

#

and the cinemachine brain seems no long hooked up

rich adder
deep bolt
#

i mean but im loadingit back in though?

crystal agate
rich adder
deep bolt
#

there arent new ones though </3

slender nymph
#

sounds like maybe you've got a singleton that is destroying extra copies, but without actual context it is hard to tell

rich adder
#

are you certain they were part of that scene in the first place ? without seeing the complete setup is hard to tell

deep bolt
#

uh yes i think?

slender nymph
#

if it's DDOL the one that survives would be in the DDOL scene. but of course you still haven't shown context so it's only a guess

rich adder
# deep bolt

instea of name , search by component t:CinemachineCamera

deep bolt
slender nymph
#

we need more context, like any relevant code. also the scene appears to be unsaved, are you certain that object exists in the saved version?

deep bolt
#

oh ok

slender nymph
#

!code

radiant voidBOT
deep bolt
slender nymph
#

and, again, are you certain that the object that is missing is in the saved version of the scene? if you haven't saved the scene since adding it then it is not so when the scene is loaded from disk it only loads what has been saved

deep bolt
#

yes

slender nymph
#

okay, i'm only confirming this because the scene was not saved in the screenshot you provided above. but just as a precaution you should make sure you do save it just in case

deep bolt
#

aye aye

#

oh wait the formmating for the paste is kinda strange

slender nymph
#

there's also nothing in that code that would destroy an object (other than ones being destroyed by unloading the scene) so this may not be all of the relevant code. does that Cam object have any other components besides the CInemachineCamera one?

deep bolt
#

uhh yes but its just for perlin noise though it is a singleton

slender nymph
#

well i did already point out that the issue could be caused by it being a singleton, but that entirely depends on the implementation so show it

deep bolt
slender nymph
#

i'm guessing that is 100% the case though, especially since the scene is being loaded additively, the new one destroys itself before the old scene is unloaded

deep bolt
#

i dont think this would have caused any issues? idek

slender nymph
#

yep, that's it. it's not DDOL so the old one doesn't stick around

deep bolt
#

there isnt any cameras in the additive scene though so shouldnt this be the only camera

#

that is persistent

slender nymph
deep bolt
slender nymph
#

right because when you "load it normally additively" there isn't already an instance of that singleton, right?
so when you load it additively again and there is an instance of that singleton, the new instance destroys itself because an instance already exists, but then you destroy that existing instance by unloading the scene that it exists in (since it isn't DDOL), but you only unload the scene after the new instance has already been queued for destruction (since that happens in the first frame the scene is loaded, the same frame you queue the new scene to be unloaded)

crystal agate
#

am I not able to use SetActive for buttons?

deep bolt
#

ah ok

slender nymph
slender nymph
neat prairie
#

Hey folks, don't know if this is the correct channel or not, but I have been running into trouble with tilemap colliders and rigidbodies, specifically with my player'r rigidbody clipping. I've already tried:

  1. Kinematic -> Dynamic on the player
  2. Discrete -> Continuous detection on both player and tilemap rigidbodies
  3. Changing the player collider's size and type
  4. None are triggers

I use Rigidbody2D.MovePosition in my PlayerController script. Is there a good fix to this?

naive pawn
slender nymph
deep bolt
#

i didnt test it without the script enabled

crystal agate
#

next question, if I wanted to set every object in an array to SetActive(false), do I have to use for loops or is there a faster way?

#

or an easier to read way rather

slender nymph
#

you do have to use a loop, but you can abstract that into its own method

nocturne kayak
#

hello everyone , is it a good idea to use myInstance.GetComponent<scriptname>().myvariable= variable; to change a variable value from another script , or are there better way ? ty

naive pawn
neat prairie
slender nymph
# neat prairie nope

then you'd have to show relevant code. but if it's not a code issue then #⚛️┃physics would be the better place to ask this (providing relevant set up/context)

naive pawn
crystal agate
#

is there a way to shorten this into one method?

neat prairie
naive pawn
slender nymph
#

or even just the index

naive pawn
#

wouldn't work to cover the last case

slender nymph
#

ah shit yeah, didn't notice that one

crystal agate
#

the problem is that all of these have to be assigned to a different button

naive pawn
#

was gonna say that at first too lol

naive pawn
#

though typically, hardcoded indices like this could indicate a code smell, so you might want to consider doing this more programmatically

crystal agate
naive pawn
#

pass the index in the unityevent

crystal agate
#

like on the text box here?

slender nymph
#

yes, but with the right method selected

#

that method also does need to accept an int parameter

crystal agate
#

yeah my thing's still got compiler errors so the right method isnt showing yet but i got the idea, thank you

neat prairie
# slender nymph then you'd have to show relevant code. but if it's not a code issue then <#49787...

I think this is the relevant code:

using ...

public class PlayerController : MonoBehaviour
{
    public InputActionAsset actionAsset;
    public float speed = 1.0f;
    public float jumpforce = 1.0f;
    public float speedInAir = 0.5f;

    private Rigidbody2D rigidBody;
    private InputAction moveAction;
    private InputAction jumpAction;
    private Collider2D groundCollider;
    private new Camera camera;
    private bool isJumping = false;

    // Start is called once before the first execution of Update after the MonoBehaviour is ...

    // Update is called once per frame
    void Update()
    {
        var newPosition = transform.position;
        var value = moveAction.ReadValue<Vector2>();
        var actualSpeed = isJumping ? speedInAir : speed;
        var deltaDistance = value.x * actualSpeed * Time.deltaTime;
        newPosition.x += deltaDistance;
        transform.position = newPosition;
        // ...  
    }

    private void LateUpdate()
    {
        var newCameraPosition = transform.position;
        newCameraPosition.z = camera.transform.position.z;
        camera.transform.position = newCameraPosition;
    }

    private void FixedUpdate()
    {
        if (jumpAction.IsPressed() && groundCollider != null)
        {
            rigidBody.AddForceY(jumpforce, ForceMode2D.Impulse);
            isJumping = true;
        }
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        var dot = Vector2.Dot(collision.contacts[0].normal, Vector2.up);
        if (Mathf.Approximately(dot, 1.0f))
        {
            groundCollider = collision.collider;
            isJumping = false;
        }
    }
    private void OnCollisionExit2D(Collision2D collision)
    {
        if (groundCollider == collision.collider)
        {
            groundCollider = null;
        }
    }
}
slender nymph
#

transform.position = newPosition;
this does not respect collisions

#

didn't you say you were using MovePosition?

naive pawn
neat prairie
#

I overlooked this... makes perfect sense

#

I mixed up projects

naive pawn
#

AddForceY wouldn't work on a kinematic either lol

neat prairie
#

okay so this now causes a few weird things:

  1. player doesn't seem affected by gravity as much (can be remedied by increasing gravity scale or mass)
  2. player no longer jumps, presumably because no surface is detected below
slender nymph
#

share the current code, in a bin site preferably so you don't have to remove parts

neat prairie
naive pawn
#

again MovePosition is intended for kinematics, you shouldn't use it for dynamics

slender nymph
#

you're now mixing MovePosition which moves to a specific position (and should also ideally be put into FixedUpdate) with AddForce, this combination is why gravity isn't working correctly. you need to either move entirely with forces, set the velocity, or entirely with MovePosition

neat prairie
naive pawn
#

should the player ignore collisions?

slender nymph
#

also yeah, ideally you wouldn't be using MovePosition with a dynamic body

neat prairie
slender nymph
#

same code? or have you changed it? because if it is the same, then the reason i just provided is why

neat prairie
slender nymph
#

i know . . . i was referring to that code

neat prairie
#

there's also all around weirdness to the movement, so I'm probably going to need to dissect all that

naive pawn
#

so what's the current code?

neat prairie
#
    // Update is called once per frame
    void Update()
    {
        var newPosition = transform.position;
        var value = moveAction.ReadValue<Vector2>();
        var deltaDistance = value.x * speed * Time.deltaTime;
        newPosition.x += isJumping ? 0f : deltaDistance;
        transform.position = newPosition;

        var newScale = transform.localScale;
        if (Mathf.Approximately(value.x, 0.0f)) { }
        else if (value.x > 0.0f)
        {
            newScale.x = Mathf.Abs(newScale.x);
        }
        else if (value.x < 0.0f)
        {
            newScale.x = -Mathf.Abs(newScale.x);
        }
        else { Debug.LogError("Unexpected value.x: " + value.x); }
        transform.localScale = newScale;

    
    
    }

only changes to Update so far

slender nymph
#

you're back to moving via the transform?

neat prairie
#

yes, the alternative was no movement

#

I'll have to deal with the tilemap differently

slender nymph
#

so now you don't get collisions and (though probably unnoticable at this scale) worse performance!
hooray!

neat prairie
#

collisions?

slender nymph
#

i'm confused by this question considering your initial issue was that you weren't colliding properly

neat prairie
#

I guess one of the problems I now see is with the iar control code, which obviously is badly hacked together. The easiest way to fix it is to prevent air control until things are sorted.

slender nymph
#

so start by addressing the most obvious bit, which is the fact that you are moving via the transform

neat prairie
#

oh, right the no clipping is still there

#

a thing to note is I never had this issue on plain sprites and box colliders

#

should I rely on tilemaps for side scrollers at all?

slender nymph
#

why do you keep getting hung up on the fact that you're using a tilemap. the issue is that you are moving via the transform as has been pointed out several times now

#

that literally ignores collision

#

and the only reason it kind of works is because the dynamic rigidbody is depenetrating you every 0.2 seconds

naive pawn
#

the viable choices for moving a dynamic rigidbody are setting the velocity or applying forces

#

this is not one of them

neat prairie
#

gravity straight up didn't work

slender nymph
#

for reasons that were already pointed out

#

do you just not pay attention to the information provided to you or what

neat prairie
#

I mean, kinda. I haven't dinner in hours.

#

Could you please point me to why the gravity thing doesn't work with rigidbody mode turned on? I'll probably come back later.

slender nymph
#

MovePosition which moves to a specific position
specific position includes on the Y axis

slender nymph
#

you tell it to go to one place but expect it to go somewhere else. but it will do exactly what you told it to do

neat prairie
slender nymph
#

or maybe use one of the viable choices for moving a dynamic rigidbody

neat prairie
slender nymph
#

yes, gravity is enabled on a dynamic body. but you're still overriding it by telling it specifically where on the Y axis you want it to go

neat prairie
slender nymph
#

at this point i'm done attempting to help, you clearly don't really intend to pay attention and just want to do your own thing so good luck

neat prairie
slender nymph
#

that part is irrelevant because it's not where you tell the rigidbody specifically where on the Y axis you want it to go

neat prairie
neat prairie
#

Hey, I went back and read everything you said. I made it all work, collisions and all!

Changelog:

  • Use linearVelocityX to move the player (do I need to accoutn for the delta time?)
    private void FixedUpdate()
    {
        var value = moveAction.ReadValue<Vector2>();
        rigidBody.linearVelocityX = value.x * speed;

        if (jumpAction.IsPressed() && groundCollider)
        {
            rigidBody.AddForceY(jumpforce, ForceMode2D.Impulse);
        }
    }
  • Tilemap is static, player is dynamic. Composite Collider is applied in Merge mode.
#

only con is that the player is very bouncy haha

neat prairie
# rich adder You're overriding it

you were absolutely right, so I had to make sure any movement on the Y axis is only based on acceleration/force and not teleporting the rigidbody around

naive pawn
marble hemlock
#

https://paste.myst.rs/ju6o08i7
i'm having a problem where it seems that it just runs the interact method and then the escape method all in one go

the interact button is also e, but i dont really know what to do because i'd have reasoned requiring a bool to also run, and not just the input of the e key, would prevent this

#

notably the other puzzle i made based on this system doesnt have this error, but i can only assume thats because it just hasnt shown its face yet, since before this script didnt have this problem at all

#

it didnt appear until i closed down the project and reopened it iirc

grand snow
marble hemlock
#

i'd have thought that it returning it on the frame it was pressed would only trigger it on the frame it was pressed 🗿

grand snow
#

Input.GetKeyDown does only return true if the key was pressed this frame

marble hemlock
#

my glorious script which isnt exploded yet

#

until now

#

it might be ass idk
it works enough and thats goo

#

i did put debug logs in the original balancer script and it did run through both the escape and interact method

#

i changed the key to escape to be r at one point, and that completely solved it, so i can only guess that the problem is that they share a keybind

#

but i feel like im still doing something wrong it shouldnt be that difficult...

grand snow
#

Its a but cruddy but I managed to parse it

marble hemlock
#

🫡

#

i mean there isnt any other script which is even calling it so i have no clue

grand snow
#

Your ide wont show UnityEvent subscriptions however, those are kinda magic

marble hemlock
#

i guess i have to find what could be lurking and calling the balancer script

so the code itself isnt hte problem then?

grand snow
#

I dont actually know the method name that you think is being called incorrectly

#

i just guessed based on your description

#

If you can plz state the exact name

marble hemlock
#

i dont entirely understand
whats happening is that as soon as the interact method in the first script gets triggered, it also activates the script to immediately take the player out of it. from what ive seen it is just running through both methods one after the other.

#

i said before but when i changed the button for how to get out of the balancer UI, it does work again but in general it shouldnt be having this problem.

grand snow
#

e.g. InteractFunction.InteractMethod() is called then Poop.FuckYou() is called incorrectly!

marble hemlock
#

ahhh
BalancerPad.EscapeBalancer();

i think thats whats being asked, i may possible be misunderstanding

#

hmmm
i will try something

grand snow
#
if ((usingBalancer) && (Input.GetKeyDown(KeyCode.E)))
            {
                EscapeBalancer();
            }

Well this must be what you were referring to then right?

#

in Update()

#

If this script executes its update AFTER the interact script then thats why this happens @marble hemlock

marble hemlock
grand snow
#

So thats it?

grand snow
# marble hemlock Ye

BalancerPad.Update() executed after BalancerPad.InteractMethod() which causes what you experience

marble hemlock
#

So I should take it out of update?

#

I don't know where id put it tbh

grand snow
#

or do its logic in LateUpdate() instead

marble hemlock
#

Hmmm
Time to intentionally use late update for the first time

I shall see!

marble hemlock
#

late update didnt work....

marble hemlock
#

nothing works idk what t do

#

does anyone have any solutions for when creating a toggle that uses the same input key activates them both at the same frame one after the other?

woven rune
#

guys i need help with animator

zenith cypress
woven rune
#

tryna create a character controller and im doing fine but sneaking substate machine has defeated me i think

rich adder
rocky wyvern
#

any recommendation for a library to serialize list<> to json file?

slender nymph
#

Literally any, including json utility

rich adder
#

the latter gives you some options with Dictionary, props and more complex shit but for basic stuff jsonutil is fine

slender nymph
#

The only caveat with json utility is that the list can't be the root object, it has to be inside a class or struct that you are serializing

rocky wyvern
#

you sure?

#

because thats what I have and JsonUtility.ToJson() just returns {}

slender nymph
#

Show your actual code

rocky wyvern
#

xd was using an auto generated property and of course that is not serialized because the field is private

#

durr

grand snow
marble hemlock
#

im trying tyo understand input action but i dont think i do...

grand snow
#

ive said what to do so give it a try or not 🤷‍♂️

marble hemlock
#

i did try both
putting a delay between them was one of my first attempts, but it did little beyond temporarily allowing me to see for a second that it was opening

#

i also did try using late update for the escape balancer, to try to separate it, but it didnt mean much

#

no change notably

naive pawn
stuck palm
#

i have this script that inherits from Button, but any extra fields i add seem to not be added to the component inspector. how do i fix this

rich adder
marble hemlock
#

i don't get why this wouldnt be working because i feel like it not working is a sign that any other minigame ive made or begun working on is subject to imploding

stuck palm
#

i want to use the button api

naive pawn
#

would composition just be easier to deal with here

grand snow
#

yea its too painful to ever extend UGUI components unless you really need too (e.g. scroll rect)

#

you have to define an inspector to add the fields or override it fully back to default

stuck palm
swift crag
#

fortunately, you can easily look at the custom editors for the UGUI components

#

but composition is a better idea for this kind of thing

stuck palm
#

btw composition in this context means like

#

multiple scripts right

#

so like a script for the button and a script for the values

#

separated but work together

#

been a while since i've brushed up on my OOP definitions

grand snow
swift crag
#

yep!

marble hemlock
#

i think i fixed it this is insane

#

huzzah

#

i just shut down the entire interact script for the duration of the things being open

#

ah yes, ofc it works for one script but not the other

#

i fixed it and now the crosshair stops working i'm genuinely baffled on what's going on

#

this happened before and i kind of just dismissed it but now i dont know..

#

i restarted unity and the bug reappeared i feel like im losing my mind
fortunately it only happens on the first click so thats an improvement

thorn hull
#

How would i get something to only happen after opening my game? Like if i hit the start button, i want an opening scene to load. However, if i go back to the main menu from the hub world, I want the start button to load the hub world rather than the opening scene.

topaz gorge
topaz gorge
teal viper
#

There are many ways to do it. Look it up.

topaz gorge
teal viper
#

This is enough to find the right answer. I can't list all the possible solutions here

#

It would also depend widely on the context of their project

topaz gorge
teal viper
#

"just use a bool" is not a solution, as it would get reset between scene load normally.

solar hill
#

a bit of a non answer dont you think?

#

"oh to do the thing you want to do just do the thing you want to do!"

topaz gorge
#

use player prefs to save the bool, or a json based save system

teal viper
# topaz gorge SAVE

Save to disk? What if they want the opening scene to play every time they launch the game?

topaz gorge
#

doesnt matter, but using a bool to check wether if the opening scene has been already played isnt crazy

thorn hull
swift crag
topaz gorge
swift crag
#

if they do want this to happen only once, then persisting that flag would be reasonable

thorn hull
#

Maybe like have a first start set to false first then set it to true when the start button is selected. Then if first start is true the button will load smth else? Would that stay across scenes?

teal viper
#

And also learn something in the process.

topaz gorge
#

You can still use a bool though that persist through the games period cross scenes, Its called using DontDestroyOnLoad on a specific object that holds temporary information

thorn hull
teal viper
#

Indeed. You now listed 2 of the possible ways to persist state.

thorn hull
teal viper
thorn hull
#

I'll look some up thx. At least now i have a vague idea of what to do

harsh rain
#

I’m building a Minecraft-style voxel renderer where chunk meshes are procedurally generated, textured from a single atlas, and rendered with custom atlas shaders for terrain blocks plus special objects like doors, leaves, glass panes, and poppies.

Fully opaque rendering works when alpha/undefined atlas pixels are forced to black, but when I enable alpha cutout for those transparent pixels, the opaque parts of those objects start showing terrain/shadow/silhouette artifacts from objects behind them.

It looks like a depth/shadow/render-queue or shader-pass issue where background geometry is leaking through or being projected onto cutout objects even outside the transparent holes.

I have attached three images.
One image shows the leaf block, glass pane block, and poppy block, and you can see on the objects where I attempted to "cut out" the transparent parts, it just ends up not working that well.
Second image shows the door, where you can see weird artifact shadows when there are other blocks behind the door, but the third image shows that when there are no blocks behind the door, there are no artifacts.

I am not too experienced when it comes to rendering and specific cutouts or texturing/shadows etc, so any help would be greatly appreciated.
Also for each image, left side is cut out version and right side is plain black no cutout. I have also attached my texture atlas.

Been trying to fix this issue for hours upon hours and it is not working. Thanks for any help you guys have to offer!

#

If you need any more info in order to help, I can easily provide it

solar hill
topaz gorge
harsh rain
topaz gorge
harsh rain
#

Wait

#

Just did a google search

#

Maybe that might be the issue, I'll take a look

#

I doubt it though, because it is only when I enable shadows?

#

Yeah nvm I already enabled Point

topaz gorge
#

also you shouldnt have generate mip maps on either

#

Like you can use it but like it does not work well for that at all

#

You also shouldnt have compression on if you do or atleast only have it at its minimum setting

#

Im currently looking through your shader code i just figured i should bring those up before hand

harsh rain
#

Ah good point

#

I don't have compression enabled

#

Mipmaps are also off

topaz gorge
# harsh rain Ah good point

Ah you realize that your cutout version of your shader leaves behind before rendered artifacts, your cutout shader isnt complete compared to your other one, hold on

harsh rain
harsh rain
#

Thank you so much man, I'll try that out

topaz gorge
harsh rain
#

Uh @topaz gorge unfortunately it didn't work.

I did want to tell you something specific tho, that at least for the door, I can see the shadows/dark spots of the blocks that are actually behind the door. Idk if that helps. It's definetely an issue with shadows because I turned the shadows off for these objects, and there was no glitchiness like this

harsh rain
topaz gorge
topaz gorge
#
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"     // <-- important

struct v2f
{
    float4 pos : SV_POSITION;
    float2 uv : TEXCOORD0;
    float2 atlasData : TEXCOORD1;
    float3 worldNormal : TEXCOORD2;
    UNITY_SHADOW_COORDS(3)      // <-- add this
};

In the Vert()

UNITY_TRANSFER_SHADOW(o, v.uv);   // <-- add this

In the fragment

float shadow = SHADOW_ATTENUATION(i);
float3 directional = _LightColor0.rgb * directLight * shadow;   // <-- multiply by shadow

Should be all you really have to do

harsh rain
#

Man this is confusing

#

(terrible image but you can see the artifacts on the poppies)

topaz gorge
#

This stuff is always hard to diagnose

harsh rain
#

I can try to provide any info

#

I really appreciate all of your help by the way

topaz gorge
#

Yeah can you give me a up close picture of everything having a artifact issue

#

cause it might even go beyond just shadow

harsh rain
topaz gorge
#

i added you rq so we can talk there

harsh rain
#

Okay

teal viper
topaz gorge
acoustic sequoia
#

i feel like i'm losing my mind with this coding issue...

UnityEngine.MonoBehaviour.StartCoroutine (System.Collections.IEnumerator routine) (at <6a469c5cf96a43eab23a293167261e20>:0)
General.ParticleBehavior.CollectableManager.DoRoutine (UnityEngine.Coroutine routine, System.Collections.IEnumerator callback) (at Assets/Scripts/General/ParticleBehavior/CollectableManager.cs:47)
General.ParticleBehavior.CollectableManager.Collect (UnityEngine.Vector3 position) (at Assets/Scripts/General/ParticleBehavior/CollectableManager.cs:42)
General.CellBehavior.Cell.OnTick () (at Assets/Scripts/General/CellBehavior/Cell.cs:109)
GameManager.OnTick () (at Assets/Scripts/GameManager.cs:56)
GameManager.Update () (at Assets/Scripts/GameManager.cs:71)

what are the reasons for getting this, because i've tried everything i could find looking through google and docs and even tried chatgpt and nothing makes this error go away. and my coroutine will not execute. which also doesn't make sense becasue i have the exact same code executing a coroutine elsewhere in the project that works perfectly fine. but not this one. whyyy

sour fulcrum
#

!code

radiant voidBOT
teal viper
hallow sun
#

inspector error, colors stuck at all zeroes (0,0,0,0), ignores color picker and even initialization

topaz gorge
acoustic sequoia
# teal viper Showing the relevant code might be helpful...

it starts here in a cell script:

GameManager.Instance.HandleCollectables(transform.position);

then in the instance it does this:

public void HandleCollectables(Vector3 position) {
        collectableManager.Collect(position);
    }

then in the collectablemanager it does this:

public void Collect(Vector3 position) {
            var item = GetCollectableFromPool();
            if(!item) {
                return;
            }
            item.gameObject.SetActive(true);
            item.Initialize(position, Vector3.zero, this);
            _myRoutine = StartCoroutine(CollectCoroutine(item));
        }
        
        private Coroutine DoRoutine(Coroutine routine, IEnumerator callback) {
            
            if(routine == null) return StartCoroutine(callback);
            
            StopCoroutine(routine);
            routine = null;
            return StartCoroutine(callback);
        }
teal viper
acoustic sequoia
# teal viper The return type of a coroutine method needs to be IEnumerator iirc.

this is the Coroutine:

private IEnumerator CollectCoroutine(Collectable item) {
            transform.position = item._startPosition;
            var currentPosition = item._startPosition;
            var elapsedTime = 0f;
            while(elapsedTime < collectDuration) {
                elapsedTime += Time.deltaTime;
                if(elapsedTime >= collectDuration) {
                    elapsedTime = collectDuration;
                }

                transform.position = Vector3.Lerp(item._startPosition, item._endPosition, elapsedTime / collectDuration);
                if(!(elapsedTime >= collectDuration)) continue;
                ReturnCollectableToPool(item);
                break;
            }

            return null;
        }```
it is type IEnumerator
topaz gorge
#

Just so you can read more about it

teal viper
topaz gorge
teal viper
teal viper
hallow sun
#

yeah im pretty sure this is a unity issue, not my code:

public PointResource[] pointResources; //everything works except i cant set color variables in inspector
public PointResource test; //everything works if its not in an array?
acoustic sequoia
teal viper
#

So either you shared older stack trace or it's still being called

topaz gorge
teal viper
teal viper
acoustic sequoia
# teal viper It's in the error stack trace though..?

so i added the yield into the Coroutine and i added the DoRoutine method back and now i'm getting this error:

NullReferenceException: Object reference not set to an instance of an object
GameManager.HandleCollectables (UnityEngine.Vector3 position) (at Assets/Scripts/GameManager.cs:85)
General.CellBehavior.Cell.OnTick () (at Assets/Scripts/General/CellBehavior/Cell.cs:109)
GameManager.OnTick () (at Assets/Scripts/GameManager.cs:56)
GameManager.Update () (at Assets/Scripts/GameManager.cs:71)




teal viper
topaz gorge
#

Im dense

#

GameManager

#

Fucking hell

acoustic sequoia
teal viper
sour fulcrum
#

(Probably instance)

topaz gorge
#

The instance is null

acoustic sequoia
sour fulcrum
#

When is Instance set

topaz gorge
acoustic sequoia
sour fulcrum
sour fulcrum
topaz gorge
#

Well yes a getter is fine, but what i mean is if you reference a instance from any where the execution needs to be after awake

acoustic sequoia
topaz gorge
acoustic sequoia
topaz gorge
#

you should always return after destroy, but that isnt the problem anyways

acoustic sequoia
# teal viper Log both to know for sure.

here is the instance log:

UnityEngine.Debug:Log (object)
General.CellBehavior.Cell:OnTick () (at Assets/Scripts/General/CellBehavior/Cell.cs:109)
GameManager:OnTick () (at Assets/Scripts/GameManager.cs:56)
GameManager:Update () (at Assets/Scripts/GameManager.cs:71)

teal viper
#

And make the log more verbose to not get confused.

hallow sun
teal viper
teal viper
left jacinth
#

trying to have one script call a function from another script, so I serialized the script I'm calling the function from and used the function, but I got an error saying the object reference is not set to an instance of an object.

using UnityEngine;
using UnityEngine.Timeline;

public class Meteor : MonoBehaviour
{
public Rigidbody rb;
[SerializeField] ScoreTracker scoreTracker;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{

}

// Update is called once per frame
void Update()
{
    rb.linearVelocity = new Vector3(0, -3, 0);
}

private void OnCollisionEnter(Collision collision)
{
    scoreTracker.addScore();
    Destroy(gameObject);
}

}

#

sorry i should have put it in a .txt

topaz gorge
left jacinth
#

let me see if that works, i have my doubts because of separate incident

left jacinth
acoustic sequoia
topaz gorge
left jacinth
#

alright

topaz gorge
teal viper
#

Take a screenshot

acoustic sequoia
#

how do you want me to log them specificly. like this?
Debug.Log("GamemanagerInstance: " + GameManager.instance) as an example.

topaz gorge
#

Well i mean if it isnt null before that piece of code runs then thats a whole seperate issue, meaning either that instance gets nulled out magically, maybe by scene swapping, or by the piece of code running before awake but that can't technically happen in this case. So i would put the log along with the line of code that calls the function that is giving you the issues

left jacinth
#

the blue outline thing

teal viper
topaz gorge
#

use "" at the top and "" at the bottom

left jacinth
#

thank you/

topaz gorge
#

it didnt show

#

hold on

#

use three of these `` at the top and three at the bottom

#

you can also just use ` at the top and bottom

left jacinth
#

I did this but it turned out to have the same error

void Start()
{
    GetComponent<ScoreTracker>().addScore();
}
topaz gorge
#

no your grave key

left jacinth
#

oh

topaz gorge
#

the one above tab

#

Aye

#

you can also add cs after the first pair for highlighting like this

left jacinth
#

alright

#

anyways it has the same error message

topaz gorge
#

Well where is the component stored at, is it in the same location as the script or on a child object

left jacinth
#

it's a NullReferenceInspection

#

the script is stored where all scripts are, but the prefab is stored in the prefabs folder

topaz gorge
#

No no, i mean the RIgidbody your trying to reference

left jacinth
#

well the rigidbody is instantiated into the scene so its nowhere until it is spawned

left jacinth
#

three seconds after the game starts

#

the code for the score addition is in the prefab for the meteor

topaz gorge
#

ok so in the same code that you instantiated the rigidbody with, after that instantiation you then assign it right, cause you can't assign it sooner

left jacinth
#

here's the full pseudocode:

-The floor instantiates a new meteor every 3 seconds
-Meteor (should) call the addScore function from the ScoreTracker script canvas and then destroy itself (second part works) when it collides with an object

#

ohh

topaz gorge
#

Did it click

left jacinth
#

it should be referencing the floor.meteor

#

is that right or am I stupid

topaz gorge
#

Well if your instantiating a bunch of meteors, the proper logic would be that when a metor collides then it talks to your score counter, says hey i collided right.

left jacinth
#

yeah

#

so I could either figure out how to make the meteors do it or just have the floor do it. That's well and good, but I think the best learning experience is to have the meteors-- the instantiated objects-- do the signalling

topaz gorge
#

So floor makes meteors, the collision logic is in the meteors, you have your score class make it a Instance/Singleton, when meteor collides it can reference that instance and the function to increase your score

#

Nothing needs to know about the rigidbody's but the meteors themselves

left jacinth
#

hold on i'll be back

#

okay it wasn't exactly specified which object should be the singleton, and i'm having a hard time understanding it. sorry, this is my first game and I'm starting very basic

topaz gorge
left jacinth
#

from the video i watched, a singleton can be made by making something static. so I should make the score tracker class static?

burnt vapor
topaz gorge
burnt vapor
left jacinth
topaz gorge
burnt vapor
burnt vapor
burnt vapor
#

You don't need to keep a component reference in another component's memory. You can just call GetComponent the moment you need it. Only when you work with code that must fetch a reference often is when you need to start wondering if maybe you should keep a reference.

#

Regardless you should keep initialization of data and references to Awake/OnEnable and put actual behavior from Start and methods that come after

topaz gorge
burnt vapor
#

It's not "expensive". These are negligible calls when you do them a hundred times a second. Like I said, as soon as you start working with more intensive code you need to start wondering if it makes sense to maintain a reference.

#

You can get away with a lot of things performance wise, you just need to wonder if it makes sense to keep a reference or if it's simpler for you to get it only when you need it. It also depends a lot on the availability of the component(s)

#

A bigger offender would be getting a component directly versus using something like the Find methods for components. The find methods for example make a significant performance impact if you use them, especially if you do it often.

topaz gorge
#

But teaching a proper way instead of letting people do lazy things is just better in general. What your basically saying is, everytime im thirsty i walk to the fridge grab a drink and walk back, instead of keeping the water with me yk

burnt vapor
#

Usually I just grab a single can each instead of grabbing the whole tray 😄

topaz gorge
left jacinth
#

okay well GetComponent on awake didn't work either. I'll send the code

#
using UnityEngine;
using UnityEngine.Timeline;

public class Meteor : MonoBehaviour
{
    public Rigidbody rb;
    private ScoreTracker scoreTracker;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    private void Awake()
    {
        scoreTracker = GetComponent<ScoreTracker>();
    }

    // Update is called once per frame
    void Update()
    {
        rb.linearVelocity = new Vector3(0, -3, 0);
    }

    private void OnCollisionEnter(Collision collision)
    {
        scoreTracker.addScore();
        Destroy(gameObject);
    }
}
topaz gorge
burnt vapor
#

There's nothing wrong with lazily loading content. Especially ing ame design there are a million ways to tackle this. I'm just saying that if you suffer from exceptions because components might initialize later due to execution, there is nothing wrong with loading it later

topaz gorge
#

as your score tracker probably doesnt liver on the meteor object

burnt vapor
burnt vapor
#

They're slow and messy. You suggested the singleton pattern before and this is a very good idea to work with here

left jacinth
#

i'm not sure how to use singletons. I watched a video but it sailed over my head

topaz gorge
burnt vapor
#

I would suggest learning more about them. They're one of the most useful things to learn.

#

Vertx made a great site to explain things like this

topaz gorge
#

They are fantastic honestly, once you get them there pretty god sent

burnt vapor
#

It also gets rid of needing to maintain a reference to the component. ScoreTracker just exists once in the scene, right? Then a singleton pattern is perfect as the whole single instance flow is enforced there.

topaz gorge
left jacinth
#

haha i kind of get that actually

burnt vapor
#

Whatever the case, using a Find method should never be required. It ends up being some implicit reference that is unclear if it even gets found, instead of just keeping direct references which you know will work

left jacinth
#

okay i made a singleton and same error. let me give you the code(s)

#
using UnityEngine;
using UnityEngine.UI;

public class ScoreTracker : MonoBehaviour
{

    public Text scoretext;
    public int score = 0;
    public static ScoreTracker Instance { get; private set;}
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Awake()
    {
        Instance = this;
    }

    public void addScore()
    {
        score += 1;
        scoretext.text = "Score: " + score.ToString();
    }

}
using UnityEngine;
using UnityEngine.Timeline;

public class Meteor : MonoBehaviour
{
    public Rigidbody rb;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    private void Awake()
    {

    }

    // Update is called once per frame
    void Update()
    {
        rb.linearVelocity = new Vector3(0, -3, 0);
    }

    private void OnCollisionEnter(Collision collision)
    {
        ScoreTracker scoreTracker = ScoreTracker.Instance;
        scoreTracker.addScore();
        Destroy(gameObject);
    }
}
burnt vapor
#

It would help if you shared the error(s), especially from the console

left jacinth
#

hold on

burnt vapor
#

The code looks fine reading through it. That's how a singleton pattern works in basic terms

#

You can extend it with checks if Instance is already set for example, to better secure against accidental second instances in the scene

left jacinth
topaz gorge
#

Oh yeah double click the prefab

#

and assign the rb through the inspector

left jacinth
#

but it is assigned

burnt vapor
#

And my suggestion to check if (scoretext == null) and to log the error properly so it's clear it can't be found

topaz gorge
#

Wait hold up, MineTerra do you switch between a main menu and your game scene currently

#

And is your score script in your main menu scene or game scene

left jacinth
#

i don't have a main menu.

topaz gorge
#

Ok was just checking, now your score script actually exist in the scene right

left jacinth
#

yeah

topaz gorge
#

And like he said above, you have the text assigned correct

left jacinth
#

it's not assigned...
it also won't let me assign it though

topaz gorge
#

That because your component is a TMP text

#

in your score script you need to change the reference

#

to TMPro_Text, instead of Text

left jacinth
#

error pops up in the code that TMPro_Text couldn't be found

topaz gorge
#

you need to add at the top using TMPro;

left jacinth
#

alright

#

same issue

topaz gorge
#

screen shot it?

left jacinth
#
using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class ScoreTracker : MonoBehaviour
{

    public TMPro_Text scoretext;
    public int score = 0;
    public static ScoreTracker Instance { get; private set;}
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Awake()
    {
        Instance = this;
    }

    public void addScore()
    {
        score += 1;
        scoretext.text = "Score: " + score.ToString();
    }

}
topaz gorge
#

OH SORRY XD its TMP_Text

#

not TMPro_Text

left jacinth
#

haha it's all g

burnt vapor
#

Your IDE should have corrected you on this. Did you configure it properly?

#

Could you screenshot it and show how it looks like currently?

left jacinth
#

IDE?

topaz gorge
#

bro there aint no way your doing this in notepad++

left jacinth
#

no I'm using visual studio

topaz gorge
#

OK

#

i was about to say

left jacinth
#

i just don't know what IDE stands for

topaz gorge
#

Did you install the Unity addon though the Visual Studio installer

left jacinth
#

yes

#

it works now btw

topaz gorge
#

And in your unity preferences under External tools you assigned the IDE your using>

left jacinth
#

can't believe that

burnt vapor
#

Can you screenshot how it looks like currently? With code included please

left jacinth
#

hold on it's being slow

topaz gorge
left jacinth
#

yeah

burnt vapor
#

Yeah, okay, it's fine. I guess you didn't see it mentioning what class to use then

topaz gorge
#

Sometimes mine doesnt either

#

It acts weird sometimes

left jacinth
#

no it's just that I added using TMPro afterwards so it didn't get to autocorrect

#

anyways thatnks, I'll finish this little project tomorrow

errant breach
#

Hello, i have a small question. I've made that little script that should play while in the editor, and i've recently added "LAND" as a parameter... But it does not appear in the editor, only while in game. Can someone help me please ?

Here's the entire code if needed : https://pastes.dev/8R7xDKwWRY

Thanks !

naive pawn
# errant breach Hello, i have a small question. I've made that little script that should play wh...

But it does not appear in the editor, only while in game
sounds like you're confusing editor vs edit mode.

marking something #if UNITY_EDITOR means it runs only while you're in the unity editor, ie the app that you use to make unity games - it won't run in a build. this doesn't mean it will run in edit mode, aka the mode when the game is not running in the editor (which is play mode)

to have stuff run in edit mode, you have to mark the class [ExecuteAlways], and then you can check whether you're in edit mode or play mode with Application.isRunning, i think? i don't remember the exact field name. note that since the class is marked here, this will affect all lifecycle messages, so you may have to check for playmode in other messages as well

errant breach
#

Thanks for that big explanation ! So ive tried to translate using my knowledge (im french) and if i get this right :

marking something #if UNITY_EDITOR means it runs only while you're in the unity editor, ie the app that you use to make unity games - it won't run in a build. this doesn't mean it will run in edit mode, aka the mode when the game is not running in the editor (which is play mode)

This is what i want and this is the issue i encounter ! I want the list to update when im in the unity Editor; The app. But it does not.
So i should use [ExecuteAlways] as suggested ? Or is the issue elsewhere ?

naive pawn
#

everything not marked that also runs in the editor lol

naive pawn
naive pawn
#

which one are you referring to?

#

as in wdym by "require enum"

midnight tree
#

Nevermind

#

I can be stupid sometimes

undone rampart
errant breach
undone rampart
#

if you want to run logic in the editor you have the following options:

  • the OnValidate function, will make your code run in the editor every time an inspector value is changed
  • the Reset function, will run when the script is attached or reset to the default values, useful for assigning default values (judging by your code this might be what you need)
  • OnDrawGizmos/OnDrawGizmosSelected, these functions are specifically designed for drawing gizmos and handles but they do technically run logic in the editor
  • [ExecuteInEditMode] [ExecuteAlways] attributes, will make all your unity event function in the class run in the editor, this might not be always ideal
  • [ContextMenu] attribute, you can add this to functions to run them from the context menu of the inspector
  • Custom editors, you can create custom editors to add editor only logic or debug features to your script
errant breach
#

Oh ! You are a legend, using "OnValidate" worked and now the value do appear ! I will copy/paste your message somewhere to be able to read it if needed, thanks you, Chris and v0lt, for helping me out ! :)

sage mirage
#

Hello, guys! I have a question. I would like to create my own Custom Animation System, and play animations without the use of an Animator Controller, but only using the Animation Window and Animation component basically. I would like to have an idea on how to create this system and actually think about it. Can somebody help me with that, because I have never created my own Custom Animation System. What I have in mind is to use State Pattern + FSM for the Animation Transitions.

teal viper
sage mirage
teal viper
#

Okay. Then go for it. State machines sounds like the right approach.

keen dew
naive pawn
#

either Reset or ExecuteAlways Awake seem about right

midnight tree
#

Quick question.
Do you use method implementations in the interface? I mean are they effective and are there any pitfalls? Because I've never seen anybody doing that in their projects.

sage mirage
#

interface is just a contract, it says whatever class has this interface must implement these specific methods. If its an abstract class then you can have some implementation but its different

#

an abstract class is not a contract its a half implementation think about it like this

#

and abstract classes can only have abstract methods

naive pawn
#

interfaces can have method implementations

#

so can abstract classes

night raptor
#

I assume they mean default implementation. It is possible to provide default implementation for the methods but usually they don't, in OOP interfaces are meant to be the interface, not the implementation

sage mirage
#

oh I confuse it with static

#

abstract class can have non abstract methods

naive pawn
#

i mean. both interfaces and abstract classes can have static members as well

sour fulcrum
#

Newer c# expands upon this kinda stuff too btw

burnt vapor
#

CoreCLR my beloved

visual idol
#

"Hey, can someone help me? I don't know why my NPCs can't talk to each other, and because of that, I can't continue with my quest."

visual idol
#

"This is my QuestManager."

naive pawn
radiant voidBOT
naive pawn
#

and could you be more specific about which part is having issues?

visual idol
#

No, I don't know why this is happening. Everyone in Unity got caught up in it, but I still can't talk to my NPCs anymore.

#

Sorry, my English isn't very good.

burnt vapor
#

Specifically place it at the very start of your Start method too. That way we can determine if the code is ever entered.
If you don't see the log appearing at all, that would mean the component never runs the method. This could be because the component is disabled, for example. Alternatively you haven't placed it in the scene at all.

errant breach
light glacier
#
using System;
using System.Collections.Generic;
using UnityEngine;

namespace _tmp {
    [CreateAssetMenu(fileName = "RanklistData", menuName = "Scriptable Objects/RanklistData")]
    public class RanklistData : ScriptableObject {
        public StringIntDictionary PlayerScores;
        public List<int> TestNumbers;
    }

    [Serializable]
    public class StringIntDictionary : ISerializationCallbackReceiver {
        public Dictionary<string, int> Dictionary = new();
        public List<string> Keys = new();
        public List<int> Values = new();

        public void OnBeforeSerialize() {
            Keys.Clear();
            Values.Clear();
            foreach (var kvp in Dictionary) {
                Keys.Add(kvp.Key);
                Values.Add(kvp.Value);
            }
        }

        public void OnAfterDeserialize() {
            Dictionary = new Dictionary<string, int>();

            for (var i = 0; i < Mathf.Min(Keys.Count, Values.Count); i++) {
                Dictionary[Keys[i]] = Values[i];
            }
        }
    }
}

This is more about learning I'm aware there is probably much easier/better solutions but I wnat to understand this Serializing concept.

I get the Player Scores In the Inspector and Also Keys and Values. But when I click the Plus symbol nothing happens. No error, nothing.

naive pawn
light glacier
#

thanks ill look into it. on the first sight it confuses me just more. I'll post in Editor Extensions if I'm lost

white condor
#

can i ask shader code questions here

verbal dome
light glacier
white condor
proven crystal
#

Hey chat, is it possible to make navmesh agent on 2d side view project

rich adder
woeful grotto
#

I am programming in unity after a while, why is this method deprecated. What is the alternative?

rich adder
#

the why ? only unity internally knows that..

#

things change often, especially if for optimizations purposes etc. nature of software

woeful grotto
#

so it this method obsolete now?

#

they won't add an alternative

rich adder
#

it still works but in the future it may not

rich adder
woeful grotto
#

uh I think it really is obsolete now

rich adder
#

this i a transition into the new ECS/Gameobject system they're trying to merge into

woeful grotto
#

I think any object might work because I have only one of it.

rich adder
#

Obsolete/Deprecated still work fine. Until it wont in future updates / unity versions

#

in this case is not a huge deal considering we're not in the ECS/GO mix system yet

woeful grotto
#

I don't think I am gonna update my project to another version anyways so I think it's safe to use it

rich adder
#

but also

Note: This function is very resource intensive. It's best practice to not use this function every frame and instead, in most cases, use the singleton pattern. Alternatively if you only need any instance of a matching object rather than the first one you can use the faster Object.FindAnyObjectByType

woeful grotto
#

yeah ik that, but it's only being called once in start so that won't be an issue

rich adder
#

I'd still use .FindAnyObjectByType since thats not deprecated anyway

woeful grotto
#

yeah I used that one

#

it works perfectly so there is no reason to use a deprecated one

#

thanks for the help!

harsh rain
#

Sorry, been waiting for a while can anyone help me with my post in #1390346776804069396 ? Been trying to get it fixed for hours now. Yesterday too

cosmic sable
#

Hello, I'm currently learning in unity and I ran into a problem which isn't addressed below the texts. Everytime I click spacebar a banana spawns because of the prefabs, the real problem is when it goes out of bounds, it deletes the banana, but it doesn't just delete that 1 thing that went out of bounds, but as a whole, meaning I can no longer access it

#

how do I fix it?

rich adder
#

show instantiate code

cosmic sable
rich adder
# cosmic sable

dont share screenshots of code and show it as a whole so context makes sense

#

!code