#💻┃code-beginner

1 messages · Page 242 of 1

pearl lodge
#

that means its not active so your while loops doesn't execute because it starts off inactive

strange dune
young wren
#

Is that possible to make UI in unity 2d by html / css?

teal viper
warped vale
#

what im i supposed to do in this situation

obtuse axle
#

Hello, I have a question about character jumping and movement, when i jump while running, it doesn't jump as high as when im not running or moving. Is this a frequent mistake in the code?

wintry quarry
wintry quarry
warped vale
#

oh ok thanks

obtuse axle
#

Then how can i keep the same jump height in my code?

#

Is there something to add or to remove?

eternal needle
#

Jump height could be a side effect of the 2 moves

lusty flax
#

I parented my character to a kinematic rigidbody moving platform in order for it to move with it. However, it is not moving with it normally. I change the rigidbody's position by setting its velocity. Does that cause a problem?

eternal needle
eternal needle
obtuse axle
#

Oh i see

lusty flax
eternal needle
#

If it's simple movement it should work fine

young lava
#

If I have a nested Enum called ActionType in my PlayerController class, and I set the variable ActionType actionType using a method called SetActionType. If I wanted to call SetActionType in another script, would I use the line:

playerController.SetActionType(PlayerController.ActionType.Attack);

cosmic dagger
#

The best way to find out is to test it . . .

wintry quarry
warped vale
#

android apk

foggy lion
#

I'm having a issue with prefabs, I'm not sure how to describe my issue so I attached a video (With text) below. Please help me if you can.

ivory bobcat
ivory bobcat
#

If it doesn't have the block instantiator component, you'll not be able to drag it in

#

Also prefabs know nothing of the scene so they cannot reference scene objects

foggy lion
#

Oh

#

Hmmm, that may be the issue?

#

Is there anyway to fill those slots in my code, instead of having to drag the Block Instantiator into them?

ivory bobcat
#

Likely so. Any scene can be active at any given time. The prefab is always available though so having it reference a scene object makes little sense.

#

After you instantiate it during runtime, provide the appropriate references.

#
var instance = Instantiate(...);
instance.instantiator = this;//or whatever applicable```
foggy lion
#

What if I used GetComponent on Awake?

small mantle
#

Why is this sometimes jumping three times the height? ```cs
if (jumpInputLetGo && isGrounded) {
rb.velocity = new Vector2(rb.velocity.x, instantJumpSpeed * multiplier * Time.deltaTime);

    }```
#

It is sometimes a regular low jump (As I Want), but then sometimes it will jump three times that height. For context jumpInputLetGo is GetButtonUp for SpaceBar

feral oar
#

my first guess is that multiplier might be getting altered somewhere

#

hard to say without the full context, though. you should do a copy paste in one of those "blocks of code" websites so we can see the whole script

small mantle
ivory bobcat
ivory bobcat
small mantle
ivory bobcat
foggy lion
#

But I do seem to be referencing an object, the prefabs I think

foggy lion
#

Yeah

#

One sec

wintry quarry
ivory bobcat
#

I'm assuming you've got a static member trying to access a non static member.

foggy lion
#
using Unity.VisualScripting;
using UnityEngine;

public class FallingBlocksScript : MonoBehaviour
{
    public GameObject BlockManagerObject;
    public bool CanMove = true;
    public float BlockFallDelay = 2.0f;
    public float BlockFallDistance = 0.5f; 
    public bool TouchedGround;
    private Coroutine fallingCoroutine;
    BlockInstantiator BI;

    // Start is called before the first frame update
    void Start()
    {
        fallingCoroutine = StartCoroutine(FallRoutine());

    }

    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Ground"))
        {
            CanMove = false;
            Debug.Log("BlockTouchingGround");
            StopCoroutine(fallingCoroutine);
            TouchedGround = true;

        }
    }

    void FixedUpdate()
    {
        if (TouchedGround == true)
        {
            TouchedGround = false;
            BI.SpawnRandomObject();
        }
    }

    IEnumerator FallRoutine()
    {
        while (CanMove)
        {
            yield return new WaitForSeconds(BlockFallDelay);
            transform.Translate(0, -BlockFallDistance, 0, Space.World);
        }
    }

    IEnumerator FrameTime()
    {
        yield return new WaitForSeconds(1.0f);
    }

    private void Awake() 
    {
        BI = GetComponent<BlockInstantiator>();
        CanMove = true;
        TouchedGround = false;
    }
}```

And

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

public class BlockInstantiator : MonoBehaviour
{
    public static GameObject[] myObjects;
    private BlockSpawnerScript BSScript;
    // Start is called before the first frame update
    void Start()
    {
        myObjects = Resources.LoadAll<GameObject>("Prefabs");
    }

    public void SpawnRandomObject() 
    {    
        int whichItem = Random.Range (0, 7);
        GameObject myObj = Instantiate (myObjects [whichItem]) as GameObject;
        myObj.transform.position = transform.position;
        Debug.Log("Spawn Prefab");  
    }
}
wintry quarry
#

what are they

foggy lion
#

Yep, it marks 39 in FallingBlocksScript

raw sun
#

How can I destroy Player when it fell down?
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController1 : MonoBehaviour
{
Vector2 moveInput;
// Start is called before the first frame update
void OnMove(InputValue value)
{
moveInput = value.Get<Vector2>();
Debug.Log(moveInput);
}
Rigidbody2D rig;
[SerializeField] float speed = 10f;
[SerializeField] float Jump = 10f;
BoxCollider2D col;
Animator anim;
void Start()
{
rig = GetComponent<Rigidbody2D>();
col = GetComponent<BoxCollider2D>();
anim = GetComponent<Animator>();
}

// Update is called once per frame
void Update()
{
    Run();
    Flip();
    FallDead();
}
void Run()
{
    rig.velocity = new Vector2(moveInput.x * speed, rig.velocity.y);
}
void Flip()
{
    bool handmove = Mathf.Abs(rig.velocity.x) > Mathf.Epsilon;
    anim.SetBool("IsRunning", handmove);
    if (handmove)
    {
        transform.localScale = new Vector2(Mathf.Sign(rig.velocity.x), transform.localScale.y);
    }
}
void OnJump(InputValue value)
{
    if (value.isPressed && col.IsTouchingLayers(LayerMask.GetMask("Ground")))
    {
        rig.velocity = new Vector2(rig.velocity.x, Jump);
        anim.SetBool("IsJumping", true);
    }
}
void OnCollisionEnter2D(Collision2D collision)
{
   if (collision.collider.CompareTag("Ground"))
    {
        anim.SetBool("IsJumping", false);
    }
}
public void FallDead()
{
    if (col.CompareTag("Player"))
    {
        if (rig.velocity.y >= -100)
        {
            Destroy();
        }
    }
}

}

foggy lion
#

BI.SpawnRandomObject();

eternal falconBOT
wintry quarry
foggy lion
ivory bobcat
foggy lion
#

Like this?

ivory bobcat
wintry quarry
wintry quarry
#

the other error you showed was a compile error

foggy lion
#

Oh

#

Huh wait

#

One second

#

I think

#

Ugggh I think I showed the wrong error right before I changed something

#

Sorry

foggy lion
ivory bobcat
foggy lion
#

Is it a setting I may not have enabled?

summer stump
#

When you click the error in the console window, it will show more information right there, also in the console window

foggy lion
#

Oh oh

#

This thing?

summer stump
#

Yep

foggy lion
#

Note to self, the strange box on the bottom of the errors console is called the stacktrace!

summer stump
#

Interesting that it doesn't show more though

wintry quarry
ivory bobcat
raw sun
#

Alright.

#

Uh when I fix it. It got error like this.

summer stump
#

What is line 70

raw sun
#
Destroy(col.GameObject);
summer stump
raw sun
#

Ah ok

#

Thank you.

foggy lion
#

So @ivory bobcat, do you think you know what my issue is

#

Its saying that line 39 is referencing an object without saying what object its trying to reference.

#

Which doesn't make much sense to me, because I tested the code that actually spawns the prefabs, and it works.

foggy lion
#

So its having some issues referencing the function or the script I guess.

wintry quarry
#

BI.SpawnRandomObject();

foggy lion
#

Yeah

wintry quarry
#

Thje problem is that BI is null

#

that's the only possiblity

foggy lion
#

But is BI not set to BlockInstantiator?

wintry quarry
#

BI is a reference variable. and it's not pointing at anything

foggy lion
#

at like 13

wintry quarry
#

that's just the type of the reference

foggy lion
#

Right...

wintry quarry
#

Do you know what a reference is?

foggy lion
#

I think so

wintry quarry
#

A reference is like a piece of paper with an address on it

summer stump
# foggy lion at like 13

That is a declaration, not an assignment
Declared but annasigned means null

Ah, miscounted. That's why posting longer code should be in links

wintry quarry
#

if the reference is null, it means the paper is blank

#

when it's assigned properly, it has the address of an actual house

#

You are trying to assign it here: BI = GetComponent<BlockInstantiator>();

#

but GetComponent will return null if such a component doesn't exist on the object you're trying to get it from

#

which in this case is the same object this script is attached to

foggy lion
#

Ooooooh

#

I think I get it

wintry quarry
#

Is there a BlockInstantiator on the same object as this script?

foggy lion
wintry quarry
#

if not, you aren't assigning your reference properly

foggy lion
#

and I know how to do that

#

But it won't let me do that on prefabs

wintry quarry
#

Is this the prefab that the block instantiator is spawning?>

foggy lion
#

Yeah

#

Its a mess of code tbh

wintry quarry
#

you're making your life harder with the GmaeObject reference tbh

foggy lion
#

Yeah

#

Im trying to do it in code

#

And thats where we are now, me not understanding how to do that.

summer stump
#

Usually always better to instantiate from a component than a gameobject

wintry quarry
#

But you can do this:

GameObject myObj = Instantiate(myObjects[whichItem]);
if (myObj.TryGetComponent(out FallingBlocksScript fallingBlock)) {
  fallingBlock.BI = this;
}```
#

