#💻┃code-beginner

1 messages · Page 106 of 1

polar acorn
#

If itemData being null is a normal occurrence, there's basically no better way to do it than this

autumn tusk
#

is it possible in c# to define multiple case statements at once

#

so say for instance im generating a random number between 1 and 5

#

if i get a number between 1 and 3 can i define that case in one line

eager elm
polar acorn
tender stag
#

if this is how i manage my movement, how would it be possible to add force to the rb object?

#

or do i have to make the movement by adding a force instead of changing the velocity?

eager elm
verbal dome
#

Add a force to reach the target velocity

#

desiredVelocity here would be pretty much the moveVelocity in your current code

tender stag
#

so something like this?

verbal dome
#

Yeah, and then tweak moveForce to your liking

#

It affects the acceleration speed basically

tender stag
#

that works soooo goooood

#

why didnt i think of this

#

thanks man

verbal dome
#

Idk I rarely see anyone suggest it, it works really well

tender stag
#

wait why is my player falling slow now?

verbal dome
#

Oh yeah, better set difference.y to zero

#

At least when not grounded

#

So that it only affects your horizontal movement

tender stag
eager elm
#

why do you apply gravity yourself instead of letting the rbs build in gravity handle it? 😮

tender stag
#

its not enough

#

i mean i could increase the mass

#

true

verbal dome
#

Mass doesn't increase the effect of gravity

#

Drag can affect it tho

eager elm
#

it has a gravityScale build in

verbal dome
#

I think that's only in 2D rigidbodies

stuck palm
#

its checking if there is any item data in the container

verbal dome
#

If your character is scaled too big then it will also appear to fall slower

#

It's all relative to the Physics.gravity settings. The default value assumes that 1 unit = 1 meter

tender stag
#

not anything else

verbal dome
#

Yeah that's probably what they meant, in Rigidbody2D you can set a multiplier per rigidbody

#

Not in 3D

tender stag
#

one more thing, i thought moveForce would be the acceleration, but the higher i increase it the faster the moveSpeed is, how can i have like an acceleration variable?

verbal dome
#

smaller moveForce = slower acceleration

#

I would rename it acceleration or something though

tender stag
#

yeah that makes sense now

#

thanks again

chilly vigil
verbal dome
#

That's just a shrinking object that destroys itself when it's < 0 scale

#

It will work for the ring visuals yeah, but you need to check each player's distance from the center and compare it with the radius

#

To check if they are outside of the ring

#

You can probably tweak it a bit to use the Y too. Show what you have?

#

Do you understand how it works?

#

Also please look at how to format your code in your IDE

#

In the transform.position = ... line you can add the camera's Y position (multiplied by some value, maybe amountOfParallaxEffect) to transform.position.y

brave tapir
#

Hi I just tried to make a WebGL build, switching over to WebGL worked fine but then when I tried to build, it ended in build failure with these error messages:

#

unity is inherently a 3d engine so it will always include z

verbal dome
#

2D games are still in 3D space

stuck palm
#

can you virtual and override unity functions like start and update?

short hazel
verbal dome
#

They can even be IEnumerators or async

rich adder
safe root
#
public class Jumping : MonoBehaviour
{
    Rigidbody rigidBody;
    public float jumpPower = 5f;
    public Vector3 moveDirection;
    void Start()
    {
       rigidBody = GetComponent<Rigidbody>();
       moveDirection = new Vector3 (0.0f, 2.0f, 0.0f);
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            rigidBody.AddForce(moveDirection * jumpPower, ForceMode.Impulse);
        }
    }
}

Why ain't my character not jump?

rich adder
verbal dome
#

And check the value of jumpPower in the inspector

brave tapir
fair flicker
safe root
rich adder
safe root
rich adder
#

pick one

rare plume
#

!code

eternal falconBOT
safe root
stuck palm
#
 private void CheckOverlap()
    {
        Collider[] colliders = Physics.OverlapBox(transform.position, bc.size / 2, quaternion.identity, _layerMask);
        foreach (var collider in colliders)
        {
            if (collider.gameObject != gameObject)
            {
                Item item = collider.gameObject.GetComponent<Item>();
                if (item != null)
                {
                    HandleItemCollision(item);
                    return;
                }
            }
        }
        ResetVariables();
    }

How can i grab the closest collider? right now if there are multiple in the overlap it craps out

gaunt ice
#

iterate all colliders and check the distance between them, store the collider with minimum distance

queen adder
short hazel
cosmic grove
#

guys uh why does this say "object reference not set to an instance of an object"?(which i take means this, the very thing thats doing it, doesnt exist?)

short hazel
#

info is null

cosmic grove
#

oh

polar acorn
#

DOUBLE KILL

cosmic grove
#

my bad

#

thanks

queen adder
worn fulcrum
restive solstice
#

!code

eternal falconBOT
restive solstice
#
using System.Collections.Generic;
using UnityEngine;

public class Checkifincameraview : MonoBehaviour

