#💻┃code-beginner

1 messages · Page 12 of 1

timber tide
#

I know for scriptable object, the editor doesn't like multiple classes

#

unless encapsulated

summer stump
#

I really don't know haha.
I thought the naming thing had to do with ECS where you may want a bunch of related components in one file (since they often only have one value per struct).

But that doesn't explain monobehaviours which I'm probably wrong about anyway

teal viper
#

Ecs components are not MonoBehaviour though, so they wouldn't need to change it for them to be stacked in one file.🤔

summer stump
teal viper
#

Didn't read till the end...👍

sullen rock
#

can I somehow use convert an enum to an int easily? (basically use the 0-4 numbers without usign a switch or something similiar)?

cosmic dagger
sullen rock
#

oh

#

well thats cool

#

thanks

light moss
burnt vapor
#

By providing more context around the issue, like relevant code

burnt vapor
#

If you plan on passing a number rather than an enum, I advice you use Enum.IsDefined or something similar before anything else.

versed light
#

so what exactly are am i suppose to use then

stiff birch
versed light
#

how do you do that in edit mode?

stiff birch
versed light
#

thanks

storm coyote
#

anyway i can make a solid block that can only move when being pushed by certain tagged objects and acts as a solid walls for others using rigidbody?

onyx tulip
#

My Map moves slightly upwards and i don't know why

solid coral
#

If the animation of the parent is playing, then the animation of the child object is not played. I want to make the character stand up in a pose, and the weapon shoots, with its own animation. An animator has added an animator to the weapon, the trigger is triggered and the states are switched.

tender stag
#

can someone help me? this is on the Item script and its supposed to stack items, and it kind of works, but it removes both of the items since its on both scripts ```cs
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.GetComponent<Item>())
{
Item collisionItem = collision.gameObject.GetComponent<Item>();

    if(collisionItem.itemData.maxStack > 1 && itemData == collisionItem.itemData)
    {
        Debug.Log("Items can stack");

        int totalAmount = amount + collisionItem.amount;

        if(totalAmount <= itemData.maxStack)
        {
            Debug.Log("Stacking items");

            amount = totalAmount;
            Destroy(collisionItem.gameObject);
        }
    }
}

}```

timber tide
#

lol wat

#

oh you're stacking with collision interesting idea

tender stag
#

how else would i do it

neon ivy
#

I'm making a pixel simulation and thus made a pixel data class, now I want to make this into a grid and my first thought was a 2d array but I'm wondering if anyone has any ideas that would work better?

jovial mesa
tender stag
#

trueeeee

jovial mesa
#

the stack would be stackable as well but adding the correct number of items into the final stack

timber tide
#

Destroy doesnt happen till end of frame is the problem here

jovial mesa
#