(after making BI public)

foggy lion
#

AAAAHHHH

#

THAT DID IT

#

THANK YOU SO MUCH DUDE

#

Uh oh

#

Wait

#

Well it did work for a bit

#

Then all of the sudden it spawned in like a thousand prefabs lmao

wintry quarry
#

sounds like an unrelated bug

foggy lion
#

Probably

wintry quarry
#

maybe one of your prefabs has a block spawner on it

foggy lion
#

Indeed it does

#

Im tired lol

#

Well actually

#

None of them have the Block Insantiator script

#

This block spawning has plagued me for days tired

ivory bobcat
foggy lion
#

I don't think its that

#

It looks like an issue with one of my coroutines

ivory bobcat
#

BI is null because the component doesn't exist on this object

#

GetComponent returned null

hot wave
#

is getcomponent bad? and should i start changing it as early as possible, or ok for starting?

foggy lion
#

I think I see the error

ivory bobcat
#

If this object is the instantiated object and the manager has the necessary component, after instantiating it with the manager set the public field to the manager in the manager script

foggy lion
#

And its really dumb (I think)

hot wave
#

If It is null, i put !null in if statement I think, but not sure if ok here UnityChanThink

foggy lion
#
    {
        fallingCoroutine = StartCoroutine(FallRoutine()); //Here

    }

    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Ground"))
        {
            CanMove = false;
            Debug.Log("BlockTouchingGround");
            StopCoroutine(fallingCoroutine);  //Here
            TouchedGround = true;
        }
    }```

Idk why I did this, but I believe I fixed it (changed StopCoroutine(fallingCoroutine); to StopCoroutine(FallRoutine());
ivory bobcat
foggy lion
#

Ahh, unfortunately that was not it...

#

Well actually it partially was

#

Im no longer getting errors

#

Its just spawning thousands of prefabs now

#

So much better...

#

As soon as one block collides with another, it all goes haywire, but when they just touch the ground, its all fine...

#

Uh oh

#

It won't let me back into my Unity window

#

I hope I didn't lose a lot of progress

#

I think i know what to do to stop a million blocks from spawning

cobalt creek
#
for(int x = 0; x < size; x++)
        {
            for(int y = 0; y < size; y++)
            {
                GameObject gu = GameObject.Instantiate(
                    gridUnit
                    ,new Vector3(x/1.5f, y/1.5f, 0)
                    ,Quaternion.identity
                    ,GameObject.Find("Lobby").transform);
            }
        }

so this script i create quickly for testing and the result is in attachment. Basically it create a grid of squares in x and y and I want to make the 100x100 squares contact perfectly without overlap

but when i dont divide by 1.5, I get the spacing in the grid. Why is that?

acoustic sun
#

I am getting an error saying: The variable audioSource of SoundManager has not been assigned.
You probably need to assign the audioSource variable of the SoundManager script in the inspector.
SoundManager.Start () (at Assets/SoundEffectsCoin.cs:11).

#

I am trying to add a sound effect on an object, but when I play the game, it is not there

hot wave
calm coral
acoustic sun
#

I added the sound effect on Audio Clip and also created a script with it. I guess it is a script issue

calm coral
cobalt creek
#

bevause i set size var to 4 and doesnt change during runtiem

hot wave
calm coral
cobalt creek
#

perhap something like using spacingX and spacingY will make that mroe clear for me instead of explicit value

#

more

hot wave
#
int size = 10; // Number of grid units in each dimension

for(int x = 0; x < size; x++)
{
    for(int y = 0; y < size; y++)
    {
        float offsetX = (gridSize / size) * x;
        float offsetY = (gridSize / size) * y;

        GameObject gu = GameObject.Instantiate(
            gridUnit,
            new Vector3(offsetX, offsetY, 0),
            Quaternion.identity,
            GameObject.Find("Lobby").transform
        );
    }
}``` can you try this, ah but not sure if working xD
acoustic sun
cobalt creek
#

thank! maybe also it just a code clarity issue .. that looks like a good way to write it

calm coral
hot wave
acoustic sun
foggy lion
#

Ugghh

calm coral
foggy lion
#

Everything is working, except for the one thing that isn't

#

my brain aches

acoustic sun
calm coral
calm coral
acoustic sun
cobalt creek
#

this probably useful if someone making a word search or something