bool alreadyWon = false;
{
     Camera camera;
    MeshRenderer renderer;
    Plane[] cameraFrustum;
    Collider collider; 

    
    // Start is called before the first frame update
    void Start()
    {
        camera = Camera.main;
        renderer = GetComponent<MeshRenderer>();
        collider = GetComponent<Collider>();
    }

    // Update is called once per frame
    void Update()
    {
        var bounds = collider.bounds;
        cameraFrustum = GeometryUtility.CalculateFrustumPlanes(camera);
        if (GeometryUtility.TestPlanesAABB(cameraFrustum,bounds))
        {
            if (alreadyWon)
            Invoke("LesGo",10);
            
            
        }
    }

    public void LesGo()
    {
        Debug.Log("Les goooo!!!!");
    }
} ```
#

how do I fix these errors?

cosmic grove
#

looks like a syntax error

calm coral
cosmic grove
#

see if you made a mistake somwhere

#

real

#

irrelevant question ,doesnt the ide show the error? like it wont compile unless the errors are fixed

calm coral
calm coral
#

I was thinking about the same

cosmic grove
#

i have no idea. i really shouldnt be coding at 1 am. does a lot to a tiny mind like mine.

#

im going to sleep

restive solstice
polar acorn
eternal falconBOT
timber tide
#

Say I have a transform and I want a local position such that if I feed it a Vector3(0,0,5) then I would receive a new value relative to the transform (depending on its rotation/direction) as a new Vector3

#

without affecting the transform itself

#

I think translating it and grabbing the position is probably what I want but I guess I have to translate it back which makes little sense

#

probably would prefer to do it with a matrix4x4

restive solstice
boreal tangle
#

Does someone know what's wrong with this grounded function

#

Update keeps printing air even when the player is on the ground

rare basin
#

!code

eternal falconBOT
boreal tangle
#

I don't have access to discord on my computer

rare basin
#

🤷

#

you can use discord in the browser

polar acorn
rare basin
#

ok i need to save it xD stealing

boreal tangle
stuck palm
#

how do flush a variable? like make it have no value

polar acorn
polar acorn
stuck palm
#

like null or what

polar acorn
#

"no value" depends on whether your type is nullable or not

stuck palm
#

it says its expecting an expression

boreal tangle
stuck palm
#

i think my thing is nullable

polar acorn
restive solstice
polar acorn
boreal tangle
polar acorn
#

If the ground starts inside the box, it also won't be detected

boreal tangle
#

But it doesn't. The box cast starts at the players.orgin and is the size of the players collider

#

Which is square

polar acorn
restive solstice
boreal tangle
#

I'n the air away from the platform.

polar acorn
polar acorn
boreal tangle
#

I could only show the code through hatebin. I don't have access right now to discord on my computer. Il wait till I'm home to get that.

restive solstice
polar acorn
#

If it's being destroyed, something you wrote is doing it

#

It doesn't just destroy of its own volition

restive solstice
stuck palm
#

how do you make it so when you click an error you can highlight what is writing the error?

restive solstice
#

double click it should show you the line in which the error accrued

stuck palm
willow scroll
verbal dome
stuck palm
verbal dome
#

Then you single click the log message and it highlights that object

polar acorn
#

Is this a custom error or one unity provides?

willow scroll
#

it does write a GameObject if the error's associated with any.

polar acorn
#

Errors already do that by default.

stuck palm
#

i want to see what object is causing this error

willow scroll
polar acorn
#

Check while the game is running, when you get that error

willow scroll
#

oh, well, it should give you a GameObject with Item.cs script when you click at the error

verbal dome
#

I feel like it doesnt always work as it should 🤔

willow scroll
verbal dome
#

Is Item a script on a gameobject? Or a SO? @stuck palm

exotic matrix
#

hey! was wondering what the best way to create a skybox with labelable stars?
i want for the player to be able to look at the stars, and name them as they wish
and i was wondering what the best technique to go about this would be
probably a way to vague explanation but any help would be appreciated!!!
thanks in advance!!!

stuck palm
#

when an object is created it calls start right

exotic matrix
#

oh shoot this question would probably be betetr suited for code advanced

exotic matrix
exotic matrix
#

not looking for like a step by step, just some ideas u guys might have :3

restive solstice
#

how come my bullets aren't doing any damage and they just bounce of the base? base has a health script and the bullet has the damage script

harsh owl
#

How can i make my car drive in the direction its facing and not in the previous direction? Currently when i drive and then steer in a direction, my car drives in the old direction and not in the direction its facing

https://gdl.space/upubekezum.cpp

verbal dome
#

It should already be relative to your car's direction since you are using AddRelativeForce 🤔

short hazel
exotic matrix
#

that could help identify if a player was looking at a star

#

but would it work similarly for detecting if a player is looking at a specific star?

#

i guess jsut checking the vector rotation of the camera right?

short hazel
#

The direction from the player to the star is for a specific star

harsh owl
verbal dome
exotic matrix
#

oh!! yea i think i understand now 🙂

thank you thank you! i was mostly looking torwards how i should approach the idea in the firstplace

#

very helpful :))

harsh owl
#

man this is frustrating

verbal dome
#

@harsh owl is it currently rotating as you expect?

harsh owl
#

ill show you wait

polar acorn
# harsh owl its not tho

Show a screenshot of this object selected, in the scene view, with the Transform gizmo visible (showing the three arrows)

harsh owl
restive solstice
#
using System.Collections.Generic;
using UnityEngine;
using System;

public class Basehealth : MonoBehaviour
{    public static event Action OnPlayerDeath;
    public float health = 100f;
    public static Basehealth Instance;

    public Transform player;

    private void Awake()
    {
        Instance = this;
    }
    public float AddBasehealth(float amount)
    {
        return health += amount;
    }

    public void DecreaseBasehealth(float amount)
    {
         health -= amount;

        if (health <= 0)
        {
            health = 0;
            Debug.Log("base destroyed");
            player.gameObject.SetActive(true);

        }
    }
}```       Hp code  ```using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Damagedealing : MonoBehaviour
{
    public float amount = 10;

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.GetComponent<Health>())
        {
            Health.Instance.DecreaseHealth(amount);
            Debug.Log("Hit");
        }

    }

    private void OntrTggerEnter(Collider other)
    {
        if (other.gameObject.TryGetComponent(out Health health))
        {
            health.DecreaseHealth(amount);
        }

    }
}  ```  Damage code
verbal dome
# harsh owl

Oh well that works just like the code tells it to work

polar acorn
harsh owl
restive solstice
verbal dome
#

You can try to Vecror3.RotateTowards the velocity towards transform.forward @harsh owl

restive solstice
polar acorn
#

Show the inspector of that object

#

Also, hang on, does everything in the project all share the same health value?

#

That seems... odd

restive solstice
#

no

polar acorn
restive solstice
#

I tweak in in th einspector

polar acorn
#

This is a singleton

stuck palm
#

does itemdrop.start execute before the code i pointed out happens?

stuck palm
#

so what the hell 😭

polar acorn
#

Start runs before the first Update the object is alive for

short hazel
#

Awake will run though

stuck palm
#

im getting a dumbass error that shouldnt be happening

violet token
restive solstice
#

how so?

polar acorn
#

I'm assuming the error is on the line with the arrow

#

meaning itemdrop is null

stuck palm
#

no no

#

the error is happening on the itemdrop being created

#

its saying itemdata is null

#

when i set it

violet token
polar acorn
stuck palm
#

i already deleted the error from the screenshot i showed

#

i tried to run a piece of c ode from item drop that wouldnt work because start hadnt run yet

polar acorn
restive solstice
#

I don't under stand the question?

polar acorn
#

Presumably you want different objects to have their own health instead of one shared script

restive solstice
#

yes

harsh owl
visual hedge
#

why does debugLog name every single enemy by the name, but at the end I only get the last one in loop added X times

polar acorn
violet token
# restive solstice it does

Bullet (Has rigidbody), Base (Has Health Script with OnTriggerEnter with Collider set to trigger). When bullet Enters the Trigger, the Trigger should detect the bullet get the damage and apply to base

#

No OnCollision needed

verbal dome
restive solstice
verbal dome
violet token
polar acorn
# visual hedge why does debugLog name every single enemy by the name, but at the end I only get...

Okay, strap in because this one's a fucking doozy. What you're running into is an annoying little prick of a problem called "Variable capture". AddInfo is defined outside this loop, meaning every iteration of the loop is modifying the same instance. Since it's passed by reference, what you're doing is adding multiple copies of the same variable to the list, and every time you change a field on it, it's affecting every copy. This can be really nasty to run into and not notice so it's good you caught this problem. What you need to do is create a new AddInfo (whatever type that is) inside the foreach loop, so each iteration adds a brand new instance to the list

#

This is the easiest to spot form of it, with a proper foreach loop, but if you start doing anonymous functions with lambdas this is gonna be the bane of your existence and despite knowing it exists I still end up accidentally doing this every project I make and losing days to trying to track down the source of the problem

visual hedge
polar acorn
restive solstice
#