(feel like I'm using "stack" a lot)

neon ivy
timber tide
#

loops?

neon ivy
#

wondering if I want UI with horizontal and vertical layout groups or simply squares spaced apart

timber tide
#

wouldnt be too hard to make it in 3d space

neon ivy
#

wouldn't it cause rendering issues?

timber tide
#

Probably not more than doing it in 2D

#

just a bunch of quads

neon ivy
#

ok I'll try that, thanks :D

jovial mesa
onyx tulip
#

What can i do to change this?

jovial mesa
onyx tulip
#

Not that i can go through walls

#

Look closely my map is moving upwards

timber tide
#

there are no race conditions, so you'll have info when one or the other executes

#

it's just destroying doesn't work until end of frame, so even after being 'destroyed' it'll still run the logic

frozen dagger
#

i dont understand whats wrong, it always make grounded tag true, and when i try to make it false in inspector it sets true, but i does not touch any object

tender stag
timber tide
#

Ok, so the way I'm thinking of the logic is they collide, you check if the component you collided with is a similar item.
Now, if the component isn't being stacked, then you run the code and then flip isStacking to true. So, now the other item will run the same code and fail when it check's the other item isStacking

timber tide
frozen dagger
#

if (grounded = true)
{
animator.SetBool("IsJumpingDown", false);
animator.SetBool("IsJumpingUp", false);
}

#

i removed it and it fixed

#

is it making tag true? how?

timber tide
#

when using the = operator, you're assigning something usually

#

but you're not trying to assigning anything here, rather you want to compare

#

which is the == operator

frozen dagger
#

okay, it helped, thanks

timber tide
#

always check the hints your ide gives you

lean basin
#

Hello, I'm trying to override Cinemachine input manually.
Documentation said:

Cinemachine has defined an interface: Cinemachine.AxisState.IInputAxisProvider. If a MonoBehaviour implementing this interface is added to a Virtual Camera or FreeLook, then it will be queried for input instead of the standard input system.

But how exactly am I supposed to do that?

I tried to make script and add it as a component:

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

public class CinemachineManualInput : AxisState.IInputAxisProvider
{
}

It's not correct... what is the correct way?

modest dust
#

An interface requires you to implement it's properties and methods

lean basin
#

ah right thank. It didn't hint me toward that earlier because I didn't add MonoBehavior before AxisState.IInputAxisProvider

idle orbit
#

A quick question, how should I code a side view camera movement where upon touching a certain position in the scene the camera will gradually advance forward, such as in an automatic scrolling level design or going through a doorway?

unique hull
#

I think theres a couple of ways to do that.
From the top of my head: Have a trigger depending on a specific number before it starts to move on its own , or you could use a collider for when it triggers / deactivates

#

So : Bool for when the camera follows the player and when its off - auto progress forward

tribal locust
#

Can U help me I have this error: NullReferenceException: Object reference not set to an instance of an object
AnswerButtons.Start () (at Assets/Scipts/AnswerButtons.cs:43)

#

and this: NullReferenceException: Object reference not set to an instance of an object
AnswerButtons.Update () (at Assets/Scipts/AnswerButtons.cs:49)

modest dust
#

Whatever you're using on these lines is not assigned (null)

#

Basically read the error message

tribal locust
#

No I have app and I try to make score bar

modest dust
#

Yeah, sure, but whatever you're doing in that script is not set to an instance of object

tribal locust
#

may I send code?

modest dust
#

Send it

tribal locust
#

!code

eternal falconBOT
#
Posting code

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

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

cosmic dagger
tribal locust
#

it is longer but I make it short

slender nymph
#

how are you gonna use the bot command then completely ignore it

modest dust
#

lol

tribal locust
#

oh ok Im stupid

#

this?

modest dust
#

There's no Text component most likely on these GameObjects

#

You can also just reference the component instead in the inspector

#

not the GameObject

slender nymph
#

100% the issue is that they are using TMP_Text objects in the scene and not UI.Text objects

north kiln
#

You should not reference things via GameObject, it's a waste of time and leads to runtime errors like these

tribal locust
slender nymph
#

yeah so take the advice the others gave and reference the components directly instead of referencing the GameObjects then using GetComponent. but also use the correct type

tribal locust
#

thanks all

pine crown
#

hello does anyone know how to fix this

languid spire
#

make TakeDamage public

slender nymph
#

when no access modifier is specified, it defaults to private

pine crown
#

o thanks dude

delicate portal
#

What does "{ get; set;}" in Unity mean?

north kiln
languid spire
#

not a Unity thing, it's a C# thing

north kiln
#

Should go through the scripting courses pinned to this channel if you do not know

delicate portal
north kiln
soft lotus
#

Whats the diffirence between -= and =-

#

or more like, which does what exactly

slender nymph
#

one is the subtraction compound assignment operator. the other is the regular assignment operator with a negative sign after it

brave compass
#

=- means you forgot to add a space. It's valid, but i =- 1 is the same as i = -1

north kiln
#

-= (one operator) and = - (two)

soft lotus
#

Huh okay

swift crag
#

Spaces aren't mandatory

#

this also leads to funny things like 3 !>= 5

#

this returns false

#

it's actually parsed as 3! >= 5, where ! is the unary null-forgiving operator

#

(only relevant if you told the compiler to error any time you use a variable that might be null)

faint osprey
#

my animation wont play on my cinemachine i have it set to increase my fov in the animation and it plays through script and its not working

#

it keeps saying defualt clip could not be found in animations list

swift crag
#

you will have to show us what you've done.

#

notably: show your !code

eternal falconBOT
#
Posting code

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

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

faint osprey
#
    {
        isSat = true;
        anim.Play();
    }```
swift crag
#

sounds like you're trying to use the (extremely) legacy Animation component

#

You should use an Animator.

faint osprey
#

why cant i use the legacy system

swift crag
#

well, you can, but it's very old and barely used anymore

cosmic dagger
#

you'll have a hard time getting help on a deprecated design (component) . . .

feral notch
#

I have a 2D game and for a certain reason I need the camera to be attached to the player as a child. Is it possible to have camera damping while the camera is a child of the player?

swift crag
#

Sure, but Cinemachine would make that really easy

#

just track the player and give the cinemachine camera some damping

zealous oxide
#

hey peeps, whats the best way to set a variable on a script on an instantiated object, from a separate, other script, thats instantiating said object. do I have to make a function for this in the instantiated object (lets call it "setProjectileDamage"), or is there an easier way?

rich adder
#

take out the () and it should work if damage is a public var
make sure prefab is of the type you're trying to interact with , eg your "other script"

inland canopy
#

Hello! Is it possible if i want to make movement for 2 different players in a single script

zealous oxide
#

its an INT variable in the script of the new instantiated object

cosmic dagger
rich adder
snow mural
#

How would I do if I want to generate and shuffle a deck the same for all connected clients, using netcode? I already have the working functions for generating deck and shuffling it.

snow mural
zealous oxide
cosmic dagger
#

display error message . . .

zealous oxide
#

i dont mind using a function within the instantiated objects own script to set the variable (which is public!!) but i'm struggling to understand why I cant set it from the other instantiating script

rich adder
#

it cannot be GameObject

swift crag
#

GameObject does not have a member named damage. It never will.

#

the type returned by Instantiate is the type you gave it. if your prefab variable is a GameObject, then you'll get a GameObject back

#

it'll be a game object with your projectile component on it, sure

cosmic dagger
zealous oxide
#

im trying to work my head around how do i make this work

cosmic dagger
#

change the type of the prefab to instantiate the type you want to access . . .

rich adder
#

^^

#
    public GameObject prefab; //old
    public MyScript prefab;//new
swift crag
#

you can reference a prefab as a GameObject, or as any component on the prefab

#

Instantiating a component instantiates the entire object the component is attached to.

#

Prefabs references should almost never be a GameObject.

#

You want something more specific than literally any game object, right?

cosmic dagger
#

A GameObject is a container holding a list of components; its prime use is activation and deactivation. Primarily, we need a specific component attached to the GameObject. Change the type of the variable (field) to the component (you want to access) instead; this avoids using GetComponent whenever we grab an item from the object pool . . .

zealous oxide
#

this is a lot and i'm lost now

#

it sounds like using a method on the new objects script would be easier?

cosmic dagger
cosmic dagger
zealous oxide
cosmic dagger
zealous oxide
#

yeah, i can understand that

cosmic dagger
#

what script has that variable?

zealous oxide
cosmic dagger
#

then you need to use that script as the Type of the prefab variable instead of GameObject . . .

polar acorn
cosmic dagger
#

now, when you call Instantiate it will create a copy of the GameObject, but return a reference to the CrescentDartProjectile script, allowing you to access its public members . . .

zealous oxide
#

so change the "GameObject" into "Type" ?

swift crag
#

No.

zealous oxide
cosmic dagger
polar acorn
summer stump
swift crag
zealous oxide
#

ok so i've gotten rid of the line that said public GameObject prefab and replaced it with " public CrescentDartProjectile prefab;//new
"

#

if i'm understanding this right, this should now work as intended?

#

wow, that worked, thank you all for your help.

faint osprey
#

right so my player is riding a cart and when they jump off it i want the momentum from the cart to be conserved onto the player how would i do this

wintry quarry
polar acorn
faint osprey
wintry quarry
#

the short answer is "when the player leaves the cart, give it the same velocity the cart had"

faint osprey
#

the cart doesnt have a rigid body tho

polar acorn
wintry quarry
faint osprey
wintry quarry
#

You're translating it by the amount equal to the velocity you want to impart to the player

stiff stump
#

how can i get all the colliders that overlap another collider?

stiff stump
#

2d

faint osprey
still wren
#

does this code give random values between 1 and zero into a 2d array

stiff birch
still wren
#

i dont know if i did it correctly

stiff birch
#

Then test it and see if you get satisfying results

still wren
#

what does the perlin noise look like in unity

#

i mean to say that if it is like the one on the left or right?

polar acorn
#

(The joke being that these are both perlin noises with different parameters)

stiff birch
#

It's just a question of scale here i think

#

As digiholic say, you can obtain both result IIRC

radiant vector
#

I'm struggling with my bullets. They work fine if I am going straight ahead but since my ship continues on it's velocity when turned if I shoot the bullets don't take the ships velocity. I was thinking of using Vector2.Dot(xx,xx) but I'm not sure what the solution is. I want them to adopt the moving direction velocity. :/

Relevant Code: https://gdl.space/bicilesevi.cs

radiant vector
# still wren i mean to say that if it is like the one on the left or right?

Here's a good tutorial: https://youtu.be/bG0uEXV6aHQ?si=CGDr-CJ30-Ayak8E&t=542

I linked to the relevant part where you change the scale and the image looks like the left or the right in your examples.

Let's have a look at Perlin Noise in Unity.

More on procedural generation:
● Sebastian Lague: http://bit.ly/2qR3Y3P
● Catlike Coding: http://bit.ly/11pMR7O

♥ Support my videos on Patreon: http://patreon.com/brackeys/

····················································································

♥ Donate: http://brackeys.com/donate/
♥ S...

▶ Play video
swift crag
still wren
#

how do i scale the noise

#

@swift crag

swift crag
#

Mathf.PerlinNoise(x, y) samples the noise at coordinates [x,y]

#

suppose you plug in positions in your world

#

you'll sample 0,0 at the origin, 1,0 one meter to the right, etc.

#

now, instead of plugging in the position, plug in the position divded by 10

#

now you're sampling 0 , 0 at the origin and 0.1 , 0 at one meter to the right

still wren
#

oh

swift crag
#

This stretches the noise out by a factor of 10.

rich adder
still wren
faint osprey
#

is it possible to test for a collision between two objects when neither of them have a rigid body

still wren
#

a seed is put in (like minecraft) and the actual number is generated from GetHashCode()

still wren
#

then i just use a random and get a random number from that seed

#

then we plug that in when getting values

swift crag
# still wren

If you make the numbers that go into PerlinNoise larger, then the noise will change more rapidly

#

If you make them smaller, then the noise will change more slowly

still wren
#

it changes by 1

radiant vector
rich adder
queen adder
still wren
#

if the seed is 10, then it starts at (10, 10) then goes to (10, 11) then goes to (10, 12)

swift crag
# still wren

note that adding an enormous random number doesn't really make sense

#

did you mean to add a random value between 0 and 1?

#

System.Random.Next is a random integer

rich adder
still wren
#

thats to make it different everytime

queen adder
#

Also why are you recalculating the velocity every frame? @radiant vector

radiant vector
swift crag
#

gotcha

#

I would still use smaller numbers. You're going to run into problems with floating point precision with huge numbers.

radiant vector
swift crag
#

Maybe just add a random value between 0 and 10000 or something

#

anyway, multiply x and y by a scale factor to change how big the noise is

faint osprey
still wren
#

yeah if the mapwidth and mapheight are 10, then it takes 100 values from a random point on this infinite perlin noise

#

but its for the purpose of, if u want to always have the same world, then u can always enter the same seed

swift crag
#

also, that reminds me

rich adder
swift crag
#

I believe perlin noise is 0 at integral coordinates

still wren
#

what does integral coordinates mean

swift crag
#

coordinates where every number is an integer

#

[3,0]

#

hm, it's not zero, but it's certainly the same value every time

I tried Debug.Log(Mathf.PerlinNoise(Time.frameCount, 0))

#

It's always 0.4652731

still wren
#

so i have to use floats

swift crag
#

So, you should definitely be rescaling these coordinates

still wren
#

or multiply it by something

swift crag
#

I would suggest doing this

#
float sampleX = x * scaleFactor;
float sampleY = y * scaleFactor;
Mathf.PerlinNoise(sampleX, sampleY);
#

where scaleFactor is a float

still wren
#

ok

#

scalefactor should be a const float though

swift crag
#

well, it probably won't be changing

still wren
#

wait why dont i just add 0.5f to it?

swift crag
#

but making it const will stop you from editing it in the inspector

swift crag
still wren
#

this is on a static non monobehaviour script anyways

spare relic
#

i have a very rudimentary question
if i want to fade in/fade out a canvas
is it better to use an animation system or modify the alpha/opacity value of an image directly from code

swift crag
#

I just do it in code.

#

Animation makes sense when you can't easily express the animation in code.

#

for example, animating a character's limbs

spare relic
#

yeah thats what i was wondering

swift crag
#

I do this all the time

spare relic
#

cause it can easily be done in code

#

alright ty

swift crag
#
canvasGroup.alpha = Mathf.MoveTowards(canvasGroup.alpha, shown ? 1 : 0, Time.deltaTime);
#

shown is a bool
canvasGroup is a CanvasGroup

spare relic
#

thank you im going to try it out now

edgy prism
#

Hello I created this function however after adding the foreach statement it tells me not all code paths return a value

public string UpdateObjectiveProgress()
    {
        foreach (var quest in questList.Quests)
        {
            if (quest.Base.RequiredItem != null)
            {
                var inventory = Inventory.GetInventory();
                int itemCount = inventory.GetItemCount(quest.Base.RequiredItem);

                return $"Obtain {quest.Base.RequiredItem} ({itemCount}/{quest.Base.RequiredCount})";
            }
            else
                return quest.Base.ObjectiveText;
        }
    }
polar acorn
earnest forge
#

Hello, I'm looking for a way to create grid lines similar to Debug.DrawLine? Any suggestions? currently looking at either using LineRenderer (which will require handling many line renderers) or instantiating gameobjects per grid box

polar acorn
edgy prism
#

I tried just else return but thats not correct

polar acorn
#

Put a return statement after the foreach loop

edgy prism
swift crag
#

you MUST return a string

#

an empty string is a valid string

#

a null reference is also, according to the type system, a valid option

#

probably not what you want

polar acorn
edgy prism
polar acorn
#

||Update: upon further review, strings can be null in C#. Still probably shouldn't return null though||

swift crag
#

strings are just immutable; they aren't value types

edgy prism
swift crag
#

You can't modify a string in-place

#

so with an array, you can do

#
arr[3] = 123;
#

you can't do that to a string

#

obviously you can reassign the variable entirely

edgy prism
swift crag
#

but that's not modifying the contents of the variable

polar acorn
swift crag
#

an empty string sounds fine, as does "No active quest"

edgy prism
#

Yeah I see the issue but the case for this string is the string thats never going to be used

#

So im assuming I can just return an empty string and not worry about it?

swift crag
#

Sure.

#

If this is an unusal situation that should never happen, you could throw a Debug.LogWarning in there

#

I do that in places that shouldn't ever be reached

edgy prism
#

Thankyou both

weary crystal
#

Um help, a = b, why are the saying first number is equal to second, I don't understand...?

polar acorn
#

a == b is asking a question. It returns true if a equals b.

#

If they are not the same, it will return false

swift crag
#

= is the assignment operator; == is the equality operator

wintry quarry
#

== is in the same family as > < >= <=. It's indeed comparing two things and giving back a result

swift crag
#

if only we used <- for assignment

#

):

weary crystal
#

Ohh, wait, I got it.

#

Thanks!

#

I still kind of don't understand though, I mean "a" is not equal to "b"

weary crystal
#

but also they are not greater than 10

#

so if they are greater than 10 but not same, it'll return false.

polar acorn
#

&& means "and"

weary crystal
#

but if the answer is greater than 10 and it is not same, it will also return false?

weary crystal
polar acorn
#

if their sum is greater than 10 and the first two are equal, do the first block. In literally any other case, do the second

weary crystal
#

Ohh, yeah damn, I got it, thank you so much and sorry.

#

uh why my browser crashed??

swift crag
#

while (counter < 10);

#

This is a while loop that runs an empty statement

faint osprey
#

hey is there anyway to make ur raycasts visible to check stuff

swift crag
#

; ends a statement. A while loop applies to the next statement.

#

So you're doing nothing as long as counter < 10 is true

summer stump
swift crag
#

Notice the squiggle here. The compiler is warning you about this

faint osprey
summer stump
weary crystal
swift crag
weary crystal
faint osprey
#
            {
                Debug.Log("woking");
                sitCheck();
                pm.isSeated = false;
            }```
#

my ray cast isnt working

#

and im not sure why

swift crag
#

Try using Debug.DrawRay to visualize the raycast

#

so, Debug.DrawRay(gameObject.transform.position, cylinder.transform.up, Color.green, 1f);

#

that'll draw a green line that lasts for 1 second

wintry quarry
#

if is already checking for true

#

anyway "doesn't work" doesn't mean too much to us. Perhaps if you explained what you are expecting this to do and what it's doing instead?

faint osprey
onyx prairie
#

why can't i put my CharacterController component into the Character Controller reference?

spare relic
polar acorn
short hazel
onyx prairie
#

ty!

polar acorn
#

But also do make sure they match

swift crag
#

Oh that's funny -- the original CC icon still shows up

short hazel
#

Yeah last compilation pass failed, that's why

onyx prairie
#

fixed it

summer stump
swift crag
#

If you can't see the ray, then you're either shooting it from the completely wrong place, or you're not shooting it at all

ionic totem
#

Hey guys, just a quick q (might be an easy fix but new to unity thx) my models clothes n hair etc is glitching through any idea how to fix?

ionic totem
#

oh yea sorry!

faint osprey
#

im setting a bool fron another script true in a different script and im getting the object refrence not set to an instance of an object error does anyone know a fix

weary crystal
#

Why everything I have learned feels like I understood nothing bruh

languid spire
polar acorn
cosmic dagger
faint osprey
faint osprey
languid spire
#

the bool is not a null, the reference to the object holding it is

summer stump
polar acorn
# faint osprey wdym

Your error says you're trying to get something from a reference that doesn't exist. Instead of doing that, try using an object that exists instead.

wary delta
#

Post your code via pastebin

cosmic dagger
faint osprey
faint osprey
summer stump
polar acorn
#

You haven't showed us anything related to how you're getting the reference

summer stump
faint osprey
#

PlayerMovement playerm;

summer stump
#

You should share the whole script with a paste site

cosmic dagger
summer stump
faint osprey
#

oh it needs to be public

#

right

cosmic dagger
summer stump
# faint osprey oh it needs to be public

Well, not ONLY. You also have to reference it

You could also do it other ways, but public allows you to do it in the inspector (also another way, but I won't add more confusion)

cosmic dagger
wary delta
faint osprey
cosmic dagger
faint osprey
#

its not a variable its a class

wary delta
#

Ffs

summer stump
#

Collider is also a class. But you use those as variables, right?

cosmic dagger
polar acorn
faint osprey
#

its fixed now u guys gotta chill lol

cosmic dagger
summer stump
wary delta
#

Like 5 people asked you to post the script

cosmic dagger
polar acorn
#

Unrelated to the current situation

green copper
#

I'm using the Modular First Person Controller from the asset store to control a bumper for a pool game type thing, to allow the player to steer around a bumper. I glued a cube to the player and applied a super bouncy physics material, but whenever the ball impacts the bumper it loses all velocity. The physics material is working on the walls of the play space, all velocity is correctly retained.

swift crag
#

that's what I'd look at first

green copper
#

yes, the walls of the play space are made of a cube with the same physics material and it behaves as expected

swift crag
#

a pool game type thing

is the ball hitting the bumper, or is the bumper flying into the ball?

green copper
#

all velocity towards the player is lost, but any sideways skew is retained

#

the ball essentially stops dead and begins drifting to whichever side it already had sideways velocity in

green copper
#

the properties of the two bodies, if relevant

#

and the scene heirarchy

#

the chaos balls are set to be given a 50 velocity kick on game start and have their y level locked to 2 with no gravity, so they skim the ground without drag or gravity and bounce infinitely

eager maple
#

Is there some way to fix A polygon of Mesh ..... in Assets/Prefabs/Office.fbx is self-intersecting and has been discarded.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

swift crag
#

your model has a weird polygon in it

eager maple
#

how would I fix it

swift crag
#

like a quad shaped like this

#

you could go look at the model in Blender and try to find the bad polygon

#

or just ignore it

eager maple
#

hmm, how should I like, make it work

swift crag
#

is something not working right now?

#

that's just an import warning

eager maple
#

the fbx looks horrible

swift crag
#

that's very vague.

eager maple
#

missing a lot of textures and all

swift crag
#

(this is also not a code problem)

eager maple
#

half of the textures

eager maple
swift crag
green copper
wary delta
green copper
wary delta
#

In the script, debug log therb.isSleeping()

green copper
#

should i put that in update or oncollision?

wary delta
#

On collision

green copper
#

enter or exit?

wary delta
#

Both technically, but I'f it's sticking it might not be exiting

green copper
#

returning false on both wall and player collisions

idle karma
#

I'm quite stupid and can't figure this out

short hazel
#

You need to configure visual studio

#

!vs

slender nymph
#

configure your !IDE so you don't make spelling mistakes like that in the future

eternal falconBOT
#
Visual Studio guide

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

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

#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

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

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

swift crag
#

yes, your code editor should be flagging the error for you

idle karma
#

ah yeah fuck I capitalized the b

#

ty

green copper
wary delta
green copper
#

there's a capsule on the back that's part of the player controller, could that be causing it?

wary delta
#

Move the box a little bit further away.

tender stag
wary delta
#

And off the floor a lil

tender stag
#

its because the script is on both items

#

thats why it destroys them both

#

but i dont know a way around it

ashen ferry
#

I guess they both destroy themselves cause they both run that method lol

tender stag
#

yeah

#

i know

#

but how do i go around that?

green copper
wary delta
ashen ferry
#

make one of them special somehow maybe lifetime in the world whoever is newer it gets destroyed for older one

green copper
#

Adjusted positions, no effect

wary delta
#

Might need to move to physics channel

green copper
#

ok

idle karma
#

Does it matter which one I press

rich adder
#

yes

slender nymph
#

select the one you actually plan to use

rich adder
#

and make sure its the one that has Unity Workload installed :p

idle karma
#

Both have unity workload installed

#

I also have this if it matters

#

Idk which one to use either

#

shit's confusing

slender nymph
#

well one is a preview version. surely you didn't just randomly install that for no reason and actually planned to use it for something? or did you just go and install each free version?

short hazel
#

I'd use the third one since it's the stable release. Second one has nothing to do with Unity, and as the description says, it installs the tools required to make software without VS installed

rich adder
#

yup old way of getting VScode to work with unity back in the day was using the Build Tools notlikethis

queen adder
#

any way i can get the geometry of, say, this tree with Physics.OverlapSphere? it doesn't have a collider

slender nymph
#

it doesn't have a collider
then it will not be detected using a physics query like Physics.OverlapSphere

idle karma
wintry quarry
idle karma
rich adder
#

yes

short hazel
#

Yes

queen adder
#

yeah, I'd like to be able to check if there is a mesh at a specific position for an effect

wintry quarry
#

it doesn't need to be perfect. Looks like a CapsuleCollider will be a decent approximation in this case

queen adder
#

and i oop

#

it just needed a mesh collider haha

ashen ferry
#

ayo ur making that horror game?

idle karma
rich adder
queen adder
#

im making that horror game

ashen ferry
#

kekW ill live to see it being made on like 20 platforms

slender nymph
queen adder
#

(what horror game are we referring to)

ashen ferry
#

idk I forgor

queen adder
#

i forgor 💀

ashen ferry
#

your map is dark and u shoot lines they hit walls and entities

#

thats how u navigate

queen adder
#

oh i rember 😄

#

lidar.exe or whatever

ashen ferry
#

yeaa

queen adder
#

this is not lidar game dw :)

rich adder
#

sounds cool

#

like a spin off of Outlast but with newer zoomies technology

queen adder
#

Basically it's a sound-based horror game where your footsteps reveal the environment :)

rich adder
#

DareDevil - the game

queen adder
#

now i just gotta figure out how to apply a mesh collider to this model i imported.

wintry quarry
weary crystal
#

It works if I use " instead of '

#

but why?

rich adder
#

" " for strings

weary crystal
#

oh so ' is for one character and " is for words, right?

rich adder
#

pretty much

weary crystal
#

Ohh, alright.

#

Thanks

cosmic dagger
#

for strings, not necessarily words, but a string of chars . . .

weary crystal
#

Got it.

junior ether
#

if I use the input action on the keyboard "any key" can I print out what key am I pressing?

junior ether
#

no

#

im talking about the new input system

#

with callback context

#

can i print out from the callback context which key im pressing?

weary crystal
#

Uh what am I wrong doing now?

wintry quarry
#

You just have d e with nothing between?

#

and a * b <what goes here??> (c + ..

weary crystal
#

Oh bruh, got it, thanks.

slender nymph
#

yeah unlike when writing the text as a math expression on paper or something where the multiplication operator can be implied, in programming the operators are required

tender stag
polar acorn
tender stag
#

yeah on all items

wintry quarry
#
    private void OnCollisionEnter(Collision collision) 
    {
        if (gameObject.GetInstanceID() < collision.gameObject.GetInstanceID()) return;
        // the rest.
tender stag
wintry quarry
polar acorn
# tender stag what does that do?

The instance ID is effectively a random number assigned to each object. One of them will be less than the other, and that one gets to live

tender stag
#

like this?

#

or have i got the wrong idea

wintry quarry
#

no

#

copy my code

#

you messed up the first part and now it makes no sense

weary crystal
#

!cdisc

eternal falconBOT
tender stag
#

but

#

sometimes when i drop like you can see it gets stacked to the item on the floor, but sometimes the floor item gets stacked to the item which still has velocity

#

how could i make it so that it always gets stacked to the item on the floor?

wintry quarry
#

If you want to do "destroy the one at a higher y position", that should be simple enough to do
basically the same technique as the code I shared, just checking a slightly different thing.

ashen ferry
#

imo implement lifetime like I said im assuming you will want to despawn very old items later on as well it will double as factor which item runs its code

tender stag
tender stag
wintry quarry
tender stag
tender stag
#

and when i throw the original item without splitting the one on the floot gets stacked to the one you threw out

ashen ferry
#

no like imagine your on ground item has lifetime of 40 seconds since it got dropped and your new dropped item has only half of a second since it just started existing in world then you can compare and stack to the older one, solving your current problem + use that lifetime to despawn old items to not clutter

#

what u do in ui dont matter its only ui representation of ur item not like an entity in the world

tender stag
#

yeah but when i split items in the inventory

#

into half

#

i instantiate a new item

#

wouldnt that matter?

ashen ferry
#

is ui item class same as the item you drop into the world?

tender stag
#

look at the hierarchy

ashen ferry
#

why u do that

tender stag
#

wdym

ashen ferry
#

u dont need items to exist in world to have them in inventory

tender stag
#

yeah ik, but when you drop them they wont appear from air

#

so i do need them to exist

#

because when i drop an item out of inventory

#

all i got to do left is set it active

#

and add force

ashen ferry
#

visually they still appear from air

polar acorn
#

Your inventory slots should probably always exist and you just change what sprite and number they display based on what item is in that slot

ashen ferry
#

anyways u need to change ur whole inventory setup for my thing to work so forget it kekW

tender stag
#

yeah to check which one has less momentum is the best option

#

probably

#

yeah im lost, it doesnt work```cs
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.GetComponent<Item>())
{
Item collisionItem = collision.gameObject.GetComponent<Item>();

    if(collisionItem.itemData.maxStack > 1 && itemData == collisionItem.itemData)
    {
        float thisMomentum = GetComponent<Rigidbody>().mass * GetComponent<Rigidbody>().velocity.magnitude;
        float collisionMomentum = collisionItem.GetComponent<Rigidbody>().mass * collisionItem.GetComponent<Rigidbody>().velocity.magnitude;

        int totalAmount = amount + collisionItem.amount;

        if(totalAmount <= itemData.maxStack)
        {
            if(thisMomentum > collisionMomentum)
            {
                collisionItem.amount = totalAmount;
                collisionItem.GetComponent<Rigidbody>().mass += GetComponent<Rigidbody>().mass;
                Destroy(gameObject);
            }
            else
            {
                amount = totalAmount;
                GetComponent<Rigidbody>().mass += collisionItem.GetComponent<Rigidbody>().mass;
                Destroy(collisionItem.gameObject);
            }
        }
    }
}

}```

wintry quarry
#

check if you are the faster or slower object

#

if you're the faster object, jsut return

#

the other object will run its code and destroy you

tender stag
#

when the item touches ground

ashen ferry
tender stag
#

or anything

wintry quarry
#

TryGetComponent would be useful

#

also avoid using GetComponent so much - cache the reference

#

you can also probably just throw that in as the first line inside the if (collision.gameObject.GetComponent<Item>()) block

#

and it should be fine too

unreal imp
#

guys, why is my instantiate not working? I made this condition and even if I set it as true by default, the particle is not generated void Update { if (isInFire) { Instantiate(fireParticles, transform.position, Quaternion.identity, transform); var v = fireParticles.GetComponent<DestroyInRandomTime>(); if (!v.isActiveAndEnabled) { hitsReceived = maximalHitsToDestroy; } } }

wintry quarry
#

You can verify with Debug.Log

short hazel
#

And if it's true, you're getting stuff on the prefab

#

Not the instance you created in the scene

wintry quarry
#

if you just did

public bool isInFire = true;``` that's not going to affect any already serialized components in the scene.
#

You need to actually set it in the inspector

unreal imp
#

oh,thanks

wintry quarry
#

because you probably didn't do it properly

acoustic arch
short hazel
#
var clone = Instantiate(prefab, ...);
var p = clone.GetComponent<T>();
// use 'clone' and 'p'
acoustic arch
#

how come the rotate on the camera returns back to its original after the turn of the mouse variable changes at all? (lines 9-10 and 25-27)

acoustic arch
unreal imp
# wintry quarry show how you did so
{
    public GameObject toiletSherds;
    public GameObject explosionParticlesPrefab;
    public int minimunHitsToDestroy = 6;
    public int maximalHitsToDestroy = 12;
    public int hitsReceived;
    public float impactForceScale = 1.0f;
    public float velocityOfImpactForExplode = 7f;
    public float velocityOfCollisionByObject = 4f;
    public bool isInFire = false;
    public GameObject fireParticles;
    public int random;
    public float maxDetectionDistance = 10;
    public float maxDetectionForce = 5;
    [System.Obsolete]
    private void Start()
    {
        random = Random.RandomRange(minimunHitsToDestroy, maximalHitsToDestroy);
    }
    void Update()
    {
        if (hitsReceived >= random)
        {
            Instantiate(explosionParticlesPrefab, gameObject.transform.position, Quaternion.identity);
            Destroy(gameObject);
            Vector3 position = gameObject.transform.position;
            Quaternion rotation = gameObject.transform.rotation;
            GameObject sherds = Instantiate(toiletSherds, position, rotation);
        }
        if (isInFire)
        {
            Instantiate(fireParticles, transform.position, Quaternion.identity, transform);
            var v = fireParticles.GetComponent<DestroyInRandomTime>();
            if (!v.isActiveAndEnabled)
            {
                hitsReceived = maximalHitsToDestroy;
            }
        }
    }
}
short hazel
#

Somehow Start is marked as obsolete lol

wintry quarry
tender stag
# wintry quarry you naturally need to check if the object HAS a rigidbody before _using_ the Rig...

in theory this should work now```cs
private void OnCollisionEnter(Collision collision)
{
//If the collision is even an item
if(collision.gameObject.GetComponent<Item>())
{
//If you are the slower item
if(gameObject.GetComponent<Rigidbody>().velocity.magnitude < collision.gameObject.GetComponent<Rigidbody>().velocity.magnitude)
{
Item collisionItem = collision.gameObject.GetComponent<Item>();

        //If this item is even stackable and is the same as this item
        if(itemData.maxStack > 1 && itemData == collisionItem.itemData)
        {
            int totalAmount = amount + collisionItem.amount;

            //If the total amount of both items can fit into the max stack size
            if(totalAmount <= itemData.maxStack)
            {
                amount = totalAmount;
                Destroy(collisionItem.gameObject);
            }
        }
    }
}

}```

#

right?

ashen ferry
#

we use Begin(); now

short hazel
#
void Begin() {
  pinMode(1, OUTPUT);
}
unreal imp
short hazel
#

Yeah you should be using Random.Range()

#

It's RandomRange() that's obsolete, the warning should be telling you that

wintry quarry
languid spire
#

Unbelievable

unreal imp
#

😘

languid spire
#

Let me guess, the namespace System and the namespace UnityEngine both have a class called Random

tender stag
#

does awake get called when an object is instantiated?

wintry quarry
unreal imp
#

also anyone knows how to simulate the fire in barrels like gmod?

polar acorn
unreal imp
#

the fire is semi transparent,and it is in a position in the middle of the object which if the rotation of the object changes the rotation of the fire will not be affected either

short hazel
#

Just make sure the particles are simulated in world space (setting to change) and you'll be fine

unreal imp
#

oka

#

wait, to make the particle not rotate relative to its parent object, do you use Quaternion.Identity?

wintry quarry
#

no

#

you simulate it in world space

#

which was the whole point of mentioning that

unreal imp
unreal imp
spare relic
# tender stag

i would recommend against calling get component in any method that gets called beyond Start unless it only runs once

tender stag
#

it runs once

summer stump
# tender stag it runs once

Drop only runs once ever?
It should run every time you drop an item, right? In that case it may be better for item to simply have a reference to its own rigidbody.

tender stag
#

i thought he meant like in update

#

yeah it runs every time you drop an item

ashen ferry
#

what is going on why my draggable rect transform isnt at 1:1 sensitivity https://hatebin.com/viqsujtofv you can see mouse moving centimeter on screen but star image which is child of "StarsRoot"(the thing which is dragged) moves like 3 apparently scale can mess it up but my whole hierarchy is at scale 1 so what else

ashen ferry
#

why double?

wary delta
#

I've never experienced it in unity. I've only had it happen in Maya when the parent transform is += to the child transform because of history

#

Not sure if that helps or not

#

As a hack I've fixed it with extra empty parent

#

Don't know if that works in unity though.

ashen ferry
#

yea idk I shuffled around everything anchors setting position or local position instead of anchoredPosition remade canvas altogether

wary delta
#

Are you using a script to link their positions?

ashen ferry
#

that sensitivity isnt even same when mouse approaches edge of screen it accelerates too im so confused

#

im changing position of empty element with just rect transform according to how mouse moved

wary delta
#

Show script via pastebin

#

Are you using the mouse delta?

ashen ferry
#

thing is at the morning when I did that it worked as I wanted I dont know when it started this bs it just did

timid quartz
#

say I have a script attached to a prefab and like 40 copies of the prefab in a variety of scenes, and I want something to affect all copies of that prefab. Can I just make a static method in that script and then call that static method elsewhere and it'll be called on all copies?

#

I feel like it won't work on unloaded scene copies

wary delta
sly lintel
#

hello, I am currently trying to activate the children of my parent object through a script in the parent object. I figured out how to reference a variable from an entirely different script but now I am struggling with figuring out how to activate each of the children based on the value of the variable from the other script. How do I go about this?

versed light
#

i really dont know how to setup my code architecture for editor stuff -_- theres no simple way for monobehaviours to subscribe to editor events in edit mode

summer stump
#

Dang Brackey! His curse will never leave us! lmao

wary delta
#

Damn lol

#

How do you get from last pixel then?

ashen ferry
#

ig im going to sleep with this big unsolved

#

aint no way bruh

#

always the 2 + 2 = 5 bugs

#

I seriously doubt my code is the issue

#

perhaps I repost in ui

summer stump
# wary delta Only for getaxis?

Only for things that aren't already frame independant.
GetAxis returns a value. For example, GetAxis("Horizontal") returns between -1 and 1 iirc. High framerates will apply that 1 or -1 more often than slow framerates, directly affecting speed. MousePosition is just a position, applying that position quickly or slowly won't change anything, but multiplying it by a small number WILL

#

So, no, not just for getaxis

wary delta
#

Okay, that was my mistake. So what's causing his transform issue?

summer stump
wary delta
#

🍻

ashen ferry
#

cap

#

bro doenst know either wtf is going on

summer stump
#

took a quick look. I would start by logging both the offset and anchored position.

wary delta
#

Divide your rect width and height by 2

#

@ashen ferry

ashen ferry
#

Me 5secs ago: sleep

#

How will that help tho

wary delta
#

Lol do you have a better idea?

#

Your offset is clearly doubling from the vid you posted and you didn't post the the debug log from offset and anchored position so...

ashen ferry
#

Why ur getting defensive im curious it sounded like a solution

#

Anyways im off to sleep thats why I didnt reply to aethenosity

wary delta
#

I'm not getting defensive, just thought it might work

lone sable
#

I change my keybind icon during runtime, and I get this weird overlapping. I can fix it by in editor toggling the button on and off again. However, I was wondering if there was a line of code I could run that I'm not thinking of that could fix it/referesh it? I tried LayoutRebuilder.ForceRebuildLayoutImmediate(item); however no luck.

viral nexus
#

If i set my project to use URP i have to restart?

#

cuz i can't find my pipeline asset

timber tide
#

You may need to create a new renderer asset if there isn't one in your project

red finch
#

hey, I have a unity ragdoll and its floating in the air, I have know idea what i should check for.

sharp oracle
#

Hello I've made a function that basically display a big rectangle (character) and a smaller one (weapon) the function is working well and I've made 2 type of rectangle "white one" and "pink one" (see screen) the problem is I've made a list of big rectangle and a list for the small one but when I press the key r the renderer don't change the "color" of my rectangle I don't know why .https://pastebin.com/c5iXtNzM

real heart
#
CreateBuffers(lod);
        float[] noiseValues = new float[currentBufferSize];

What are buffers ? Are buffers like boxes in which you put your stuff inside ? Also why and when would you need these "boxes" ?

Can't you just put stuff wherever and use it ? Why some stuff requires buffers while other stuff doesn't ? What determines how big the buffers should be ? How do I know if something is compatible with being put in a buffer or not and do buffers come in multiple types and sizes ? Are buffers hardware dependant or can they be whatever ? Do things work faster or slower when using buffers ?

Way too many unknowns for me. Where can I find the answer to all those questions ?

#

Also I am observing 3 types of what appears to be buffer specific operations: Create(), Initialize(), and Release(). Why do buffers need to be initialized, aren't they initialized when they are created by being put inside the script ? And why would you release them ? And don't you need to put the stuff back then ? I don't see any operations related to "putting stuff back in the boxes".

teal viper
polar acorn
eternal falconBOT
#
Posting code

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

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

sharp oracle
real heart
# teal viper It depends on the context. Generally, buffers are arrays of data. And you need t...
public class NoiseGenerator : MonoBehaviour
{
    ComputeBuffer _weightsBuffer;
}

private int currentBufferSize = 0; // Variable to store the current size of the buffer 

public float[] GetNoise(int lod, Vector3 globalOffset)
    {
 CreateBuffers(lod);
}

void CreateBuffers(int lod)
    {
        int requiredBufferSize = GridMetrics.PointsPerChunk(lod) * GridMetrics.PointsPerChunk(lod) * GridMetrics.PointsPerChunk(lod);
        if (_weightsBuffer == null || requiredBufferSize != currentBufferSize)
        {
            ReleaseBuffers();
            _weightsBuffer = new ComputeBuffer(requiredBufferSize, sizeof(float), ComputeBufferType.Default);
            currentBufferSize = requiredBufferSize;
        }
    }

    void ReleaseBuffers()
    {
        if (_weightsBuffer != null)
        {
            _weightsBuffer.Release();
            _weightsBuffer = null;
            currentBufferSize = 0;
        }
    }```
teal viper
sharp oracle
polar acorn
#

Buffers are essentially packages that can be shipped to your gpu, they have some special operations because you can't just pass whole data to the GPU, the rate is very limited. Buffers can massage the data in ways the GPU can understand to reduce the amount of times you have to do the slow transfer process. Think of it kind of like putting something in one of those special boxes they have at FedEx that are pre-priced, rather than having to weigh and package it yourself and figure out the proper postage for it

#

A little bit of pre allocation can give some pretty significant speed boosts

real heart
polar acorn
#

There's a lot of overhead when sending any data, that is the same no matter how big

real heart
# polar acorn Yes actually. A great analogy.

So basically between the cpu and the gpu there is like a bridge. And you need to send 200 soliders to the gpu. Instead of sending one solider at a time, you pack them all in a big car and send them that way right ? This way you don't have to send one solider at a time and wait for them to arrive and then send the next one and so on. Is this correct ?

wary sable
#

for some reason I cant refrence Cursor in my script, all im trying to do is Cursor.visible = true;

polar acorn
#

You can think of "Create" as making the car, "Initialize" being loading the soldiers in it, and "Release" being letting them all out so you can send another one

real heart
polar acorn
teal viper
real heart
# polar acorn You can think of "Create" as making the car, "Initialize" being loading the sold...

What boggles me about this, is after a buffer gets released, isn't it supposed to be re-used maybe later ? Like what if I want to send another batch of 200 soliders to the GPU, but last time I used the buffer, the last operation was released. So the car is basically on the other side to the GPU. Don't buffers need to be "Called back" to be re-used or does the whole thing run like a loop and I do not need to worry about such things ?

Like does the buffer gets re-created automatically again and "dispatched" again by itself if needed ?

polar acorn
wary sable
sharp oracle
polar acorn
wary sable
polar acorn
# wary sable

You are using UIElements which has its own Cursor class, if you want to use the built in one, you can use UnityEngine.Cursor instead

sharp oracle
real heart
teal viper
#

That beings said, you can't send data to the GPU outside of buffers afaik. Even if it's one element it has to be a buffer.

wary sable
teal viper
real heart
teal viper
# sharp oracle Yes but isn't that code ```csharp if (renderer != null && weaponstypeList[change...

I don't see that code in this if block:

        if (Input.GetKeyDown(KeyCode.R))
        {
            changeweapon = changeweapon + 1;
            UnityEngine.Debug.Log($"toto a appuyé sur r, la valeur de changeweapon : {changeweapon} {string.Join(", ", weaponstypeList)}");
            UnityEngine.Debug.Log($"toto couleur {weaponstypeList[changeweapon]}");
 
            //if (weaponstypeList[changeweapon] == 1) 
            //{
            //    UnityEngine.Debug.Log($"element actuelle et sa couleur! {weaponstypeList[changeweapon]}");
            //}
 
            //else
            //{
            //    UnityEngine.Debug.Log($"element rooooooooooooooooooooose actuelle et sa couleur! {weaponstypeList[changeweapon]}");
            //}
 
            if (changeweapon >= weaponsList.Count)
            {
                changeweapon = 0;
            }
        }
teal viper
sharp oracle
real heart
teal viper
sharp oracle
#

I got this error:

teal viper
sharp oracle
#

it's that line ```csharp
Renderer renderer = weaponsList[changeweapon].GetComponent<Renderer>();

#

the thing I don't understand is that it "work" on press p but not on press r

teal viper
#

It's probably the elements in the list.

sharp oracle
#

from what I've understand it only "work" when list index is at 0 but I don't understand why

#

better print

summer stump
sharp oracle
#

so index is just the index like elem nb 9 of the list current element refer to either 1 or 2 for the color of the object and whole list is just the whole list of color

summer stump
#

Can you include the weaponsTypeList.Count in that?

sharp oracle
#

ok

#

I don't get it how I got this error while I have the same list on the print and it was working before ```csharp
UnityEngine.Debug.Log($"list index current element of the list and whole list and weaponsTypeList.Count : {changeweapon} '---------' {weaponstypeList[changeweapon]} '---------' {string.Join(", ", weaponstypeList)} '---------' {weaponsTypeList.Count}");

summer stump
#

@sharp oracle You wrote weaponsTypeList instead of the previous weaponstypeList

#

my fault for writing it that way

#

I missed that you had a lowercase on the second word

indigo wadi
#

Hi, I'm new using Unity and i'm still learning how to write code in C#, and doing a school work for mi programation class this isn't working, Can someone help me plz? Testing different things I reach to the conclusion that the part isn't working is "void OnTriggerEnter (Collider other)" and I don't know how to fix it. (English is my second language, so sorry for any grammar mistake, thnks)

sharp oracle
summer stump
sharp oracle
summer stump
sharp oracle
#

I understood the problem I just copy paste withouth re reading

#

here is the print

summer stump
sharp oracle
#

Is my error linked to an non existing elem on weaponstypeList ?

hot hinge
#

can someone please help me in unity talk

indigo wadi
summer stump
teal viper
sharp oracle
summer stump
#

Hmm... also, it's a list of ints, which can't be null. But... something is going on.
What is the actual code on line 81? The line causing the error
Is it this:
#💻┃code-beginner message

Because then the null would be in the weaponsList, not weaponstypeList
Debugging the latter wouldn't help find the issue in that case

indigo wadi
summer stump
#

Oh, it's a bullet.
Is it going fast? Is the bullet collider small?

#

Are you moving it by "teleporting"
(transform.position += whatever)?

#

Sometimes it can simply teleport past the collider without actually colliding

teal viper
sharp oracle
indigo wadi
teal viper
summer stump
#

Does the OTHER object have it set to trigger?

indigo wadi
summer stump
sharp oracle
ivory bobcat
# sharp oracle I now got this

The first is likely a false positive (or maybe it's real - internal). The others insist that you've got a reference to null and attempting to use it.

sharp oracle
#

oh I see so what do you think I'm doing understand

#

I tried to understand since but I don't find it

ivory bobcat
#

Can you show the !code?

eternal falconBOT
#
Posting code

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

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

sharp oracle
#

yes

#

6

ivory bobcat
#

Weapon list at the particular index did not have anything valid. The element was null.

summer stump
sharp oracle
#

Oh I'm dumb as fuck

#

result

#

code line ```csharp
UnityEngine.Debug.Log($"list index current element of the list and whole list and weaponsTypeList.Count : {changeweapon} '---------' {weaponsList[changeweapon]} '---------' {string.Join(", ", weaponsList)} '---------' {weaponsList.Count}");

ivory bobcat
#

Result of what?

sharp oracle
#

pressing r

teal viper
#

There's like 5 sec between the error and the log message. What's going on?😅

sharp oracle
#

I just press key r

teal viper
#

So does the error come out when you press r or before that? I feel like you're hiding something

sharp oracle
#

I first press key p to "make" the player and little rectangle this work fine but when I press r the error occure

#

not before

ivory bobcat
#

The two did not occur back to back

teal viper
sharp oracle
#

just tried right now

sharp oracle
teal viper
#

Ok, so it comes before the errors.

#

Which doesn't make sense.

ivory bobcat
#

You should move the log before the error line 81

teal viper
#

Unless you changed the order in your code.

ivory bobcat
teal viper
ivory bobcat
#

Where the first successfully logs and the rest just blows up with an error

sharp oracle
#

I've made it like this

summer stump
#

The debug line isn't showing the whole line. I'm interested in the count

sharp oracle
#

oh

ivory bobcat
#

Can you show the entire updated code from a link?

sharp oracle
#

yeah

teal viper
#

Really hard to read with all these dashes, but it seems like the elements after 0 are null.

sharp oracle
teal viper
#

No. Id prefer you to just look at the object in the debug inspector as I suggested half an hour ago. And take a screenshot of it.

sharp oracle
#

I have but It's not that understandable

north kiln
#

Why does it also say NewBehaviourScript

ivory bobcat
#

You've only got one weapon in the list

sharp oracle
#

let me add more weapon

#

wait isn't that supposed to fill the list ? ```csharp
private void Awake()
{
// Appelé avant le Start, souvent utilisé pour initialiser des variables
// Générez un nombre aléatoire entre 1 et 2 pour WeaponType dans Awake

    for (int i = 0; i < 3; i++)
    {
        WeaponType = UnityEngine.Random.Range(1, 3);
        weaponstypeList.Add(UnityEngine.Random.Range(1, 3));

        if (WeaponType == 1)
        {
            weaponsList.Add(spawnedEntity);
            weaponstypeList.Add(1);
        }
        else
        {
            weaponsList.Add(spawnedEntity);
            weaponstypeList.Add(2);
        }
    }
}   
north kiln
#

weaponsList and weaponstypeList are different lengths

#

I also have no idea what that if statement achieves

sharp oracle
north kiln
#

It's generally bizarre code that is unclear to me, doesn't help that I can't speak french 😄

sharp oracle
sharp oracle
north kiln
#

Yes but you could just write:

weaponsList.Add(spawnedEntity);
weaponstypeList.Add(WeaponType);
sharp oracle
#

I just removed the first add on the weapontypelist

#

now they should have the same lenght

summer stump
#

Are the lists supposed to be matched? Could the weapon just have its own type as a property?

north kiln
#

There are two other concerns

#

You are not printing weaponTypeList.Count in that log statement

#

you print changeweapon

ivory bobcat
#

I'm assuming his nre is solved now

summer stump
sharp oracle
north kiln
#

Regardless, the error is an NRE, not an index out of range, so none of the prints matter, no?

sharp oracle
ivory bobcat
#

Consider having a struct hold the pair weapon and type in a single list to not have two lists.

timid quartz
#

how would I in script un-check these check-boxes? I know I can Get Component but then how do I make them inactive?

sharp oracle
#

but from what I've seen you can't generate a circle from a rectangle object

ionic totem
#

Can anyone help with a player controller issue here?

timid quartz
idle orbit
#

where GameObject is the object to turn on and off

timid quartz
#

ty!!

north kiln
ionic totem
#

Thanks, so my character keeps running in circles when I press W

#

and my camera to look around doesn't work 😦

ivory bobcat
sharp oracle
#

I think I understand the problem it only work withouth showing error when I use the first element of the list ```csharp
Renderer renderer = weaponsList[0].GetComponent<Renderer>();

ionic totem
#

!bug

eternal falconBOT
#

🪲 To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.

📝 If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click ‘Report a problem on this page’!

💡If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.

For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting

ivory bobcat
sharp oracle
#

yes just saw that by doing test myself

#

but how I get only one weapon but the len of my list isn't one ?

ivory bobcat
#

Orange indicates the null elements. Blue including commas were the elements in the list - notice the blanks between commas.

#

Green were valid elements which only occurred with element zero

north kiln
#

It would be much easier to use the debugger than endlessly iterating on these print statements

sharp oracle
north kiln
cosmic dagger
sharp oracle
#

isn't that debugger ?

ivory bobcat
#

They meant IDE debugger

sharp oracle
#

that ?

ivory bobcat
#

Where you'd attach the process and include break points..

#

Visual Studio debugging

sharp oracle
#

oh

#

thanks

north kiln
sharp oracle
#

thanks

#

after looking searching and struggling I've understand exactly what isn't working

#

it's that ```csharp
weaponsList.Add(spawnedEntity);

#

the spawnedEntity I'm adding to my list mean "nothing" to it so it's make like it's not there

north kiln
#

If spawnedEntity was null it would only cause an error when it was accessed, and that line does not access it

sharp oracle
#

I see

teal viper
sharp oracle
#

I think so , when I print elem 2 so weaponsList[1] it print nothing

sharp oracle
teal viper
teal viper
summer stump
#

In the top middleish of visual studio it shows "attach debugger"

hearty ivy
#

Can anyone help me with sorting layers for a topdown 2d game

#

how can i make all my sprites in my sprite sheet pivot without breaking everything

#

i think that is my problem

#

the sprite sheet is my player sprite sheet so

wary sable
#

Hello, I am trying to make an inventory system and was making a method to add armor and weapons to lists for 'currently equipped'. I have two classes, Weapon and Armor, which both extend an Item class. I wanted to use one insert method to simplify and add more scalability to my system. Currently I have: private void EquipItem(Item item) { if(item is Armor) { equippedArmor.Add(item); } else if(item is Weapon) { equippedWeapons.Add(item); } }
Which isn't working because item is defined as an 'Item' is there any way around this?

#

I also cant make Item an interface since it has monobehavior methods inside it

patent portal
#

Curl error 56: Receiving data failed with unitytls error code 1048578 what kind of this error?

timber tide
wary sable
timber tide
#

Strange, well, you can always add like an enum for weapon/armor then assign their type inside of their own respective class and instead check that

north kiln
#

Nobody knows the context, elaborate by mentioning what came up when you searched about it

wary sable
#

how would I remove an element from an array without resizing?

timber tide
#

arr[i] = null

wary sable
#

alright, is there a way to do it by object instead of indice?

#

said objects are not primitives*

timber tide
#

Like, clean up an object entirely? You don't really use deconstructors in c#, so if you want an object to be collected by the garbage collector, you'll need to remove all references relating to it.

wary sable
#

I moreso meant something similar to List.Remove(myObject) so I wouldnt have to use a loop or lambda to remove it from the list.

north kiln
#

IndexOf and then setting that index to null

timber tide
#

ah, right

north kiln
#

Though you've really got to question why you're using an array

wary sable
#

using it for an inventory element displaying armor / weapons (2 different arrays). Since there is a limited number of slots for armor and weapons I figured an array would be best since I could easily limit the size without having to add a bunch of checks

wary sable
timber tide
#

That's fine if you're not extending your inventory at all

wary sable
queen adder
wary sable