queen adder
#

        public static void AlphaChange(this SpriteRenderer sr, float alpha)
        {
            var col = sr.color;
            col.a = alpha;
            sr.color = col;
        }```is there better way to do this?
teal viper
queen adder
#

not really just hoping theres a better way :3

hot wave
rich adder
acoustic sun
#

So I was able to assign it to coin, but I am still not getting any sound effects from it

queen adder
acoustic sun
queen adder
#

in the play line

#

change the play cause it just play whatever is in the audiosource (which i think is currently empty)

formal arch
#

im firing off projectiles using a weapon script, it's fired off using an input (mouse 1), im trying to create a turret like assist for the player that will also fire off when they are firing, using the same function that the weapon uses to fire. the function takes a transform parameter so it knows where to spawn the projectiles, the issue im having is only one is ever firing at one time, when I want both of them to fire together, they are currently both running the function off the mouse 1 input

formal arch
teal viper
# formal arch

What's WeaponManager.CurrentWeapon? Where's the code from each screenshot for?
It's very confusing. Please use the !code sharing guidelines and share the whole scripts:

eternal falconBOT
foggy lion
#

Bot

eternal needle
#

<@&502884371011731486>

foggy lion
#

Could anyone help me with this?

eternal needle
# foggy lion

You probably dont want to be using collision messages for this, because of this issue. How are these objects moving? Is it on a grid like tetris

foggy crypt
#

Hello
Can you please help me with RigidBody.AddForce?
For some reason it doesn't move my object whatsoever.
It doesn't give out any script issues - it just doesn't move
transfrom.Rotate work tho

Rigidbody playerRb;
public float verticalInput;

// Start is called before the first frame update
void Start()
{
    playerRb = GetComponent<Rigidbody>();
    gameManager = GameObject.Find("GameManager").GetComponent<CampaignGameManager>();
}

// Update is called once per frame
void Update()
{
    Movement();
}
private void Movement()
{
    verticalInput = Input.GetAxis("Vertical");
    playerRb.AddForce(transform.forward * verticalInput * speed * Time.deltaTime);
    float horizontalInput = Input.GetAxis("Horizontal");
    transform.Rotate(Vector3.up * horizontalInput * rotateSpeed * Time.deltaTime);
}
foggy lion
#

Down 0.5 Units every 2 seconds

keen dew
astral igloo
#

Hi do all components have reference to its gameobject and transform (like when we say this.gameobject or this.transform) or do they call getcomponent<>() behind ?

eternal needle
# foggy lion Yep

youll probably want to introduce some custom collision detection then, although sorry ive never made such a game i cant really suggest much. simplest way would likely just be checking the positions an object is moving to. assuming the grid data is stored in some array

eternal needle
astral igloo
#

cool! thanks

ashen adder
#

using UnityEngine;

namespace GenshinImpactMovementSystem
{
public class Player : MonoBehaviour
{
private PlayerMovementStateMachine movementStateMachine;

    private void Awake()
    {
        movementStateMachine = new PlayerMovementStateMachine();
    }

    private void Start()
    {
        movementStateMachine.ChangeState (movementStateMachine.IdlingState)();
    }

    private void Update()
    {
        movementStateMachine.HandleInput();

        movementStateMachine.Update();
    }

    private void FixedUpdate()
    {
        movementStateMachine.PhysicsUpdate();
    }
}

}

#

Its giving me an error CS1503 any fixes?

gaunt ice
#

dont cross post

keen dew
#

Nobody remembers error codes, show the full error and the line it points to @ashen adder

fair steeple
#

Hey, I have a FSM Manager with a function NextState(); that invokes the method dinamically based of the current state using Reflection. How can I make it so that NextState() Invokes coroutines in other files? Here's the code: https://pastebin.com/UP0w42Wn

eternal needle
fair steeple
#

iirc I got the script from a video which could have been ai

eternal needle
#

ditch the script, this is garbage

gaunt ice
#

you need the instance of other class

#

i dont think reflection can search it for you

eternal needle
#

dear lord i just looked closer at what the reflection is doing, using the enum state name then adding StateStart to it notlikethis

#

use an abstract class for your state, then each child class (the actual states) will override a StateStart method. This way you can call any StateStart method without all this fluff

gaunt ice
#

or use interface, though abstract class is much better

fair steeple
#

Thanks, I'll look into that, I remember trying to do something like that before

#

I barely knew the first thing about programming so I ditched the idea when trying to figure out what abstract meant lol

eternal needle
#

to answer your question also, yes you can start a coroutine on another class. It will be much easier to do when you have the actual instance of the State

fair steeple
#

But I have the state files in a game object and a reference to them, isn't that an isntance?

gaunt ice
#

it is a text file

#

the component on your object is the actual instance

fair steeple
gaunt ice
#

yes

eternal needle
#

the fields you have

public WalkState walkState;
    public CrawlState crawlState;
    public DieState dieState;

are where you would store the actual instance. except the type would just be of the abstract class (or interface) like
State whateverNameHere

gray elk
#

!code

eternal falconBOT
gray elk
#

The space button isn't working as a jump in my code, but the WASD keys are working just fine?
Doesn't seem to be a coding problem from what I can tell so not sure why its not working.


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

public class CharacterControl : MonoBehaviour
{
    public CharacterController controller;
    public float speed = 1f;

    private Vector3 playerVelocity;
    private bool groundedPlayer;
    public float jumpHeight = 1.0f;
    private float gravityValue = -9.81f;


    void Update()
    {
        groundedPlayer = controller.isGrounded;
        if (groundedPlayer && playerVelocity.y < 0)
        {
            playerVelocity.y = 0f;
        }

        Vector3 move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        controller.Move(move * Time.deltaTime * speed);

        if(move !=Vector3.zero)
        {
            controller.gameObject.transform.forward = move;
        }

        // Changes the height position of the player..
        if (Input.GetButtonDown("Jump") && groundedPlayer)
        {
            playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
            Debug.Log("Jumping");
        }

        playerVelocity.y += gravityValue * Time.deltaTime;
        controller.Move(playerVelocity * Time.deltaTime);
    }
}
keen dew
#

Do you get the log message?

gray elk
#

nope
I only get it when i can visually see the jump which is extremely few and far between

#

so hypothetically it works but not all the time, so I'm not quite sure what's preventing it from doing so all the time

keen dew
#

Probably the ground check then. Try removing it from the condition, if it works consistently after that then that's it

gray elk
keen dew
#

That wasn't meant to be a fix, you have to first identify the problem before you can fix it

#

now figure out why the ground check doesn't work and fix that part

#

I don't use the CC but check that you don't have any extra colliders etc

north kiln
# ashen adder

If your IDE is not underlining errors in red you need to configure it. !ide

eternal falconBOT
brazen rivet
#

I'm using some code to get the difficulty of the game using a little formula (infinite mobile game). For some reason, it is returning NaN.
difficulty = ((1/200)*Mathf.Pow(numSpawns - 70, 2.2f)) + 100;
Where numSpawns is how many times the 'enemies' have spawned.

north kiln
ashen adder
teal viper
north kiln
brazen rivet
#

ie it's always defined

#

Is there a quirk with unity where you can't use powers with negative numbers?

keen dew
#

Good for Desmos, but Mathf.Pow expects a positive value there

teal viper
gaunt ice
#

this is math problem, non integer power of negative returns complex number

teal viper
#

You can raise a negative number

#

Unless I misunderstand something

eternal needle
#

Yea issue is with the float

keen dew
#

You can't raise a negative value to a fractional power

teal viper
#

Aah

#

I see. That makes sense.

brazen rivet
#

Ah I didn't know about that

#

Any idea how I could get the same graph without sitting around playing with desmos for another hour

teal viper
#

A fraction is kinda like getting a root, and you can't get a root of a negative number.

#

I think

brazen rivet
#

Yep that's right

teal viper
#

Is it critical to be able to evaluate x < 70?

brazen rivet
#

I think I could just play with desmos for a bit and find a similar looking equation

eternal needle
brazen rivet
#

I'll play around to find something similar

eternal needle
#

just replace the 2.2 with 3 then and mess around with the 1/200 then

brazen rivet
#

Yep

eternal needle
#

although it will get drastically different if you are using large numbers

brazen rivet
#

In the near impossible case someone gets that far

#

I'll just let it be linear at some point

teal viper
brazen rivet
#

Never thought about that, I've never used an animated curve

#

Wouldn't that just be related to time, not how far the player has gotten?

eternal needle
#

do the animation curves let you extrapolate? i assumed you could only use it for a curve that you define values for and not an infinitely reaching curve

brazen rivet
#

I'll just stick to hardcoded math

#

Far easier for my small brain

#

And it's a very small game so it won't be something that bothers me later down the line

#

Even if it does, wouldn't be hard to switch systems

teal viper
vast sparrow
#

I never codded in c# or any other language should I start with a less complicated language?

languid spire
eternal needle
icy panther
#

Yo guys, how do i get the range of two numbers in unity?

icy panther
#

for example: 200 - 50 = 150
150 is the range between the numbers 200 and 50.

eternal needle
languid spire
#

int x = a - b;

tall delta
stuck jay
#

You just answered your own question

icy panther
#

because theres an issue

stuck jay
#

Post the code then

icy panther
#

the code wont check if the number is like say 200 - 300

#

it will return a negative

#

which is not what i want

eternal needle
#

get the absolute value of the number then (google how)

languid spire
#

then you want Math.Abs

tall delta
#

Mathf.Abs(x - y)?

stuck jay
#

Or use one of the many methods that already do that

icy panther
stuck jay
#

Or you can just be lazy and convert the negative number to a positive one

icy panther
#

or will it be an incorrect distance?

languid spire
karmic flicker
icy panther
#

alr thanks guys

#

yep it worked 🙂

karmic flicker
#

oh thank you!

teal viper
#

I hope you're not gonna sample it every frame😬

karmic flicker
ripe shard
karmic flicker
#

billboard ones

ripe shard
#

so gameobjects?

karmic flicker
ripe shard
#

wdym by "kind of"?

karmic flicker
#

idk if Its gameObject caues I am not using Instantiate(); I am using Graphics.RenderMeshInstanced();

ripe shard
#

so its not gameobjects

karmic flicker
#

yes

ripe shard
#

anyway, by this method there is no shortcut, so everything is said... had it been particles you could have referenced the terrain data and have it sampled via vfx graph.

karmic flicker
#

One more question is there a way I can get the Terrain Layer / Texture at a point in the terrain to remove the grass from the sand part ?

thin hollow
#

how do i do a .getComponent to get an image
like i want to get that Image comonent

languid spire
ripe shard
pearl lodge
#

Is there a way to change the color or alpha of a 'Tile'?
public Tile tile;

pearl lodge
languid spire
# thin hollow i have a reference

then it's simply

Image image = refToGo.GetComponent<Image<>();

like any other GetComponent.
just make sure you have the correct using statement for the Image class

thin hollow
#

ok

#

thx

earnest basalt
#

is there a way to highlight specificmesh rendererer but without creating instanced materials (without highlighting meshes that use the same shared material)? maybe with resource blocks.. the reason i dont want instanced mats is because i usually keep forgetting to replace them with sharedmats when im done highlighting but maybe ill just need to do that

verbal dome
#

I mean change to a completely different material while highlighted

silver phoenix
#

using System;
using UnityEngine;

[Serializable]
public class flashlight : MonoBehaviour
{
public GameObject flashlights;

public AudioClip switchsound;

public Light myLight;

public flashlight()
{
    myLight = (Light)flashlight.GetComponent("Light");
}

public virtual void Update()
{
    if (Input.GetKeyDown("f"))
    {
        myLight.enabled = !myLight.enabled;
        GetComponent<AudioSource>().PlayOneShot(switchsound);
    }
    if (Input.GetMouseButtonDown(1))
    {
        myLight.enabled = !myLight.enabled;
        GetComponent<AudioSource>().PlayOneShot(switchsound);
    }
}

public virtual void Main()
{
}

}

languid spire
queen adder
#

anyone made a grid checkbox system before? Like ruletiles, but probably larger

#

for tilebased movement something

#

like this

#

in inspector, is it hard?

waxen cypress
#

probs just a simple answer but im making like a vinyl player and its as simple as making an event for each like "disc" that activates music when played ye?

verbal dome
#

You could just draw a bunch of buttons tbh

#

Or toggles with button style

queen adder
#

it's for movement of pieces thingy

verbal dome
queen adder
#

uh so i cant use it?

verbal dome
#

If you need to save the SO in a built game, then no

#

What exactly do you need to save?

teal viper
#

You can create new SOs, and serialize them in json or something

#

New instances

queen adder
#

i mean i just need to tell that my archers can attack in the square 2 box away from center

#

then lancers can attack in a + shape

verbal dome
#

Ok but does that change during gameplay?

teal viper
#

But those included in the build are immutable (or rather, not gonna persist through the sessions)

queen adder
#

while being able to just check check thingies if they needed

#

like in ruletiles

queen adder
verbal dome
#

You mentioned saving so I thought you wanna change the SO while playing

verbal dome
#

And yeah can make instances of SO too if needed

queen adder
#

uh the quesation main is: is it hard to make 5x5 of this

#

but just true or false

verbal dome
#

5 rows of 5 toggles

low flint
#

hey guys where do i go to for help with scripting camera movements? i dont want to be in the wrong place

verbal dome
#

Can use the string "Button" as the guistyle parameter in Toggle

queen adder
#

thanks imma look for them

languid spire
eternal falconBOT
verbal dome
#

So it looks like a button and not a radio button

low flint
#

ok so i have never used unity before and for an assessment i have to make a rollaball type game. i want to make the camera follow the player (a ball) but when i find a script online and use it, it doesn't work as i need it to work. i tried using ai to fix it up but it doesn't do it properly. been trying for the last two hours but couldn't figure anything out so i came here. i also installed something called Cinamachine and tried to use that but couldn't figure out how to do it properly.
my code https://hastebin.com/share/qerivofice.csharp

languid spire
eternal falconBOT
#

:teacher: Unity Learn ↗

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

teal viper
low flint
teal viper
low flint
#

nope

teal viper
#

That sounds very fishy. I'd complain to the school administration for giving unreasonable assignments

low flint
#

they wont do anything

teal viper
#

That being said, I'm afraid we can't give you a complete solution. You'll need to learn and come back with specific questions, details on the issue and explanation of debugging attempts. Check #854851968446365696 for more on how to ask a question more effectively.

low flint
#

so what if i say i have a problem with my script. i wrote a script to follow the movement of a ball that rolls around but for some reason it wont follow properly. I have tried searching online for other people doing the same im doing but cant find it. here is my script https://hastebin.com/share/qerivofice.csharp
any thing i can do to fix this issue?

#

are their any other servers that help with unity stuff?

languid spire
low flint
#

i can kinda understand it

#

first getting services then defining what stuff is then the main stuff

teal viper
low flint
#

yeah the target is Player1 height offest 3 and follow smoothness 0.1

#

what should the lerp be?

#

wait

#

dont tell me

#

i'll figure it out myself

teal viper
#

Check the docs for how to properly use lerp.

languid spire
#

Realistically, forget it, aint gonna work

crimson ibex
#

is there a cleaner way to do this ?

Vector3 moveDistanceV3 = new Vector3(
                raycastHit.point.x - player.transform.position.x, 
                0,
                raycastHit.point.z - player.transform.position.z
                );
languid spire
#

because Unity does not support Python code

keen dew
languid spire
#

pretty sure there are websites that can do basic Python -> C# translation

visual hedge
#

Hello there. How badly do Coroutines/IENumerators suck compared to async and how badly should I be willing to learn how to use async?

languid spire
visual hedge
languid spire
#

no, not at all, they are two completely different concepts

visual hedge
#

got you, thanks a bunch!

twilit pilot
# visual hedge ohh... okaay. So async isn't like better better coroutine, right? I mean... coro...

better has some subjectivity but they share a lot of similarities, the concepts are closely related, and the implementation is closely related. In Unity they are both typically used to solve the problem of time splicing & concurrency, though tasks with async/await are much more powerful (but come with some extra complexities because of that)

In Unity you can get away with never understanding it and just fiddling with coroutines, in the "real world" outside of Unity it's a fundamental concept of C# and other languages, so I'd definitely recommend learning it

kind lark
#

Hi together. I tried something with the unity job system and have some questions. What is the correct channel for that? general or advanced or beginner? (i think it is more of a beginner question but related to the job system)

obtuse axle
#

Hello, i have a question about the camera and body movement, when i move the camera, the entire body moves to face where the camera is looking. Is there a way to move the camera without moving the body?

languid spire
obtuse axle
#

That's basically it

languid spire
# obtuse axle That's basically it

So there is nothing in your code that directly references your Camera object. All I see is Controller.Move which, I presume, is a CharacterController attached to your player which will, of course, affect all children objects of that Player

obtuse axle
#

Oh i see so i have to either move the camera out of the player or put something in the script that manages the camera

languid spire
#

exactly, think about it, if you are sitting in a car and the car moves, do you move as well?

obtuse axle
#

Ooh yeah i see

cosmic dagger
#

Loop through the array, check each element's y-axis, and assign the target variable to the current element if its value is less than the current target's y-value. The one assigned at the end of the loop will have the lowest y value . . .

obtuse axle
#

Btw do you think using a RigidBody is better or a Character Controller?

#

In general

languid spire
#

In this case, there is no such thing as better or worse, it all depends on what best fits the mechanics you want to implement

cosmic dagger
#

There is no general answer, as it depends on the type of game and movement you want. One can make the same game with both types of controllers . . .

obtuse axle
#

Then is RigidBody harder to implement?

#

I tried using RigidBody on Godot once, i got traumatised

languid spire
#

you miss the point, you would not implement Pong without Rigidbody and also you would not implement Tetris using rigidbody

cosmic dagger
#

I have no idea the difference between Godot Rigidbody and Unity's version. I'd test movement with both controllers and decide which one feels/fits your gameplay better . . .

wind raptor
#

Question about when to use events/delegates vs references/polling. Object A changes its color based on Object B's state. Currently, A has a reference to B, and it checks B's state in Update and sets its color accordingly. Is there a point at which I should be concerned about this, performance-wise?

#

Or is it more of a best practices thing, where it's better to decouple things and use delegates for cleanliness?

frosty hound
#

It probably won't be a noticeable performance thing unless you're doing this across thousands of objects. It's more of a cleanliness thing yeah. If you suspect that the colour changes rarely, or based on something that isn't Update frequent, then you can just subscribe to an event on that object.

wintry quarry
#

But I would still use an event instead of Update for this

#

Object A will still reference B, in order to subscribe to the event

#

B will fire the event, without an explicit reference to A

#

So nothing changes about the dependency graph

frosty hound
#

(Unless you make it a static event that passes itself but that really depends on your setup)

wind raptor
frosty hound
#

It's probably not what you need, anyway. Keep with what you're doing

opaque rapids
#

imported Book of The Dead in a blank HDRP project and here's an error i got

languid spire
opaque rapids
languid spire
#

so, show what they are, they were probably made for a different version of Unity and may no longer work

languid spire
opaque rapids
languid spire
#

the 2 lines of code that are throwing the errors

wind raptor
#

Double click the error message to go right to the problem code

opaque rapids
#

am literally a beginner and i have no idea where and how those are

opaque rapids
languid spire
opaque rapids
#

do you want me to paste the codes in here?

languid spire
#

I want you to show me exactly those 2 lines of code mentioned in the error messages

opaque rapids
#

ok, lemme try finding them

languid spire
#

this is the code file, the line number is 19. Do you understand this?

opaque rapids
#

yes

sterile loom
#

stupid question but is there anyway I can keep a frame by frame animation, but change character armor/helmet/boots/gauntlet?

something like a composite sprite where I only use the "naked" character and put layers of clothing on top of the animation through code?

frosty hound
#

Yes, just animate the sprites individually and change the sprite on the SpriteRenderer. As long as the animation is only moving things, you can put whatever sprite you want at runtime on the component.

sterile loom
#

mind if I message you directly? completely new to unity and im trying to understand this more

frosty hound
#

Or, if you want to animate only a nude character, you can use code to snap a separate sprite object to it.

#

I don't do DMs, sorry

sterile loom
#

all good i guess ill just ask here then.

sterile loom
#

so I have to make the objects/sprites as a completely different thing right? i wont merge them to the old nude character sprite like on this vid? https://www.youtube.com/watch?v=tdTfgo9_hd8

in this tutorial we look at how we can grab multiple sprites and combine them into a single one! this is great if you need to export the combined sprite for whatever reason. just a tiny tutorial that might be useful to some! :)

Socials!

🐦: https://twitter.com/PhillTalksAbout
📸: https://www.instagram.com/lucernaframeworks/
🏠: https://phillse...

▶ Play video
#

basically what I have in mind, is banner saga's smooth 2d animation but I can change the character's clothing

frosty hound
#

The way you could organize it is have a character made up of multiple child object containers (head, body, arm_left) and animate those containers.

As a child of those container is the actual body sprite (nude) so that it follows.

As another child of those containers, and on a sprite rendering order higher than the body part is the clothing piece (so it appears on top).

queen adder
#

That's exactly what I do for my RPG^^^

frosty hound
#
MyCharacter (root object you actually move around with code)
  > Sprite (contains animator)
    > Head Container
       > Head Sprite (nude) | spritegroup: Character, order 0
       > Head Clothing      | spritegroup: Character, order 1
    > Body Container
       > etc.
queen adder
#

It seems like the guy ur watching is over complicating it IMO balforth

#

You just need to make child gameobjects for each customizable part of ur character and change there sprites at runtime.

sterile loom
#

let me try and visualize this from what im getting from you guys

wind raptor
#

Another vague-ish best practices question. If a script will for sure only ever have or need a single instance, is there a good reason not to implement the singleton pattern for it?

frosty hound
#

Nope, use a singleton and make your life easy

#

For example, managers or even the player in a non-multiplayer game are great singleton candidates

#

I also use them on canvases in a root scene. GameplayCanvas, DialogueCanvas, etc.

wind raptor
#

Yeah these are canvas/UI scripts I'm working with here. Mkay, thank you

summer stump
#

Ah, nevermind

sterile loom
#

@queen adder @frosty hound like so?

queen adder
#

Yeah

#

But there On top of each other

wind raptor
#

As a follow-up, any reason not to make all member variables/methods static? So that I can just access a function as MySingletonUIScript.ButtonState as opposed to MySingletonUIScript.Instance.ButtonState

queen adder
#

Or more so on type of the nude body

sterile loom
#

and I can still create separate animations for those individual sprites right? like moving clothing etc

queen adder
#

Yuh^^^

sterile loom
#

how would I determine the clothing layers tho? or will whichever comes first on the code be the one at the top?

queen adder
#

SpriteRender.Layer

#

You can change that via the unity editor inspector. Higher layer means it appears on type of anything with a lower layer number

queen adder
sterile loom
#

ill do a test when i've finished the animation for the idle animation and see if I can swap around the clothing

#

thanks for the help 😄

queen adder
#

I tend to lean more towards static events for my UI or just have my UI listen for everything else

wind raptor
#

Okay, sorta back to my earlier question from before... I recognize that I'm very much in the weeds right now and won't notice any differences between the two implementations, but I'm just wanting to get some best practices in place.

Say object A has an enum state, and a color changes based on the state. The state and color are both members of object A. Is it better to check if the state has changed and then use a switch statement to change the color, or am I fine just skipping the state change check and setting my color in every Update loop (though it will almost never be changed for any given loop)

cosmic dagger
queen adder
#

If objects A's color changes state and the state determines the color... then yeah just a normal switch statement is fine? It doesn't have to be in update? Who's changing object A's state and how?

ashen adder
#

anyone know a fix to this?

wind raptor
#

But yeah I get your point that I can just tie the color change to the state change.

queen adder
#

How the state changes is relevant for sure. If ur just accessing the enum field I would have some sort of get and set that also changes the color when accessing the field

#

I typically have a method just called ChangeState() and when a state changes for a specific class I raise an event or update the rest of the class some how

fiery badger
#

Hi guys, I want to ask what does the "?" in the code do?

queen adder
ashen adder
autumn tusk
#

ok this is kinda weird

queen adder
#

Look at the error it tells you

#

You can also double click it and it will take you to it

autumn tusk
#

why does ontriggerstay only activate while the player is moving

ashen adder
autumn tusk
#

i have a series of weapon pickups, and theyre only detected when collided with

autumn tusk
#

yep

summer stump
#

The rigidbody may be sleeping

#

Be sure to change it to always awake

autumn tusk
#

yep, that fixed it

#

sweet

queen adder
#

The error shouldn't be on line 26 it looks like Line 16 is ur problem

ashen adder
#

What would the problem be?

queen adder
#

Ur passing in the wrong type

ashen adder
#

Sorry Im really new to this what do you mean?

queen adder
#

The method ur calling

#

MovementStateMachine.ChangeState()

#

Doesn't take movementState.IdleState as a argument

#

Also ()(); is invalid syntax

#

!ide

eternal falconBOT
ashen adder
queen adder
#

Show me ur current code please

ashen adder
queen adder
#

It's saying the argument should be of type GenshinImpactMovementSystem.IState

#

Is the PlayerStateMachine supposed to inheret from IState?

ashen adder
#

Yeah

queen adder
#

Could you share the code for that?

ashen adder
queen adder
#

Are you following a tutorial?

summer stump
#

That function expects IState

queen adder
#

Yeah lol

#

That's why I'm asking because you said yes then said no so I'm guessing you rewatchd a video

#

It's supposed to inherit from IState for sure

rocky canyon
vagrant lynx
woven crater
#

i tried to modify the rotation parameter in the shader graph but it doesnt work?

swift crag
#

the name is wrong

#

click on Rotation here

#

then look in...was it the Graph Inspector or the other one?

woven crater
#

Reference name?

swift crag
#

Graph Inspector -> Node Settings

#

Yes, you want "Reference"

woven crater
#

ah i see thank

swift crag
#

so, in your case, it's probably _Rotation

#

The default is to add a leading _ and to replace spaces with _

#

"Total Damage" becomes _Total_Damage

woven crater
#

i see i see

vagrant lynx
#

I saw a guy on YouTube saying that, stop making webs on animators and instead use this, he showed that
animator.Play("")
thing to handle animations
Well, should I use this for 3D games and movements ??

rocky canyon
#

if its a simple state/machine type anim setup i use code

swift crag
#

I think it's a good idea for situations where you unconditionally play an animation

gaunt ledge
#

okay... specialists of unity, I like to organize some of my components in diferent objects, like, a object specific for visuals, and a object specific for sound inside the main object, but many of them are empty, how much does a big amount of empty game objects can affect my game?

swift crag
#

Or for when the conditions for the animation are hard to express in the animator controller's state machine

rich adder
gaunt ledge
#

but if like... we are talking about the fact that I need up to 100 of those things spawning?

queen adder
#

As long as u dont plan for a mobile release it's probably fine

summer stump
gaunt ledge
#

ahhh, okay then

#

thanks

vagrant lynx
queen adder
#

Animator.Play() is fine but you lose transition options and visual scripting which is what Animator is really for. But for a simple game it's fine

vagrant lynx
#

Well, is it good to make movement and animation controllers in one script ?

rich adder
#

I would personally sperate them

cosmic dagger
queen adder
#

I seperate them to

#

It logically doesn't make sense to me

vagrant lynx
#

Okay then

queen adder
#

And makes the classes harder to read and understand IMO

vagrant lynx
#

I'm separating them too

summer stump
gaunt ledge
#

but not individualy

#

but the audio sources would stay, I just don't wanna have all of them in the same object

#

Gets kinda confuzing to find a specific audio

cosmic dagger
proven herald
#

is there a way to prevent rigidbodies from merging child colliders with self?
i have a rigidbody with a collider, and I want a bigger collider to use as a raycast target but also want to use the main collider for physics

rich adder
#

layers

queen adder
#

There's two ways you could do it off the top of my head

#

Layers or Physics.IgnoreCollision()

proven herald
#

Seems like it works by pair?

queen adder
#

Layers then

proven herald
#

They are already on layers, what's the next step?
Not quite sure what that means

cinder crag
queen adder
#

Put them on separate Collision layers

proven herald
#

oh COLLISION layers, hmm

queen adder
#

And inside the Inspector you can tell them what collisions to ignore via the Collider2D component

cinder crag
# cinder crag idk why the goggles and abckpack just acting weird , last time i did this , it w...

https://youtu.be/f473C43s8nE?si=dsqEdurxnVwMR5xQ i was just following this tutorial , i did it before and it was working fine but now they jsut actting weird af

FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial

In this video I'm going to show you how to code full first person rigidbody movement. You can use this character controller as final movement for your game or build things like dashing, wallrunning or sliding on top of it.

If this tutorial has helped you in any way, I would really appreciate...

▶ Play video
cinder crag
queen adder
#

Sounds like a pivot point issue

#

I believe you just need to make separate gameobjects that will hold them in place

spiral narwhal
#

How would I have a game object move towards a target B from a starting position A, following a strict path, instead of moving exactly towards the target like done in Vector3.MoveTowards?

Would I have to implement A* or is there a different solution more adequate?

For more context, this is supposed to be for a tabletop game where the figures move between different nodes on the game board. The curved path is supposed to simulate the natural movement one does when moving figures around in real life.

#

I also thought of beziers, but then I'd have to define each node individually for each pathway, right?

hidden lotus
#

i have a question is 8.5 a float or a double?

#

my instinct tells me its a float since surely it doesnt occupy that much space in memory

#

all i did was convert the float '8' to 8.5 and it generated this error

eternal needle
#

Did you read the error? It's quite clear

hidden lotus
#

how is 8.5 a double tho

spiral narwhal
#

Floats use the f suffix

hidden lotus
timber tide
#

fyi you can do it with the animator

spiral narwhal
#

With the animator?

timber tide
#

yep, can use that to travel on curves

spiral narwhal
#

Oh a manual animation for each path?

timber tide
#

interpolate between nodes, yes

spiral narwhal
#

Sounds like a nightmare to manage in the long run I think

#

For example, if a path changes

hidden lotus
spiral narwhal
#

Not very maintainable

timber tide
#

if it's a defined path, then you need to do it manually somehow

spiral narwhal
keen dew
spiral narwhal
timber tide
#

if you want pathfinding then you do A*

#

as it will find you the shortest path

hidden lotus
eternal needle
#

You didnt save

hidden lotus
#

im acc so stupid

hidden lotus
spiral narwhal
# hidden lotus yep thank you

The same thing is also the case with long values btw.
If you want a long instead of an int, you must use l or L (preferably L because l is easily confused with 1)

Basically, you need to tell C# which value of the same literals you want (15 could be both an integer and a long integer, so there must be some kind of way to differentiate both)

spiral narwhal
hidden lotus
#

oh

spiral narwhal
#

Always wanted to try out Unity's pathfinding package so maybe I'll use this opportunity and give it a shot :D

strong willow
#

I jus started unity im confused when i change the scale of an object it doesnt change a green out line apears this never happend before in my previous attempts in learning unity

hidden lotus
#

i assumed that instead of saying a prefix for float/double, i specify if its a double or float at the begining like in standard C

queen adder
#

It's the same way in C?

spiral narwhal
hidden lotus
queen adder
#

Believe it or not but C# borrows alot from Csadok

zenith cypress
spiral narwhal
#

Like the compiler has a typing stage, where it must assess which type the literal has

zenith cypress
#

It seems f is optional

queen adder
#

The syntax is the exact same

zenith cypress
hidden lotus
#

so c# just forces u to specify

spiral narwhal
#

C# has many of these pre and suffixes. For example, "@" will allow you to name a member after keywords

hidden lotus
#

whereas c doesn't

queen adder
#

As it should

zenith cypress
#

Ah I see, C has an implicit cast from double to float, C# doesn't

wintry quarry
#

That's the only difference^

#

Showing once again that C is very happy to let you do potentially dangerous things without complaint

#

I bet depending on your C compiler flags that may be an error under certain settings

queen adder
#

"It's ur fault ur code crashed bro. It's a skill issue"

pallid nymph
spiral narwhal
#

C is considerably more weakly typed than C# / Java / etc

spiral narwhal
#

The thing is I wanted to prevent having to redo anything if the path changes in later stages of production

timber tide
#

replace java with c#

pallid nymph
spiral narwhal
#

Mmm, I honestly have no idea how that would work and look smooth at the same time

spiral narwhal
pallid nymph
pulsar flame
#

sorry... i looked and saw that first

zenith cypress
#

In that case, ?. does a raw null check, which is why it isn't advised to use it for unity objects (no idea what that function returns so just random trivia)

spiral narwhal
#

I think it's because ?. is not overloaded by Unity

spiral narwhal
pallid nymph
zenith cypress
#

It does a raw null check, you can't overload ?.

spiral narwhal
#

Sounds like using animation sets might even be preferred

#

Thanks for the help ^^

timber tide
#

vs does throw me warnings on using ?. with monos

pallid nymph
#

the animator thing sounds super weird, but am no expert

timber tide
#

but null checking via comparison operator still works

wintry quarry
#

Look it's the little known ?[] operator!

zenith cypress
#

Yeah ? by itself is literally just an if statement (var foo = a ? b : c;)

timber tide
#

though, checking if monos are null isn't that useful if destroyed on the same frame

wintry quarry
#

nobody here has ever used ?[] I guarantee it

fiery badger
#

I see thanks

timber tide
#

usually I'm always using them for events because why not

pallid nymph
#

it's kinda the norm for events (if you mean doing ?.Invoke)

spiral narwhal
#

Rider actively admonishes you for leaving out ?. in events :D

timber tide
#

yeah, I think vs does recommend it too

faint sluice
wintry quarry
#

otherwise yes you are free to use it with any reference you want.

faint sluice
spiral narwhal
#

I'm struggling to find a reason for having singletons that can be null though

faint sluice
#

Only for events and actions

pallid nymph
#

I'm 10% considering adding some extension method that converts fake nulls to true nulls so that I can use ?. moar

faint sluice
zenith cypress
timber tide
#

well, if you don't use ddol then you can have null singletons

#

so it makes sense

spiral narwhal
#

ddol?

timber tide
#

dont destroy on load between scenes

spiral narwhal
#

That abbreviation tho haha

summer stump
spiral narwhal
#

🤷‍♂️

zenith cypress
#

Pulling from elsewhere where I posted about the difference with implicit/operator/?.. Kinda interesting

pallid nymph
stuck jay
rich adder
#

put script where animator is

#

what i do though is make a seperate script just for a Unity Event

#

then listen to it from whatever script I want anim event from

stuck jay
#

How to ignore error messages like "UnassignedReferenceException: The variable damageDealer of Health has not been assigned."?

frosty hound
#

You don't, you fix them

stuck jay
#

There's realistically never going to be a situation where this function is triggered while damageDealer is not set, and even if it does happen nothing would break

queen adder
#

You cant run the game without handling the NRE lol

stuck jay
rich adder
#

You can , doesn't mean you should

frosty hound
#

Then put a null check before you attempting to use it, if you think it's not a problem

stuck jay
frosty hound
#

Wrap it in an if statement

rich adder
#

? will not work on UnityEngine.Object

shell sorrel
#

also seems weird to GetComponent to access a other component, so you can GetComponent again

rich adder
#

def a design issue somewhere

crisp copper
#

what do i need to do so i can sprint?

rich adder
shell sorrel
#

but yeah all UnityEngine.Object stuff you need to use equality operators to check null cant use ?. and ??

stuck jay
crisp copper
shell sorrel
#

!ide

eternal falconBOT
rich adder
crisp copper
shell sorrel
#

it does not look to be considering it is not highlighting types correctly

#

follow the guide the bot above posted

rich adder
crisp copper
#

can i get help how i fix it?

rich adder
crisp copper
rich adder
shell sorrel
rich adder
crisp copper
shell sorrel
#

to follow the guide for it

crisp copper
#

wear is it

stuck jay
# rich adder def a design issue somewhere

Health.cs keeps track of GameObject damageDealer which is the GameObject that damaged this Health.cs component, XPOnDestroy.cs gives the damageDealer GameObject the XP

shell sorrel
stuck jay
#

If you have a better method, feel free to tell me. I'm doing this all from scratch with little guidance, so I probably went past a smart solution without realizing it

crisp copper
#

what will it look like when its done

shell sorrel
#

types will properly be highlighted, autocomplete will work, it will be aware of all code in the project

#

it will mark syntax errors for you, and inform of missing symbols

crisp copper
rich adder
frosty hound
#

@crisp copper In the future, don't crosspost and stick to one channel.

ashen adder
#

Anyone know a fix for this?

shell sorrel
#

stateMachine or player is null on that line

rich adder
ashen adder
rich adder
#

make it not null

crisp copper
#

!ide

eternal falconBOT
ashen adder
crisp copper
#

i cant get in the vs Code

rich adder
crisp copper
#

and the JetBrains Rider Dose not work

rich adder
#

are you just clicking random shit?

static bay
crisp copper
crisp copper
rich adder
#

its not that complex

#

VSCode is not Visual Studio

#

neither is Rider

crisp copper
rich adder
#

Follow the instructions step by step, it has pictures

crisp copper
#

wear is the steps?

rich adder
#

In the link..

crisp copper
#

wich

rich adder
crisp copper
#

1 or te sekund visual studio?

stuck jay
static bay
#

No no no

rich adder
shell sorrel
#

well by policy we do not help people who have not setup the tools properly yet. since why fight with errors that would be caught with proper tools

static bay
#

20% is null reference exceptions popping up from copied tutorial code.

rich adder
#

Ill take NRE any day over unconfigured IDEs

crisp copper
# eternal falcon

@rich adder witsh of the 2 links frome the visual studio is the 1 i need to go in?

rich adder
#

doesn't hurt to just click the one that says manually and re-verify the steps

static bay
shell sorrel
#

some of advanced is people thinking stuff is advanced because its hard to them as well

stuck jay
static bay
timber tide
#

compute buffers pretty general (the docs on the API could be improved though)

crisp copper
rich adder
crisp copper
#

I have re installd evrything and made evryting

#

evrything that the studio link whanted me to do

meager steeple
#

when i would copy my code from visual studio into word, it would usually look like this

#

but now for some reason its like this, and i dont know how to change it back

crisp copper
#

its like me i dont know what i need to do but @rich adder cant help me

wintry quarry
rich adder
strong willow
#

Can someone help w my code

ashen adder
#

How do I fix a null?

rich adder
eternal falconBOT
wintry quarry
strong willow
rich adder
strong willow
#

!code

eternal falconBOT
wintry quarry
meager steeple
ashen adder
shell sorrel
summer stump
rich adder
meager steeple
wintry quarry
#

inspect each thing that could potentially be null. See which one is

summer stump
meager steeple
shell sorrel
ashen adder
wintry quarry
#

Is your IDE configured properly?

ashen adder
#

Yeah it is

summer stump
wintry quarry
strong willow
#

!code

eternal falconBOT
summer stump
strong willow
#

srry

ashen adder
fickle plume
#

@strong willow If you not posting a proper question stop spamming the channel.

wintry quarry
ashen adder
#

Oh that VSC

olive hornet
#

Hey everyone, I'm having a weird issue with the Raycast. Depending on the angle that the ray passes through the box collider the object is not detected. In the first screenshot it is hitting, but if I move it just a bit further it doesn't hit anymore. Is there any limitation for the Raycast that can cause it?

wintry quarry
ashen adder
fickle plume
#

@strong willow If you continue spamming I will mute you

wintry quarry
strong willow
wintry quarry
wintry quarry
summer stump
#

Show the code you have using the process described by the bot

strong willow
shell sorrel
summer stump
shell sorrel
#

like ffs

rich adder
summer stump
#

I just scrolled up, copied the link to the bot message, came back down and posted it for you to make it even easier 🤷‍♂️

olive hornet
fickle plume
#

!warn 616261012714422312 Do not troll on the server. If you don't have anything constructive to say don't spam the channel.

eternal falconBOT
#

dynoSuccess fedleon has been warned.

summer stump
#

If the next thing you do is anything other than sharing code, I think you may be muted or banned

strong willow
#

idk how even with the bot im confused whats a backquote

summer stump
rich adder
#

a tool that actually gives answers!? amazing

strong willow
#

bro shut up

#

u think i didnt search

summer stump
#

Oof. Alright, I'm out

strong willow
#

nvm imma jus help my self

shell sorrel
#

`