changable methods, variables, classes?

small gull
#

where do i put errors i need help fixing

polar acorn
#

If you don't know exactly why you are using static, you should not be using it

violet token
# restive solstice Im trying

Check this out

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

public class Health : MonoBehaviour
{
    public int maxHealth = 100;
    public int currentHP;

    public void DamageHP(int _damage)
    {
        if (currentHP <= 0) Dead();
    }
    public void AddHP(int _health)
    {
        currentHP += _health;

        if (currentHP >= maxHealth) currentHP = maxHealth;
    }
    public void Dead()
    {
        Debug.Log("Wasted!");
    }
    private void OnTriggerEnter(Collider other)
    {
        Projectile bullet = other.gameObject.GetComponent<Projectile>();
        if (bullet != null)
        {
            switch (bullet.type)
            {
                case BulletType.Heal:
                    AddHP(bullet.value);
                    break;
                case BulletType.Damage:
                    DamageHP(bullet.value);
                    break;
            }
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum BulletType
{
    Damage, Heal
}
public class Projectile : MonoBehaviour
{
    public BulletType type;
    public int value;
}
violet token
polar acorn
#

At least throw in a spelling mistake somewhere to see if they're paying attention

polar acorn
violet token
#

This would not fit his situation if copy and pasted lol good try

visual hedge
polar acorn
visual hedge
polar acorn
violet token
visual hedge
polar acorn
ionic fjord
#

I'm a begginer.
I have a gameObject and I want to store as variable the sprite of the children of the gameObject. How can I?

polar acorn
#

The actual image file or the component that draws it in the game

ionic fjord
polar acorn
# ionic fjord the image file

So, what you'd want to do is make a public or serialized SpriteRenderer variable, drag in the object with the sprite you want, and do .sprite to get the sprite from it

ionic fjord
#

and then I want to change the sprite with a .png from the assets (I have to load it somehow)

violet token
polar acorn
ionic fjord
#

Sprite frame;
and to refear at the sprite of the Sprite Renderer of the children of the gameObject?

#

.GetComponent<Item>() ?

polar acorn
#

if you want the sprite a renderer is currently using you have to reference the renderer

sage mirage
#

Hey, guys! Can I use Time.timeScale with IEnumerators?

violet token
polar acorn
ionic fjord
#

Ok, so if the gameObject "OMORI" have a child called "Frame", to refear at the sprite of the sprite Renderer I have to call:
gameObject.Frame.GetComponent<Sprite Renderer>().sprite ?

ionic fjord
sage mirage
#

When I use AudioSource.stop or AudioSource.Pause on my I enumerator it doesn't pause and stop at all and I am using both wait for seconds and time.timescale inside my enumerator.

viral hound
#

I made a dash that on hold, it adds a constant force in the orientation of the camera (so wherever youre facing), but the forcemode.force is a lot stronger vertically. idk why its like this and I commented out the rest of the movement code and it still does the same thing. How do i fix it?

violet token
ionic fjord
#

OMORI > frame > Sprite Renderer > Sprite as a variable (type Sprite)

Sprite frame;
Sprite new_frame;
    void Start()
    {
        new_frame = Resources.Load<Sprite>("Assets/animations/sprites/OMORI emotion UI sprites.png");
        frame = gameObject.frame.GetComponent<Sprite Renderer>().sprite
        frame = new_frame
    }
```...
Sound good?
polar acorn
violet token
polar acorn
#

And there's no reason to store the original sprite, you want to set the renderer's .sprite

polar acorn
violet token
#

Thats not what I am saying

ionic fjord
polar acorn
#

There's also protected which can be accessed by this class or any child classes, but its uses are limited

ionic fjord
#

class is a function, right?

polar acorn
#

No, a class is a class

#

Defined by the word class

violet token
#

Im saying at the very beginning a sprite database can be made for easy reference and switching at runtime instead of drag and drop constantly, automation > manual labor

ionic fjord
polar acorn
languid spire
#

several

polar acorn
violet token
verbal dome
polar acorn
violet token
#

@ionic fjord In your Assets folder create a folder named "Resources". within that folder create your sprite folder containing your sprites

polar acorn
#

They should not be using resources

#

Don't tell them how to solve the issue they should not be having

#

It's just going to confuse things more

violet token
#

Your way is not the only right way and from what I see instead of helping him you became a university teacher and the problem has gotten worse lol

polar acorn
violet token
#

Im not going to argue, good luck friend

polar acorn
violet token
#

@ionic fjord Are you setting the sprite one time for the rest of the game or would you like to be able to change it to any other sprite at any point during the game

polar acorn
#

Resources.Load should be used when the names are not known beforehand, such as something like an item_1387 or other numbering system

ionic fjord
#
    public SpriteRenderer frame_renderer;
    public Sprite new_frame;
    // Start is called before the first frame update
    void Start()
    {
        //Getting the Animator component
        new_frame = "Some How to load the .png";
        frame_renderer = gameObject.frame.GetComponent<SpriteRenderer>();
        frame_renderer.sprite = new_frame;
    }```
Kinda?
frame is a child of the gameObj
polar acorn
polar acorn
ionic fjord
#

Assets\Emotion.cs(18,37): error CS1061: 'GameObject' does not contain a definition for 'frame' and no accessible extension method 'frame' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)

#

frame is a child, what's the code to refer to it?

#

not gameObject.frame ?

short hazel
#

None, you drag-drop it

polar acorn
short hazel
#

The only code that should be there is the one that changes the sprite

polar acorn
#

You should be dragging it in

#

not setting it in code

ionic fjord
#

there is no way to set the sprite in script?

#

(may I'm not understandin)

violet token
# ionic fjord ``` public SpriteRenderer frame_renderer; public Sprite new_frame; /...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpriteScript : MonoBehaviour
{
    SpriteRenderer frame_Renderer;

    //You can pre set this in the inspector
    Sprite new_Frame;

    void Awake()
    {
        //You can Load Sprite from File Path
        frame_Renderer = GetComponentInChildren<SpriteRenderer>();

        if (frame_Renderer != null) frame_Renderer.sprite = new_Frame;
        else Debug.Log("No Sprite Renderer Found");
    }
}
polar acorn
stuck palm
#

how do i make it so this physics overlap box goes a little bit forward?
Collider[] colliders = Physics.OverlapBox(transform.position, bc.size / 2, Quaternion.identity, _layerMask);

polar acorn
#

You tell it which renderer and which sprite by dragging them in

violet token
short hazel
#

Offset the overlap along local forward, at a specific distance

violet token
# ionic fjord with Resourses.Load right?

Yes but you only want this to run once during the boot up of the game. Then throughout the game you will always have the sprite available to you without calling Resources

polar acorn
#

You just drag them into a list instead of a single value

ionic fjord
violet token
short hazel
#

If you need multiple sprites you can make an array and drag them in. No need to go overkill with Resources

stuck palm
#

tf

polar acorn
short hazel
#

They're just starting out

ionic fjord
polar acorn
#

Resources should not be used here

violet token
#

The OP literally repeatedly saying "Change through script" or am I just crazy?

polar acorn
short hazel
#

a = b- that's how you change through script

violet token
#

Correct me if I'm wrong but OP does not want to use inspector

verbal dome
polar acorn
violet token
#

Making a list and drag and drop involves inspector

polar acorn
#

That's going to add a lot of needless complexity for zero gain

#

It's going to make the project slower, more complex, and more error prone for literally no reason

violet token
#

It's not for you to decide lol I'm just helping a person with what they asked for not what you think is best

#

Running once at the very start is going to slow things down?

short hazel
#

They didn't ask for Resources explicitly

stuck palm
#

what are resources

polar acorn
short hazel
#

They're new to the engine so assignment through Resources is the very last thing you'd want to suggest

violet token
polar acorn
#

You're making it impossible to answer the actual question because you keep misinterpreting the problem and muddying the water

verbal dome
#

Inspector referencing is one of the first unity scripting subjects one should learn

short hazel
violet token
#

its not even complicated lmaoo.
Run Resouces.Load to grab all the sprites in a folder throught them in a dictionary/List and make a static refernce, so much work

ionic fjord
#

or in alternative I can put all images in scene and make transparent those I don't want and make 1 visible at the time

But I'll prefer to change the sprite of the "frame" child

short hazel
#

"Not even complicated" is subjective lol

polar acorn
#

I'm a begginer.

short hazel
#

You need to adapt your answers to the experience of the user

violet token
short hazel
#

lol what?

violet token
#

Set the sprite through script

short hazel
#

Set the sprite, of the renderer

#

Not preload it into some variable

violet token
#

And the OP refuses to drag and drog the sprite to do that so what is the alternative?

short hazel
#

They're not refusing they don't know how to do it!

#

For the third time, they're starting out

violet token
#

To set the sprite of the renderer through code without dragging and dropping a preset sprite you would need to grab one from file path

short hazel
#

Nobody said they didn't want to drag-drop?

#

I think you're mixing up referencing the sprite asset, and assigning it to the renderer

#

But anyway

polar acorn
#

It's okay we solved the problem in a thread pretty quick when I didn't have to spend half my time telling you to stop posting disinformation

short hazel
#

[Diversion program ended with code 0]

violet token
polar acorn
violet token
polar acorn
#

If you took the time to learn the actual problem you'd have seen that. This is beginner code, you have to learn to find the question actually being asked when people don't have the words for it yet

violet token
#

All I can say is OP was far more interested in my method but you kept saying no no no and force you perspective, thats cool.

polar acorn
#

Are you ChatGPT

short hazel
#

Anything remotely complex-looking is more interesting compared to the simple stuff. That doesn't mean the complex solution is the best.

#

Yes you can build a whole database with a single Resources.LoadAll<T>() call, but they don't need that

violet token
polar acorn
#

They literally need three sprites. We solved the problem in the thread without you

short hazel
#

Missing the point entirely lol

#

It's appaling because it looks complex

polar acorn
violet token
#

So let me get this straight.. OP posts and didnt accept the method you propose, so I suggest something and OP is interested (in something that maybe complex to you), you yell no you dont need that no no no, and proceed to open a separate thread telling them to ignore me and whatevere and force your way onto them and Im hallucinating??? Lmfaoooo

thorny flame
#

hey i have a rigidbody controller script and everything is fine except momentum, sprinting doesnt work on uneven terrain or anything that isnt completely FLAT, which i think is because it doesnt have any momentum, like running of an edge doesnt do what you think id do, especially using a rigidbody controller.
Im moving with this playerRigid.AddForce(velocityTarget, ForceMode.VelocityChange); and i dont know where to look for the problem

short hazel
#

As it seems like you cannot adapt your answers to the level of the user that needs help

polar acorn
# violet token So let me get this straight.. OP posts and didnt accept the method you propose, ...

No, here's what happened:
They posted a thing they thought might have been the solution because they didn't know what to do and were trying to piece together something
You assumed that meant they absolutely 100% needed to do that exact thing and all other solutions were dumb and stinky
You proceed to derail every attempt at explaining the correct way to do anything, making explaining the actual process impossible
We take it into a thread without you and the problem is solved in five minutes

rare basin
#

I just read the whole context and jezus

#

This guy notlikethis

polar acorn
thorny flame
#

ah i didnt know its a common problem, slopes itself are fine, i slide down at a specific angle, works great, just the issue you described yeah, ill google about it NODDERS

#

thought maybe there is something im doing completely wrong, maybe a different ForceMode since VelocityChange is a bit weird too

polar acorn
#

It involves a lot of math

thorny flame
#

math dead

violet token
#

This how I know you are weird because I didnt force anything on anyone. You were talking to OP for almost 5 minutes before I even said anything, when I did I didnt even mention Resources until OP asked me questions which I gladly answered, seemd like you got butt hurt and started telling me stop no no lol Im done

thorny flame
#

is there anything easier?

verbal dome
#

Get ready for vector math if you are writing your own rigidbody character controller

thorny flame
#

i feel like ProjectOnPlane is a bit overkill

#

its not mine, its an asset and it works well, just having issues with sprinting, i guess the author never tested it lol

verbal dome
thorny flame
#

i am xd

polar acorn
# thorny flame i feel like ProjectOnPlane is a bit overkill

It's not as complicated as it seems. You have a world-space vector that you're using for AddForce already which is half of what you need. You just need to get the normal of the plane you're standing on at any given moment, then you can use ProjectOnPlane with that vector and the stored normal, and pass that vector to AddForce instead of the original one

verbal dome
#

Yeah, nothing overkill about projectonplane

thorny flame
#

oh i actually understand what youre saying WoahDrained been feeling extremely stupid the past few days trying to get things done lmao

#

thanks man, think i can work with that ye

#

been using bing ai to ask for examples and explanations for certain things too, great help in learning concepts etc

polar acorn
whole isle
#

ik what it used for but i wanna know why we need to import this inorder for us to able to make the charchter to move

slender nymph
#

you don't, unless you want to use the PlayerInput component to control your input actions

whole isle
#

i already coded it

#

but im just want to know the purpose of that

slender nymph
#

read the docs

whole isle
#

k ill give it a read

slender nymph
#

there are plenty of ways to get input via the input system. the PlayerInput component is just one of them

whole isle
#

such as wasd

autumn tusk
#

why is this error showing up, i put an animator in the script

slender nymph
#

you probably have another component in the scene where it isn't assigned.

#

or you're reassigning it to null in your code somewhere

whole isle
#

so from my understnading it has 2 components where the player can make actions such as wasd and also player input manager

#

is the stament true?

slender nymph
#

the PlayerInput component is just one of several ways to control your input actions for your objects

autumn tusk
whole isle
#

oh ok so i import player input so the user can control my chharchter alongside some code

slender nymph
#

if you have questions about how the input system works then you should ask in #🖱️┃input-system
and actually read the docs to understand how it works

whole isle
#

can u give me a yes or no cause i did read it but i just wanna clarify that statment

#

then im good

slender nymph
#

the PlayerInput component has nothing at all to do with your character. it's just a component that allows you to easily manage your input action asset and other components can react to input through either subscribing to events on it or by receiving messages sent by it.
and it is just one of several ways you can get your input to your other components. you do not have to use it

tender stag
#

how do i block strafing in the air, like when i jump and i look to the side, the player shouldnt turn in the air

#

do i just calculate the moveDirection when the player is grounded?

rich adder
#

something like that, my dir is WishDir

tender stag
#

if hes not grounded, how can i like not half but make the player turn slower in the air

#

like would i just half the inputs?
moveDirection = orientation.forward * (y / 2) + orientation.right * (x / 2);

rich adder
#

dont u have a speed multiplier ?

#

it would prob work better than axis

tender stag
#

i do

#

and acceleration

#

this is how i move the player

rare basin
#

Anyway why are you moving before calling HandleGroundCheck?

whole isle
tender stag
rich adder
rare basin
#

You handle jumping, sprinting etc THEN you are checking for is grounded

#

Should be the other way around

tender stag
#

it doesnt really make a difference

#

does it?

#

its getting called at the same frame

rich adder
#

order of events can matter

rare basin
#

It does

#

First you move, the you chceck if is grounded

#

Even if it's called at the same frame, the order is wrong

#

And it will move even if it shouldn't for that frame

#

In this case it won't make noticeable difference but still a good practice to do things in a correct way

tender stag
#

wait your on about why i have the if statement with grounded before calling the ground check method?

#

if thats what you mean then i know

#

that code is here for testing

rare basin
#

Good example would be having OnHeal event for example in your even system and a healthbar. Imagine you are updating the healthbar via this event, but you invoke it one line above actually healing

tender stag
#

its gonna be in a different function

rare basin
#

The healthbar wouldn't change then

tender stag
#

yeah i know

rare basin
#

HandleGroundCheck should be called first

#

Then the rest of the methods dependant on is Grounded

tender stag
#

how should i limit strafing in the air then?

rare basin
#

That's not related I just left a side note

#

You can decrease your strafing speed or whatever if you are in air

boreal tangle
#

does someone know why this is Grounded function does not work?

#

when the player is on the ground it should print ground but it never does.

summer stump
boreal tangle
tender stag
#

why is my magnitude not 0 but 2.384186E-06

#

object is still

summer stump
slender nymph
boreal tangle
#

I set the object the player sits on to the same layer

slender nymph
#

and are the objects that should be detected as ground actually on the ground layer?

boreal tangle
slender nymph
#

does it have a collider

boreal tangle
#

yes, a box collider

slender nymph
#

then make sure that your raycast is actually long enough

summer stump
boreal tangle
#

I dont what you mean by your message

summer stump
boreal tangle
#

ok il try 1.16

summer stump
#

The box is 1.16 units tall, you go from the center. You need .56 or so

slender nymph
#

it probably only needs to be like 0.6f since your player appears to be about 1 unit tall

slender nymph
slender nymph
#

still though, just over 0.5f should work

boreal tangle
#

but if the boxcast is the same size as the players collider then why does it have to be so big

small gull
#

how would i disable movement when ground pounding?

slender nymph
slender nymph
boreal tangle
#

oh I thought I did a box cast, Thank you

queen adder
#

Is partial MB classes strict about file naming?

verbal dome
#

Nah, just one file has to be named right

slender nymph
#

depends on your unity version

verbal dome
#

From my experience

slender nymph
#

but yeah, on 2017 you'll for sure need one with the same name as the class

queen adder
#

lemisi

#

oh it's not strict

slender nymph
#

you're able to add a component via the Add Component menu that does not match the file name? 🤔

queen adder
wintry shale
#

Hey, first time here and I am also very new to Unity, I am trying to implement a life system and I am testing it now, this is the code I have but I am not getting anything in the debug log after colliding 3 times

queen adder
#

all partial scripts are not using the name of the class

queen adder
#

can addcomp just fine, ye (with 1 script following the name, and 1 using different name)

eternal falconBOT
slender nymph
# queen adder lemmetry

is that not what you had just tried? because the Add Component menu and dragging the script onto an object are the only places where the file name matters

wintry shale
queen adder
verbal dome
summer stump
verbal dome
slender nymph
queen adder
slender nymph
queen adder
#

but you can add it in editor via script

tender stag
#

what can i improve in this locomotion function

verbal dome
slender nymph
#

it shouldn't break in a build considering the file names just don't exist in a build

queen adder
#

but pretty sure it will do the same problem

wintry shale
verbal dome
#

For the anim parameter names

polar acorn
# tender stag what can i improve in this locomotion function

Combine your calls into one.
Crouching is 1 when isCrouching, and it's 0 in all other cases.

animator.SetFloat("Crouching", isCrouching ? 1 : 0, locomotionSmoothness, Time.deltaTime);

Likewise for walking and sprinting. Walking is only 1 when isCrouching is false and either isSprinting is false or your speed is less than 0.25f.

#

Then you can just replace this entire mamoth if-else chain with three lines, each one checking its own condition

tender stag
#

oh alright

#

thanks

rocky gale
#
foreach (GameObject obj in nonPlaceableObjects)
        {
            obj.GetComponent<MeshRenderer>().sharedMaterial = currPathMaterial;
        }

i have this code. it looks at each gameobject in the array nonPlaceableObjects and sets its material to currPathMaterial. I basically want each object in the scene with a certain tag to use a material. the way im doing it now is that each time i add an object in that i want to be unplaceable i have to add it to the group. this way also just seems not good for performance and inefficient. is there a better and more optimized way to do this?

tender stag
#

so have i missed anything i could have replaced?

wintry shale
teal viper
boreal tangle
#

is it a good idea to set up a state machine for a player controller or is it better to just do it normally with it all in one file.

eternal needle
unreal imp
#

guys how is called the key Fn in the KeyCode?

boreal tangle
#

ok ty

teal viper
#

If that's the property that you want to change, yes.

rocky gale
#

its better for performance?

teal viper
#

The performance impact shouldn't be that big in either case, but it would be cleaner and allow you not to track every single object.

rocky gale
#

i see, thanks

queen adder
#

I am trying to build btw when the error come, works well except when building

north kiln
#

The error shouldn't come up because the entire class is excluded from builds with #if UNITY_EDITOR

#

Concern yourself with the first error before the others

ashen isle
#

hey can someone help me im super new and im trying to create a void method for the player score

#

im basically just making flappy bird so i can teach myself thye basics but im following an old tutorial without TMP so im having to fill in the blanks

slender nymph
eternal falconBOT
ashen isle
#

im using visual studio

slender nymph
#

yes and it needs to be configured to use with unity

ashen isle
#

gotcha brb

#

im downloading the most recent unity version

queen adder
ashen isle
#

ok i configured it, now what do i do

slender nymph
#

do you see errors underlined in the code now?

north kiln
queen adder
#

weird, my UIBehaviour is different

slender nymph
# ashen isle yes

then you should see the error is underlined. remove the () from it

queen adder
#

anyways, yea Ig I can just not override the OnVal on build
Dont need that in build

#

thanks! did just that, sure this will work now (hopefully)

#

I was in the verge of removing it(whole nicer outline) in my game

ashen isle
slender nymph
#

now look at the tutorial you are following again

north kiln
#

Or some poorly decompiled one

queen adder
ashen isle
#

ok it looks exactly like what i did but he used the regular text component

north kiln
queen adder
#

how did you find yours (UIBehaviour)?

#

omg i kept making vague replies

ashen isle
#

i tried .ToString but it showed an error for that too

slender nymph
# ashen isle

and do you not see how your line is different from line 15 there?

ashen isle
#

shows an error for that too

queen adder
#

read the whole line...

slender nymph
#

because it still isn't the same

rich adder
ashen isle
#

ok i don't even care that i just loo0ked like an idiot thank you guys

#

before i configured it i did it but put TMPro instead of .text

queen adder
#

anyway, the most important thing is you not rely on copying, try to understand why you had the error

slender bridge
#

is that from a tutorial or something because that addScore camelCase function is hideous, this aint javascript...

ashen isle
#

oh i know, i did try to figure it out before and i really do try to avoid copying and so far have figured most of it out on my own. I just use the tutorial as a guide in case something isn't workiong. I really do wanna learn how to do iot on my own

queen adder
#

public void a UnityChanOops

north kiln
queen adder
#

u is have access to unity source? O_O

north kiln
#

well, even when it wasn't a package, you can still get the C# source with the csreference.

dawn rampart
#

when i rotate in the code it doesnt rotate nicely how could i fix this?

queen adder
#

oh i just remembered that exist

rich adder
dawn rampart
#

it looks like it snaps in the pics you can see its like on the whole other side

north kiln
#

Fix the pivot point of the sprite so it's centered where you want to rotate

queen adder
#

does this means I cant see preproc directives in all of my F12 on unity thingies?

tender stag
#

how can i add the same amount of force no matter what the mass is

queen adder
#

omg, ig I am/will missing a lot if i dont rely myself on csreference

rich adder
#

.velocity also ignores mass

tender stag
#

and my player suddenly walks faster i dont know why

slender nymph
tender stag
#

nevermind crouch speed was set to 10

#

my bad

queen adder
#

Finally tested... @slender nymph @verbal dome it does build fine with weirdly named partial classes (and ig even on non partials), as long as you can add scripts without editor

slender nymph
#

yep, like i said the file name matching the class name requirement is only for adding the component in the editor via the Add Component menu or dragging the file onto a gameobject

queen adder
#

where is UIBehaviour btw?

#

@north kiln

#

what is the name of the file you were looking at

north kiln
#

It's a package in recent versions of Unity.

queen adder
#

doesnt unitycsref follow that?

north kiln
#

No, it's the core Editor, not packages

queen adder
#

so ig, the only answer is, if I didnt ask here, I wouldnt have been able to solve this prob? 😭

north kiln
#

Well, you would have been able to just intuitively know that OnValidate is not present in a build, because that's what the error was indicating

queen adder
#

I wouldnt have been able to see that preproc dir

queen adder
#

thanks

frigid sequoia
#

Can I detect if an object with just a trigger collision; collides with another object; from the object with just the trigger collider? Or do I have to detect it from the object with the isTrigger dissabled?

north kiln
#

VSCode probably decompiled it because it's not very smart and doesn't know where the file came from, I presume VS would have got it right. Rider definitely knows

north kiln
frigid sequoia
#

Then is probally something wrong on how the colliders are placed in the hirarchy; thx

rich adder
frigid sequoia
#

Is a ball with a rb and a collider; I want a moving ring with different parts which has a collider as the outer ring and a trigger collider as the actual inside of the ring you have to aim at to detect only when the trigger collider collides with the ball

queen adder
#

like cant they just add a #if in these

#

to tell that they actually hid it in the UIBe class

fluid kiln
#

What’s the difference between prefabs and scriptable objects?

rich adder
north kiln
frigid sequoia
# rich adder sounds fine. is it not working or something ?

I have issues when detecting only the trigger collider and not the normal one and also when making the scripts that handle all the stuff that needs to happen to communicate with each other since they are in different parts nested in the ring itself

rich adder
fluid kiln
#

You just save it and manually change data

north kiln
#

I don't think you can instance a gameobject without spawning it into a scene, but you can instance scriptable objects and they just exist in memory.

plucky canyon
#

hello,i am learning with unity

i want to make enemy to follow player, i tried some variations of code from chatgpt(i tried it on another project and it worked just fine) but now i want to recreate it in new proejct and for some reason my enemy jsut start walking into random direction and then fall down

plucky canyon
plucky canyon
rich adder
#

also should not use transform.position to move rigidbody

north kiln
#

Moving a dynamic rigidbody via its transform notlikethis

plucky canyon
plucky canyon
# plucky canyon

this was done with this code

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
public class EnemyMovement : MonoBehaviour 
{ 
    public Transform target;

    public float speed = 5f; 
    void Update() 
    { 
        if (target == null) 

        { 
                     return; 
        } 
      
        Vector3 direction = target.position - transform.position;  
              direction.Normalize();      
        transform.Translate(direction * speed * Time.deltaTime); 
    } 
} 

now i am testing some new ways

rich adder
#

why not just use a Navmesh agent

plucky canyon
#

but for some reason it just doesnt work as it used to work

rich adder
plucky canyon
#

public Transform target;

    public float speed = 5f; 

    void Update() 

    { 
        if (target == null) 

        { 
           
            return; 
        } 

        
        Vector3 direction = target.position - transform.position; 

        

        direction.Normalize(); 

        

        transform.Translate(direction * speed * Time.deltaTime); 
    } 
} 

this worked in my last project,but in this new,it doest work

north kiln
#

!code

eternal falconBOT
plucky canyon
rich adder
#

you should use AddForce if you're gonna use rigidbody

#

or Moveposition if kinematic

#

Obstacle avoidance will still be a pain, I still recommend you just use navmesh agent

north kiln
#

Following ChatGPT's answers is a good way to walk yourself into a corner because it doesn't understand context, and then when you're in that corner it'll just start making shit up

#

Post large scripts as links to external sites to not spam the chat, as it mentioned in the bot

plucky canyon
#

i tried this with the AddForce,didnt work either

rich adder
north kiln
#

You still need to constrain your rigidbody's rotation

#

in the Constraints section of the Rigidbody's inspector

plucky canyon
#

thanks,i will try that

queen adder
#

has there been an answer to whether use GetComp or field to do a single assignment?

#

since after the assignment, the myanim field is useless already

#

meanwhile, getcomp is a runtime cost

queen adder
#

runtimecost vs uselessfield paradox

slender nymph
#

the top one will always be faster. it's just a matter of whether you want to do the lookup or have an extra 8 bytes reserved in memory

wintry quarry
# queen adder runtimecost vs uselessfield paradox

it's not a useless field. With the inspector assignment you can reuse this script even if your hierarchy changes (such as the component moving to a different object) etc.
That's a maintainability win.

queen adder
slender nymph
#

ah yeah, slight design changes is also another consideration where the serialized field is still better

polar acorn
#

It's not useless, it's literally being used right there in your code

#

Single-use is still use

queen adder
#

just once, then useless afterwds

#

oki ig 🥹

polar acorn
queen adder
#

applies to humans ig

#

aight

#

field wins this one, apprently

plucky canyon
#

with some changes in rigidbody

rich adder
plucky canyon
queen adder
#

wait, storing any unity object in a reference field will only consume 8bytes reserved memory?

plucky canyon
slender nymph
#

note that this is the reference itself and not the underlying heap memory that is allocated for the object being referenced

queen adder
#

yep yep, im quite aware of the second one at least 😁

gaunt ice
#

I guess reference actually no taking 8 bytes only since the garbage collector will store the information of it, but pointer with malloc just the same as this, a hidden free list or whatever is used, so meaningless to include the hidden data structure

lone ferry
#

need help with a script that i got off the internet that's acting up and I'm not quite sure why it's doing the thing it's doing

#

ok, so, the script is supposed to
1- turn object X into object Y (works)
2- add a thing to my inventory (works)

#

3- place down the thing in my inventory on the world (works)

#

but it's also removing the replaced object from step 1

#

can I post the formatted code here?

rich adder
#

!code

eternal falconBOT
lone ferry
#

can i use inline for a 70 line code?

#

like, it fits

rich adder
#

ideally use link

lone ferry
#

i can post a video of what's happening too

#

if you wish

rich adder
#

yea'

rich adder
#

oh wait nvm just saw instantiate

rich adder
#

Destroy(objectX);

lone ferry
#

yeah, shoot

#

i think i should transform objectX into objectY instead and not destroy it

rich adder
#

instantiate creates a clone

#

so you're technically cloning it not transforming it

#

don't think you need destroy at all

lone ferry
#

uhum, uhum

rich adder
#

in unity conext Transform is the pos/rot/scale/

lone ferry
#

so i think i should look for a way of replacing it without destroying it?

#

and still, how do i make the objectY not disappear?

rich adder
#

what do you want to replace exactly?

lone ferry
#

oh

#

what

#

i'm confused

rich adder
lone ferry
#

why that's happening

#

i tried removing that specific part of the code but now I can't place down the object I got

rich adder
lone ferry
#

just commented foreach (var item in inventory) { item.transform.position = dropLocation.position; item.SetActive(true); }

rich adder
#

oh wait brainfart

rich adder
lone ferry
#

okay

#

don't remove the thing that destroys the cube, that part

rich adder
#

just Destroy(objectX);

#

remove

lone ferry
#

now the square isn't turning into a circle, but I think there's ways around it

rich adder
#

you should make a tag or something

lone ferry
#

ohhhh right

#

tag the interactables

#

and just replace the objectX with the tag, right?

cerulean kestrel
#

i have a box collider thats a trigger but i want it to make the player be able to go through it. ik it sounds stupid but im genuinly confused💀

rich adder
#

its not solid

lone ferry
#

not sure why you'd do that but I know very little

rich adder
#

they said they want to go through it

lone ferry
#

yeah ik, but like, with is trigger you already go trough it so i was thinking it was a typo

cerulean kestrel
#

im using the gorillarig but it just stands on the box

sour fulcrum
#

Do we have any good resources on AssetBundles?

rich adder
#

you have to remove mesh collider then

cerulean kestrel
#

i removed that

#

but it still just stands on it

rich adder
#

screenshot the scene + hirerchy

teal viper
cerulean kestrel
cerulean kestrel
rich adder
#

then its probably custom collision detection?

teal viper
#

No clue what gtag is.

cerulean kestrel
#

gorilla tag

#

vr game

#

thing

teal viper
#

Right. Not everyone knows about that game. It's not a common knowledge thing.

cerulean kestrel
#

ik

#

just tellin ya

teal viper
cerulean kestrel
teal viper
# cerulean kestrel

There's the box collider. If you want to not have collisions with the box, remove it.

lone ferry
# rich adder you should make a tag or something

sick, but i kinda forgot how to replace that with a tag. What I'm doing is replace the original GameObject objectX with a GameObject.tag but that isn't working and idk how ot change the if statement either

cerulean kestrel
#

but its a trigger

#

i need the trigger

rich adder
#

the controller probably has custom collision detection not ignoring triggers

teal viper
cerulean kestrel
#

blyat

#

oh well

lone ferry
#

sick

#

thanks

queen adder
#

im trying to make projectiles that when spawned go towards the player and for some reason when i press play none of them move and im stumped anyone got any ideas?

wintry quarry
#

The logic in this code makes absolutely no sense to me

queen adder
#

i wanted to see if i could combine the two lol dumb idea ik but i wanted to see all the same

#

sorry lol

wintry quarry
#

If you're spawning projectiles from this cannon, why are you trying to find a reference to a particular projectile in Start()?
Why are you moving that projectile from the cannon script?
How would that possibly move any projectile that this spawns, given the reference is only acquired in Start?

#

Basically - start over. The projectile script should likely be the thing moving the projectile

#

the cannon should spawn it

queen adder
#

sad ok

wintry quarry
#

Think about the logic here

queen adder
#

thanks

wintry quarry
#

you can see this makes no sense right?

queen adder
#

i can lol

#

thanks fpr the help ill start that now

#

shouldnt take long

cerulean kestrel
#

ok i learned a bit and is wondering if i can improve this to make it work. (it wont)

rich adder
#

invalid c#

polar acorn
cerulean kestrel
#

its visual studio

polar acorn
cerulean kestrel
#

listen i was just wondering how i can modify it to make it work with C#

rich adder
gaunt ice
#

learn c# and write c# code

polar acorn
#

You've basically framed your question in the form of pseudocode.

cerulean kestrel
#

damn ok

polar acorn
#

So, you should probably learn how to detect a collision, and how to play an animation, but before all that you need to learn how to make a script at all

#

!learn should be your first stop

eternal falconBOT
#

:teacher: Unity Learn ↗

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

nimble apex
#

can you enable alpha clipping of a material by code?

timber tide
#

sure why not

#

actually it may be required to be recompiled

#

in that case just dont decrease the alpha values (or was it increase? one way or another)

nimble apex
#

i have a poker, that takes in png texture

#

i render it as opaque but the edges are not well fixed

#

so i need to clip the edges out

#

using alpha clipping makes it work perfectly

timber tide
#

why do you need to disable it

nimble apex
#

alpha clipping is not enabled by default, and the team afraid it will clash with something, so we decided do it on runtime

waxen adder
#

So I know that having a public class that extends off of monobehavior makes it editable in the editor.

Is there a way to force that with other class definitions? In my specific case, is it possible to make a lone public static class that isn't extending off of monobehavior editable in the editor?

timber tide
#

you can swap materials too if you want to do that

#

that would work

nimble apex
#

ok

timber tide
#

otherwise just use the alpha slider values

nimble apex
#

i just viewed how it goes

teal viper
#

And is serializable

waxen adder
teal viper
waxen adder
teal viper
#

No. It's an inheriting class.

waxen adder
#

Ah, ok

teal viper
#

But it would be serialized/editable in the inspector if that's what you're asking.

waxen adder
#

Oh, yeah that is what I'm asking XD

teal viper
#

Because it is still a MonoBehaviour.

#

Inheriting class qualifies as any of the base classes in the inheritance chain.

waxen adder
#

Right, because the inherited class inherits monobehaviour

woven crater
#

how do i set material to none without the purple boxx?

#

i just need the trail

steel girder
#

this doesnt look like a programming language at all, this looks like a hyper user friendly library on steroids

wintry quarry
#

magenta means missing or invalid material

woven crater
#

making a "nothing" material?

wintry quarry
woven crater
#

ah thank

nimble apex
#

im now getting into property

you can write

private Material mat{
get{
       GetComponent<renderer>().material;
}
}

instead of getting it on void start right?

wintry quarry
#

aside from the misspelling of renderer yes you can do this - but it will be somewhat inefficient since it will call GetComponent every time

#

You can also write that property more concisely as private Material mat => GetComponent<Renderer>().material;

nimble apex
#

ok ty

#

so we have many scenes that will use the poker, some scene will use URP , while most of the scene will use built in pipeline

the poker is not a poker until we get into the scene that will use it, we will change the material and mesh when we load into the scene, BRP or URP materials will decide here

what i need to do , is to make sure "if material is in URP , enable alpha clipping"

#
  1. check if its URP
  2. enable alpha clipping if URP
#

this is step 1

wintry quarry
#

This is a very vague question. Explain what you're actually trying to do.

#

This is still very vague. what does "grab" mean to you?

small gull
#

what does this mean?

wintry quarry
# small gull

It means you tried to access a null reference on line 28 of your script.

nimble apex
timber tide
#

it means object reference is not set to an instance of an object

summer stump
#

This is gonna be the most common error you run into while learning

nimble apex
#

unity posess 3 types of render pipeline , its related to rendering

#

this is a huge topic

nimble apex
#

get the reference right?

#

you can use Debug.Log();

#

to check if object refer the correct one

wintry quarry
#

As it says, you didn't assign your reference

#

assign it

#

nothing in these screenshots proves you assigned your reference

#

that would be done in the inspector

nimble apex
#

check if u have duplicate objects

#

you might have just assigned one of them

summer stump
wintry quarry
#

no the code has nothing

#

the inspector is where you would assign the reference

#

the code simply has a variable that needs to be assigned

#

called myRigidbody

#

You have another copy of the script where it's not assigned then

#

somewhere in the scene (or in another scene, or in a prefab)

summer stump
small gull
#

i did infact not fix it

#

anything wrong with this?

summer stump
# small gull

Ok, I didn't see how a misplace semicolon could be relevant to the issue 😂

The line numbers are not showing. Which line is the error on?

Also, I see that the file name is "ground pound.cs" and the class name is "groundpound"

Those need to match, and you should never have spaces (or special characters other than maybe underscores) in code file names

small gull
polar acorn
#

Second, what is the error

small gull
polar acorn
#

But before you fix it get rid of your infinite loop

small gull
#

infinite loop?

#

im so confused😐

polar acorn
small gull
summer stump
small gull
polar acorn
polar acorn
small gull
summer stump
small gull
#

oh

#

i thought it was when im not grounded i get downword force onto me and when i am i dont

summer stump
polar acorn
# small gull i thought it kinda did

It runs the code inside the loop until the condition is false. Only one line of code can ever be running at once. Nothing in the loop changes the condition so the loop never ends. Meaning that once it enters that loop it will be adding force until you take your Unity process out back behind the shed and Old Yeller it

hoary karma
#

how can i only show all but one decimal with float? like from showing 1.94739 to only showing 1.9

small gull
#

ok

summer stump
# small gull ok

So just NEVER use a while loop in update until you understand it better.

As for your issue, as digi said, rigidbody is null. You never assigned a rigidbody to the variable

It is private, so you couldn't have done it in the inspector, and you don't do it in the code you showed. So it is not done

#

You can either make it public and drag it in via the inspector, or use GetComponent

hoary karma
#

Error CS1501 No overload for method 'ToString' takes 1 arguments

polar acorn
hoary karma
#

nevermind, solved it with 'reloadTxt.text = string.Format("{0:F1}", delayTimer);'. thanks btw!

slender depot
#

hi, planning on saving some user statistics in my game including total play time, what's the best way to keep track and save it? ive been looking at playerprefs but im not sure how to use onapplicationquit in this case

timber tide
#

json

sour fulcrum
#

I know don’t ask to ask just ask but bit of a weird question, Anyone have experience with AssetBundles and how their assets are saved?

slender depot
# timber tide json

i had a feeling i could use jsons, but how would i handle the onapplicationquit? do i just add it to all my level scripts?

timber tide
#

not too sure about onapplicationquit, may need to some await to the proccess

#

or save and confirm first then -> application quit

slender depot
#

ok that sounds good, is there a way to have like a global function for handling the quit process?

timber tide
#

could try a subscription model. Invoke save on them all, but you'll probably want to get callbacks too is the thing to make sure everyone has serialized the data. If you don't await it should be fine though but larger games that could lock up your program.

slender depot
#

oh man im a little out of my depth there, any tutorials or like keywords i could search for a tutorial?

timber tide
#

maybe some manager where you just collect references of types with an interface of ISave where you'd iterate through all of them and save too is another idea

slender depot
#

what do i search for these?

timber tide
#

Save/Load system unity usually. Lots of ways you can go about it.

slender depot
#

alright, thanks!

sour fulcrum
#

do Is type checks not work on derived types of derived types?

like on microsoft the example is

public class Base { }

public class Derived : Base { }

public static class IsOperatorExample
{
    public static void Main()
    {
        object b = new Base();
        Console.WriteLine(b is Base);  // output: True
        Console.WriteLine(b is Derived);  // output: False

        object d = new Derived();
        Console.WriteLine(d is Base);  // output: True
        Console.WriteLine(d is Derived); // output: True
    }
}

but if i make a something that derives from Derived, will it not find the base anymore?

#

in this script im making i have if (object is MonoBehaviour) but it's not getting true for things that derive from something that derives from monobehaviour

wintry quarry
#

including multiple levels of derivation

sour fulcrum
#

its weird because its not haha

wintry quarry
#

Prove it 😉

#

I bet you're misinterpreting something

sour fulcrum
#

fair

#

keep in mind this code is very rough right no and is more of an editor extensions thing ig but my question was generic enough to post here

minor vault
#

can someone help me with this issue? I don't see any errors when i run the script through visual studio, only in the unity console