rich adder
strong willow
#

stfu

shell sorrel
#

no reason to antagonize

strong willow
#

and yet im the troll

cobalt creek
#

so i have grid of squares where the number is part of the GO name:
012
345
678

So it easy to tell that if i add one, it mean i can reference the next value as long value 0 or 1:
int goRight = index + 1;
However, how do I now what value to get of diagonal or up/down? It not easay to tell that the lower right diagonal is 4, eg

int goRightDown = index + ???

fickle plume
proven herald
#

I have a prefab that has rigidbody, collider & a few scripts attached, plus a health bar as a children
I'd like to use different prefabs for the "model" & collider within it while keeping everything else the same, what would be the better way to do this?

I've been at this for like an hour, there's always something new that breaks

gaunt ice
#

please use 2d array
or row_idx * column_length + column_idx for flatten 1d array

strong willow
rich adder
#

telling you search something you're confused on isn't an insult lol

#

If you don't push yourself you will not learn

strong willow
#

plus im tryna learn

fickle plume
strong willow
#

and ur not helping

shell sorrel
cobalt creek
strong willow
gaunt ice
#

a easy way to go up/down is +column_length or -column_length

cobalt creek
modest dust
rich adder
# strong willow this?

saying by helping yourself pushes the brain to learn is not an insult, thought it was a fair statement. Anyway I digress since Mod wants this convo done.. I shall not reply anymoee , Goodluck with your learning

wintry quarry
proven herald
crisp copper
#

@rich adder am i done now???? or do i need to do enything else?

rich adder
#

now you're coding Properly

wind raptor
#

I have a confirmation "popup window" ui element with a confirm and cancel button. I'd like clicks outside of the window to close the window/be equivalent to pressing the cancel button, and I'd like for other UI elements to not be selectable while the popup window is open. How might I do this without having a giant invisible button over my entire canvas?

modest dust
crisp copper
modest dust
#

Basically separate the visuals and colliders from the root and have them as a child

gaunt ice
#

you have to check

twilit pilot
rich adder
eternal falconBOT
cobalt creek
#

yea, I see now

crisp copper
rich adder
#

oh you mean the bot msg

crisp copper
#

yea

rich adder
#

need to see the script

cobalt creek
#

I guess there is also big benefit to assign row and colum nto each unit because then u can check if a rxc exists, eg if youre at 1x3 and diagonal (right and down) is 2x4 but that is out of bounds and my code should catch that

rich adder
crisp copper
rich adder
#

you send it via link

crisp copper
#

wear?

rich adder
#

in the same place you capture inputs for movement

#

Update

cobalt creek
stuck jay
rich adder
rich adder
summer stump
ashen adder
#

How do I identify a Null and How do I fix It?

rich adder
shell sorrel
#

feel instead ofa XPOnDestroy would just have health invoke a event when it reaches 0, what subs can decide how to handle that

ashen adder
stuck jay
rich adder
stuck jay
#

For anything that isn't an XP giver

rich adder
#

it can only be those few things on line 55

summer stump
rich adder
#

yeah i linked them there

#

they didn't get it either lol

#

Debug.Log(myObject1)
Debug.Log(myObject2)

#

or combine them

stuck jay
summer stump
#

TryGetComponent, if not XP then don't try to give xp

proven herald
summer stump
#

The event could just let the damage giver know the thing died, or just NOT do the event. It can be quite dynamic

stuck jay
#

So it's just another way to give XP instead of XPOnDeath.cs

#

I can't think of many scenarios where this would be better in a heavily-composition-dependent project instead of just slapping an XPOnDeath component, especially since I'm trying to avoid using noun scripts