#💻┃code-beginner

1 messages · Page 700 of 1

crystal rain
#

Learning something

#

That this channel is filled with stuck up people

waxen glacier
#

You really are a lost cause

#

Ah so that's why CSGO doesnt have that issue, it's engine specific right ?

naive pawn
thorn kiln
#
    void Start()
    {
        Invoke("SpawnRandomBall", startDelay);
    }

    // Spawn random ball at random x position at top of play area
    void SpawnRandomBall()
    {
        int spawnIntervel = Random.Range(3, 10);
        // Generate random ball index and random spawn position
        Vector3 spawnPos = new Vector3(Random.Range(spawnLimitXLeft, spawnLimitXRight), spawnPosY, 0);

        // instantiate ball at random spawn location
        int ballIndex = Random.Range(0, ballPrefabs.Length);
        Instantiate(ballPrefabs[ballIndex], spawnPos, ballPrefabs[ballIndex].transform.rotation);
        Invoke("SpawnRandomBall", Random.Range(spawnIntervalMin, spawnIntervalMax));
    }

}```Can someone explain why this works exactly? Why is using Invoke in both Start and SpawnRandomBall what I needed to do to spawn the ball at random intervals?
naive pawn
#

but yes

waxen glacier
crystal rain
naive pawn
rich adder
naive pawn
rich adder
#

cleaner/type-safe to do nameof(SpawnRandomBall)

#

coroutine with a while loop even better

naive pawn
#

also consider a coroutine - would show the existance of the loop much more clearly

#

-# casually stealing nav's advice

thorn kiln
#

Yeah, the tutorial hasn't taught us to do stuff like that yet. I know about loops because I did a beginner JS course, but I always feel like when I'm going through a course, I should only use what they've taught me

rich adder
#

some courses are pretty shit and don't always show you the better / cleaner way

thorn kiln
#

So tell me if I'm right. The Invoke in Start is only actually being triggered once, right? And then it's SpawnRandomBall that's Invoking itself which actually makes it loop. Start is just to get it going the first time?

naive pawn
waxen glacier
#

I guess i'll remake my entire movement with a Character controller instead, I dont want to have to fight the engine physics for every movement

thorn kiln
naive pawn
#

huh, which one?

rich adder
#

strings don't

naive pawn
#

ah

#

i was thinking the typescript meaning of type-safe lmao

rich adder
#

microsoft javascript lol

naive pawn
#

well c# is just microsoft java

rich adder
#

c# gotta love the statically typed , when possible use that to advantage than ugly strings (js 😦 )

naive pawn
#

oh god is that why people show up asking c# questions in the ts server

#

java = javascript, thus microsoft java = microsoft javascript, thus c# = typescript

rich adder
#

microsoft doing shit "their way" love it lol

#

even a shit company can make decent stuff

naive pawn
#

like github, totally

rich adder
#

did they actully create it or bought it out ? forgot

naive pawn
#

bought it out iirc

rich adder
#

ah yea som like that.. i just know m$ copilot being confused with github copilot . the two couldnt be more different (at the time, idk about now)

naive pawn
#

so that's how i realize they're separate products

#

in my defense i never touched either lol

rich adder
#

from what I know, github copilot at least works with your own codebase / context , microsoft copilot is some pretty garbage shit except for the free Image generation

rich adder
rough granite
rich adder
#

Coroutines are nicer because you can pass arguements, stop specific routines etc. @thorn kiln

rough granite
#

when? also is this why there's the git hub ai thing

rich adder
rough granite
thorn kiln
naive pawn
rich adder
thorn kiln
rich adder
naive pawn
#

git cli, github desktop, and ide integrations are interfaces to access git

rough granite
#

i see

lethal reef
#

Hello

naive pawn
eternal falconBOT
terse silo
#

where is a place i can ask about editor scripts?

naive pawn
terse silo
#

ty!

#

did not see that at all XD

soft lotus
#

Thanks it worked! One issue tho, the saved image looks super dark for some reason

#

Insead of this

patent cedar
soft lotus
#

If i were to guess, it's because of gammacorrection/colour format, but im not sure what exactly is it

#

Okay i managed to fix it

#

i changed the colour format of my rnder texture untill it matched

waxen glacier
#

Should I still use FixedUpdate if i'm working with a character controller instead of a rigidbody or do I just use Update and Time.deltatime instead ?

naive pawn
#

CC relies on a Move every frame instead of doing interpolation between frames, so you'll have to change to Update

waxen glacier
rich adder
elfin fulcrum
#

is it worth learning the new input system immediately?

naive pawn
#

up to you tbh

rich adder
#

the sooner the better, but old tutorials still use OLD so its good to know both

#

knowing how to translate old functions into new will help you greatly

naive pawn
#

there's a learning curve to it, so learning it alongside everything else may end up being more of a pain

waxen glacier
#

To add linear damping

rich adder
waxen glacier
dawn apex
#

When upgrading my project to a newer version of Unity, is it recommended to run the API Updater when it pops up, particularly with third-party assets, third-party DLLs?

grand snow
#

meaning you need to update these if they break

dawn apex
grand snow
#

if using source control then do yes

dawn apex
#

Yes, I'm using source control. OK, thank you.

grand snow
#

99% sure dlls wont change so no harm saying yes really

dawn apex
#

Yeah, I'm not just worried about the DLLs, but also the subsequent pop ups for any C# scripts.

grand snow
#

yea it will do the whole project but you will know based on the changes

spiral oak
#

Quick question, do you think it would be useful to use a layered architecture in Unity? Is that uncommon?

vague sequoia
timber tide
#

welcome to the complexities of slopes

ivory bobcat
rough granite
timber tide
#

gravity usually isn't enough. You need some velocity along the slope to help you stay glued to it

lofty mirage
#

Does this thread become code general in a way?

#

Since there is no more chat in code general

#

(also why make threads? isn't that more stack overflow / reddit vibe?)

slender nymph
rough sluice
#

I unable to find out that why Keyboard space is working fine for jump but Jump UI button is not working?:

#

Script codes attached to Player object:

using UnityEngine;
using UnityEngine.InputSystem;

public class MobileControlsFunctioning : MonoBehaviour
{
    private Rigidbody player;
    private PlayerMobileControlsInputs mobileInputs;

    private void Awake()
    {
        //Cursor.lockState = CursorLockMode.Locked;
        //Cursor.visible = false;

        player = GetComponent<Rigidbody>();
        mobileInputs = new PlayerMobileControlsInputs();
        mobileInputs.Player.Enable();
        mobileInputs.Player.Jump.performed += Jump;
    }

    private void Update()
    {
        Vector2 moveInputs = mobileInputs.Player.Move.ReadValue<Vector2>();
        float speed = 5f;
        player.AddForce(new Vector3(moveInputs.x, 0, moveInputs.y) * speed, ForceMode.Force);
    }

    private void OnDisable()
    {
        if (mobileInputs != null)
        {
            mobileInputs.Player.Disable();
        }
    }

    public void Jump(InputAction.CallbackContext context)
    {
        player.AddForce(Vector3.up * 5f, ForceMode.Impulse);
    }
}
final trellis
#

whats up with this error?

#

like whys it gotta be static

rich ice
#
public class test
{
    int a = 1;
    int b = a;
}

this code produces the same error
basically you cant do that.
cant set a field to another field when initializing

sour fulcrum
#

field initialisers can be picky, do you know what constructors are? You might prefer one of those here

final trellis
#

yeagh probably

naive pawn
#

if this were allowed (ie, decl order mattered) then these 2 classes would have different behavior

class A {
  int a = 1;
  int b = a;
}
class B {
  int b = a;
  int a = 1;
}
rough granite
naive pawn
#

they all, semantically, exist at the same time

rough granite
naive pawn
#

yes, there is technically/practically an execution order

edgy tangle
#

It’s pretty standard that in initialization the value passed must be a compile-time constant, right? Because the compiler otherwise can’t know what the actual value should be.

naive pawn
#

but conceptually, members aren't ordered, so language design reflects that

rough granite
#

Fair

#

Was just curious makes sense though

naive pawn
rough granite
#

Oh quick question i was talking to friend that uses java the other day about inheritance, something I've never used cause most class i make are MonoBehaviours so they can't have one so i was curious why c# or unity not sure in this case doesn't let us use multiple inheritances?

naive pawn
#

oh also practically, to have that behavior, you'd have to standardize/define/specify it
so that's more constraints on a compiler/interpreter/runtime, rather than it having the choice of how to arrange stuff

naive pawn
edgy tangle
naive pawn
#

anyways about multiple inheritance - that doesn't really fit the design/structure of OOP

edgy tangle
#

But MULTIPLE inheritance isn’t a thing I think with C# in general

#

Honestly multiple inheritance just sounds like a nightmare anyway

naive pawn
#

it kinda exists in both java and c# in the form of default methods in interfaces, so it isn't exactly a practicality issue, more of a design issue

#

other more dynamic languages like js can use mixins

edgy tangle
#

But you can chain together as many interfaces as you want

#

Which can be super useful

naive pawn
rough granite
#

so many can get quite roudy

naive pawn
#

not sure what you mean by that

edgy tangle
#

Although yeah recently there can be a default definition

rough granite
edgy tangle
#

But the original intent of an interface is for the definition to be abstract and only the declaration is concrete

sour fulcrum
#

I yearn for multi inheritance and i really want the ability for default implementations of interface functions to be virtual

naive pawn
naive pawn
#

i thought the point of interfaces was everything being virtual

naive pawn
#

idk the other languages I use don't have the concept of virtual/override and everything is virtual lol

sour fulcrum
edgy tangle
#

The main usefulness of interfaces is that the definition can vary

#

I.e. I don’t care HOW you give me what I’m requesting, I just care that you give it to me

naive pawn
edgy tangle
#

That gives a lot of flexibility

sour fulcrum
naive pawn
#

i should look into that more

rough granite
sour fulcrum
#

the other wacky thing with default implementations is you can only see them if your directly referencing the object as the interface

naive pawn
#

(default impls as the only impl is also "we have multiple inheritance at home")

sour fulcrum
#

eg.

interface IWeirdThing
{
    public void DebugNumbers() => Debug.Log(1 + 2);
}

class MyMono : MonoBehaviour, IWeirdThing
{
    public void Test()
         DebugNumbers() //Can't do
         (this as IWeirdThing).DebugNumbers() // can do
}
#

but as a compromise you can be cursed and slightly inject it in via extension like

static void Extensions
{
    public void DebugNumbers<T>(this T source) where T : object, IWeirdThing => source.DebugNumbers();
}

class MyMono : MonoBehaviour, IWeirdThing
{
    public void Test()
         DebugNumbers() //Still can't do
         this.DebugNumbers() // can do
}
wide rivet
#

how do I get this kind of dynamic icon-positioning thing where it creates a semicircle under a specific 2D position, then after it reaches the max amount of icons in that specific row, it creates a new row

naive pawn
wide rivet
rough granite
naive pawn
wide rivet
#

the most obvious solution i can think of is hardcoding offsets but thats a pretty boring solution

naive pawn
wide rivet
naive pawn
naive pawn
#

oh wait i misread it

#

that's... kinda a weird solution

#

but yeah i don't think it's particularly relevant

#

try googling about like, displaying status effects to start, just to get the system

#

break this into pieces

brave robin
#

If its in UI, you could make your own layout group. Though that's more of an advanced topic than a beginner one.

naive pawn
#

could probably extend gridlayout and apply an offset

naive pawn
# naive pawn break this into pieces
  • accessing status effects and their icons
  • rendering them
  • splitting it into rows
  • making each row curve
  • positioning the icons according to the curve
topaz hatch
#

Hey all, I'm trying to enable/disable cameras in a list for a scene but for some reason when the trigger happens I get the following message:
MissingReferenceException: The variable [name] doesn't exist anymore. You probably need to reassign it. This doesn't make sense to me as I am not destroying any gameobjects, disabling them, or removing them from the list. Nor am I doing that to the gameobject this list is attached to. Does anyone know why this is happening?

#

Here is my code:
` public void OnTriggerEnter(Collider other)
{
Debug.Log("I have been activated");
if (other.gameObject.tag == "Player")
{
imagePlanes.SetActive(true);
switchCamera = true;
walkForwardScript.cameras[0].enabled = false;
walkForwardScript.cameras[1].enabled = true;

 }

}`

naive pawn
#

and what's [name]

topaz hatch
#

line 38 which is : walkForwardScript.cameras[0].enabled = false;

topaz hatch
brave robin
#

waslkForwardScript's cameras list might be null

topaz hatch
#

It's populated with all three cameras. Does turning off the component make it null?

naive pawn
#

shouldn't, no

#

it's serialized, right?

topaz hatch
#

It's public.

#

One sec

naive pawn
#

that would make it serialized, yeah

#

are you assigning to it anywhere?

topaz hatch
brave robin
#

Also make sure the WalkForwardScript its checking is the same one that's assigned to that object. Maybe you got another in the scene with an empty list and its using that one instead

topaz hatch
#

I'll try, but this is the only scene this script exists in and it's not a prefab.

#

Yeah I'm getting the same thing.

#

maybe I'll just delete this list and make a new one.

topaz hatch
#

I'm going to bonk myself

#

I accidentally added the script referencing the walkscript on a camera that wasn't supposed to have it. uuuuuuuuuuuugh

opaque pendant
#

Excuse me i have a question, I am currently making a 2D Action RPG game using Unity 2022 and originally for desktop windows but I want to make an android mobile version, how to optimize it for 2D games for android mobile ?

teal viper
#

When you know what the bottlenecks are, you can move on to addressing them.

opaque pendant
#

Thank you very much for the info

frosty flower
#

Hello, I'm looking for some help.
I'm following the beginner 3D course on Udemy.

I'm facing an issue for the moment, I've a cube that start moving when I start the game. (without keyboard input).


public class Mover : MonoBehaviour
{

    [SerializeField] float moveSpeed = 0.2f;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float xValue = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
        float yValue = 0f;
        float zValue = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;

        transform.Translate(xValue, yValue, zValue);
    }
}
frosty flower
teal viper
frosty flower
#

Found the issues, my daughter has played with my Sim Racing steering wheel

#

It was not the neutral point anymore

limber flower
#

is it possible to have a slider in the inspector clamp to whole numbers?

naive pawn
limber flower
#

i have no idea

hoary hedge
#

chris is carrying

naive pawn
limber flower
#

its a property of a float in my shader graph

#

and i dont see a way to set a min and max when i change it to integer

naive pawn
#

i believe unity materials only use floats? this is very much not a code thing though

#

if you want better answers, ask in the appropriate place

limber flower
#

ok

sour fulcrum
#

eg. they are used for bools

obsidian parcel
#

so iwas trying to setup ml agents in unity i downloaded the sorce for ml agents and also downloaded the python libraries to that but when i open the project it is giving me errors like sentis not found i tried add from package manager com.unity.sentis but that is not working any idea?

sour fulcrum
waxen glacier
#

I have a problem with my character controller, it totally refuses to touch the ground, whenever I try moving it manually it just teleports up as soon as it makes contact with the ground, which in turn makes it impossible to check for it

Here's the code, and yes it's incomplete because i've just started and want to solve this problem before continuing with the movement : https://paste.ofcode.org/iKkp8kWHUw7mfrEZtQ9pe2

wintry quarry
#

You should not have any extra colliders on your CharacterController

#

The CC itself is a capsule shaped collider

waxen glacier
wintry quarry
#

It's part of the solution

waxen glacier
wintry quarry
#

First remove the capsule, then double check where the CC itself is

wintry quarry
#

The other issue here is just the Character Controller's Skin Width

waxen glacier
#

I removed the collider

wintry quarry
#

The skin width of 0.08 looks like exactly what we're looking at here

waxen glacier
waxen glacier
#

So should I reduce it or increase it to solve the issue ?

wintry quarry
#

What do you think?

#

Try playing around with it and see

waxen glacier
cobalt crown
#

why is OnMouseDown() not working for this object, it has a capsule, this is my code (printed inside of OnMouseDown, nohting printed)

wintry quarry
#

Use IPointerDownHandler (which requires an event system in the scene and a physics Raycaster on your camera)

cobalt crown
#

I see

#

what's a resource I can read or watch to understand all about input/mouse input

#

also, is it reasonable to use an older version of Unity in case it's simpler/easier to deal with it

wintry quarry
#

Understanding all will take months of using them and building familiarity

#

Not really in my opinion.

cobalt crown
#

ok

#

ty

humble ingot
#

can anyone help, when i try to change the sprite of the item thats tagged such it doesnt change, i got a deadline in a few hours

slender nymph
#

use mp4 rather than mkv to embed the video in discord. also make sure to show the relevant !code

eternal falconBOT
humble ingot
slender nymph
#

#1390346878394040320 and don't share videos of code, it makes it much harder for someone trying to help you to actually read it

fast relic
#

hey, i'm wondering, is there a way to create a Joint2D (in this case, SpringJoint2D) component through code, while also adding an attachedRigidbody to it, i have tried using the codeblock attached below, however i can't assign a value to Joint2D.attachedRigidbody, since it's read only, and i'm wondering - is there a way/workaround to do this?

for (int i = 0; i < pointAmount; i++)
{
    GameObject pointA = _points[i];
                
    for (int j = 0; j < pointAmount; j++)
    {
        GameObject pointB = _points[j];
        if (pointA == pointB) continue;

        var joint = pointA.gameObject.AddComponent<SpringJoint2D>();
        joint.attachedRigidbody = pointB.GetComponent<Rigidbody2D>(); // error: Property or indexer 'Joint2D.attachedRigidbody' cannot be assigned to -- it is read only
    }
}
slender nymph
#

You wouldn't assign to the attachedRigidbody property because it gets that automatically. What are you actually trying to accomplish with this assignment?

fast relic
#

oh nevermind

#

turns out i need connectedBody

slender nymph
#

yes, that makes more sense. the attachedRigidbody is the one that is attached to the same gameobject as the joint2d (just like the documentation states)

fast relic
#

i read it like twice and still used the wrong property lol

sonic heart
#

i have no clue what im doing wrong
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

public class #SCRIPTNAME#
{
// A Test behaves as an ordinary method
[Test]
public void #SCRIPTNAME#SimplePasses()
{
// Use the Assert class to test conditions
}

// A UnityTest allows `yield return null;` to skip a frame.
[UnityTest]
public IEnumerator NewTestScriptWithEnumeratorPasses()
{
    // Use the Assert class to test conditions.
    // Use yield to skip a frame.
    yield return null;
}

// A test with the [RequiresPlayMode] tag ensures that the test is always run inside PlayMode.
[UnityTest]
[RequiresPlayMode]
public IEnumerator NewTestScriptInPlayModeWithEnumeratorPasses()
{
    // Use the Assert class to test conditions.
    // Use yield to skip a frame.
    yield return null;
}

}

rich ice
#

!code

eternal falconBOT
sonic heart
#

ok

naive pawn
sonic heart
#

anyways to fix

#

cuz im porting to webhtml

naive pawn
#

how did you get that file anyways

sonic heart
#

assetripper

rich ice
#

well for one, go check !learn . the issue is pretty obvious here unless you purposefully edited the code to look like that
and secondly we dont condone asset ripping here. dont post ripped code

eternal falconBOT
#

:teacher: Unity Learn ↗

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

fair nymph
#

Hello, I need help. I want to destroy this brick with the ball, but Unity is giving me this error message. What can I do?

UnityEngine.GameObject:CompareTag (string)
BouncyBall:OnCollisionEnter2D (UnityEngine.Collision2D) ```

thanks
slender nymph
#

you don't have a tag named "Brick" but you are trying to check to see if an object has that tag. consider checking for the tag the object actually has

cobalt crown
#

what's the best way to export objects and have their textures tightly linked to them all while using fbx?

slender nymph
#

this is a code channel

cobalt crown
#

oh

#

sorry

#

but didn't find anywhere to ask that

keen dew
fair nymph
#

I have tagged brick, but whenever the ball hits the brick or the wall, the error message appears

slender nymph
#

show the tag

#

edit the tag and make sure there isn't any extra whitespace in it. after that, show the line of code that the error is pointing to

ripe galleon
#

does soumeone know what the possible causes could be if i can play normally in unity but when i build the game i cannot use one surtein command?

slender nymph
#

check the player !logs

eternal falconBOT
#
📝 Logs

Documentation

Editor logs

Windows: %LOCALAPPDATA%\Unity\Editor\Editor.log
MacOS: ~/Library/Logs/Unity/Editor.log
Linux: ~/.config/unity3d/Editor.log

Unity Hub

Windows: %UserProfile%\AppData\Roaming\UnityHub\logs
Mac: ~/Library/Application support/UnityHub/logs
Linux: ~/.config/UnityHub/logs

ripe galleon
#

im a begnner btw

crystal rain
#

How do you get past hidden code

naive pawn
#

what do you mean by hidden code

rich ice
#

i dont think hidden code is a technical term

slender nymph
#

so did you check the tag for whitespace characters?

crystal rain
slender nymph
#

now answer the question i asked. did you check the tag for whitespace characters like i instructed?

rich ice
slender nymph
slender nymph
# fair nymph yes

show the tag editor then and ctrl+a the tag to show it does not have whitespace

scarlet skiff
#

bro raycats are confusing me, is this not how you check if the raycast hit nothing?

RaycastHit2D hit = Physics2D.Raycast(node, (node - to), Vector2.Distance(node, to), groundMask);

if (hit.collider == null);

slender nymph
#

sneaky ;

sacred lake
naive pawn
fair nymph
slender nymph
#

so you know where you created the tag? go there. click inside the box with the Brick tag and press ctrl+A to highlight everything in that box. it will then be obvious if there are whitespace characters in it

raw tulip
#

I want to create a multiplayer first person game, what is my biggest chalenge as a beginner?

rough granite
slender nymph
raw tulip
#

Why is multiplayer so daunting? Updating states and making animations consistent between a first person n third person camera?

rough granite
#

i think you should read up on how multiplayer works if thats what your thoughts of it is

raw tulip
rough granite
sacred lake
raw tulip
eager spindle
rough granite
raw tulip
#

Ty guys

sacred lake
#

Multiplayer not only changes the way you implement mechanics like mentioned by people here above but there are also several other layers to it that are now not as important with the plethora of frameworks out there but when implementing networking from the ground up using socket programming, real-time applications are infamously difficult

naive pawn
sacred lake
naive pawn
#

ah, true

sacred lake
#

You also use the keyword operator when defining them

naive pawn
#

but yeah it's specifically to boolean, not sure what you mean by "boolean is arbitrary"

sacred lake
naive pawn
#

this one is not arbitrary

#

the return type is used to define what type it can be cast to

#

trying to use it as an int doesn't mean it's going to get implicitly cast to a boolean first

sacred lake
#

I think you misunderstood what I was trying to say

naive pawn
#

do you think there's like, a single available "implicit operator"

#

you can define conversions, implicit or explicit, for as many types as you want

sacred lake
naive pawn
#

because you're saying "it has an implicit operator" that happens to return boolean? but that's just not the way it's structured, nor is it how it's treated

sacred lake
naive pawn
#

you're not making yourself very clear

#

you don't define implicit operators

#

you define conversions

#

saying RaycastHit defines an implicit conversion operator is... i guess not wrong, but it's just not useful

raw tulip
#

Is using Cinemachine for first person cameras good?

#

I feel like it's kinda lazy n will bite u in the future?

eager spindle
raw tulip
#

Can you access the raw C sharp?

#

My concern is that it looks not as customizable as if I were to do it myself, yfm?

naive pawn
#

you mean the source code?

#

yes it's available, but no you generally won't be modifying the code directly

lusty bramble
#

Ya'll do noob stuff here?

naive pawn
#

you'd be extending it

#

and of course using an existing system will be less flexible than making a whole new thing

naive pawn
eternal falconBOT
lusty bramble
naive pawn
#

no clue what you mean by "sonic related"

#

and, well, we can't exactly give you the info you want if we don't know what you want

lusty bramble
#

3D sonic*

#

I can't really get the object to move

naive pawn
#

not sure where you're seeing gatekeeping, i googled "unity sonic 3d" and got several tutorials lol

#

but i digress. what issues are you having specifically?

#

are you getting errors, is it not moving as intended, is it not moving at all?

lusty bramble
naive pawn
#

yeah ok ditch the chat bots

lusty bramble
#

I installed the input thingy for controller input as well

#

Yeah, thats why I came here

naive pawn
#

input system?

lusty bramble
naive pawn
#

alright so you're kinda leaving out a lot of context right now

#

what method of input are you using? Player Input, InputActionReference, etc?

lusty bramble
#

Well, before I go further. Imma try doing everything again

#

Cause I don't see the script I made anymore

#

sad

naive pawn
#

are you following a tutorial?

lusty bramble
#

I was

naive pawn
#

make sure you're following it accurately - and pay attention to what they're saying in the case of a video, they might mention an issue afterwards

lusty bramble
#

but can't seem to find anything 3D platforming related tho

#

But I might be looking too hard

naive pawn
#

i mean, i did just find several with a few keywords as mentioned before

#

but also - the genre doesn't radically change the movement

#

you don't need to find a platformer-specific tutorial just for movement when it's the same across multiple different genres

#

tutorials usually won't teach you how to make your entire game
they'll teach specific aspects, and it's up to you to combine that knowledge into your vision

lusty bramble
still ingot
#

Hi I am currently trying to make a mini rhythm game system in my project, but how can a UI game object detect when it comes in contact with another UI object. I tried the same a approach with a regular game object using colliders but seems like I don't get anything for the Debug Log?

{
    public Vector2 Velocity;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        while (collision.gameObject.CompareTag("QTE Icon Checker"))
        {
            Debug.Log($"{this.gameObject.name} has made contact with {collision.gameObject.name}");
        }

    }
    // Update is called once per frame
    void Update()
    {
        RectTransform picture = GetComponent<RectTransform>();
        picture.anchoredPosition = new Vector2(picture.anchoredPosition.x - Velocity.x, picture.anchoredPosition.y);
    }
}```
naive pawn
still ingot
rough granite
still ingot
#

maybe saying if its within a range between 2 x points

#

Has anyone ever tried doing collision detection with UI or checking when they overlap?

naive pawn
#

mb

#

that doesn't even make sense what was i thinking 😭

raw tulip
#

Is it a good idea to make my groundcheck a seperate script for general use?

wintry quarry
#

if it's only used for your player, it probably isn't worth it

modest plover
#

Hey. Im Really Early Learner. I Studied Python at school and im going to coding school in 1 and a half weeks. I want to start learning the basics so i dont have to watch every tutorial. I want to learn how to make the player movement myself

twin plank
#

Same

craggy depot
#

Hey yall so I actually want to build something like the autodesk digital twin (check out the demo version) and I wanted to ask if it’s possible and how do I go about it?

#

Am I allowed to send links in here? I’ll share the link if I can

#

If there’s anyone experienced here who can give me a few pointers I’d be very grateful

twin plank
#

!leatn

#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

lusty bramble
#

public class PlayerPhysics : MonoBehaviour
{
    public Rigidbody RB;

    void Update()
    {
        if (Input.GetButtonDown("Jump"))
            Jump();
    }

    //Jump Physics 
    [SerializeField] float gravity;
    [SerializeField] float jumpForce;

    void Jump()
    {
        RB.velocity = Vector3.up * jumpForce;
    }

    //Fixed Update 
    void FixedUpdate()
    {
        Gravity();
    }

    //Gravity Physics
    void Gravity()
    {
        RB.velocity -= Vector3.up * gravity * Time.deltaTime;
    }
}```
timber tide
#

I'm curious to what tutorial you're following

lusty bramble
#

Some random tut I found, that's related to a game I wanna make

rich adder
#

can already tell the tutorial is shite

lusty bramble
#

Man

#

I just want help

grand snow
#

Why is gravity being done in there 😆
rigidbodies already experience gravity and that can be adjusted too

#

plus its not using drag or the mass so its just bad

rich adder
eternal falconBOT
#

:teacher: Unity Learn ↗

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

lusty bramble
#

Don't be mean pls

polar acorn
#

I'm just not sure why a tutorial would have you explicitly computing gravity when that's already done for you

#

You shouldn't have the gravity function at all

lusty bramble
#

Okay-

#

So I wasted my time

#

lmao

polar acorn
#

Probably. That's why !learn was recommended. Most YouTube tutorials are made by people who don't even understand their own code as a quick cash in on a high traffic keyword search

eternal falconBOT
#

:teacher: Unity Learn ↗

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

lusty bramble
#

fair enough

grand snow
#

modifying velocity directly isnt always wise, using AddForce() means we dont fuck up existing forces @lusty bramble
sometimes we do want to modify velocity but it depends on the situation (e.g. you do want a jump to remove existing velocity and push the rigidbody up)

left reef
#

question if i watch the whole 750 hours of free live do i become and pro at this thing named scripting ?

lusty bramble
#

You can make a rocket that crashes into the moon /j

wintry quarry
left reef
#

i would watch like the first 5 people then start doing my thing

#

also i-am pro at playing Rainbow six siege and i only watched 3 people

sour fulcrum
left reef
#

hmmm ye

#

what about and amateur ?

sour fulcrum
#

Making games skills you up the fastest imo, even if they are as tiny and basic as possible

sour fulcrum
#

Being good at programming (again imo) is less about direct knowledge and more about experience in researching, thinking, problem solving, troubleshooting and failing 😄

rocky canyon
#

tell a person a solution, they know what they're doing for a brief period
tell a person how to find a solution, they know what they're doing for an extended period of time 😉

left reef
#

i like how you think

twin plank
left reef
twin plank
left reef
twin plank
#

I'm js finding it hard to choose which method should I use to learn

left reef
left reef
fresh rampart
#

Can you tell me what this is about? there is nothing on the stage and there are still such errors, the unity version is 6.1 (6000.1.10f1)

twin plank
dull grail
#

Why 2nd variable of scriptable object periodically resetting after changing scripts? I don't touch SO script at all but cur amount just resetting from whatever number i set to 0. I don't think that problem in my scripts bc it's happening before i start the game

twin plank
#

how did u learn unity?

dull grail
#

I have 4 string vars and 1 for sprite and problem only with cur amount*

slender nymph
#

do you perhaps have anything in OnValidate that may be modifying it?

slender nymph
# twin plank how did u learn unity?

you've already been directed to where you can learn to use unity in the first channel you started spamming this question in. so take that advice and go start learning instead of spamming that question everywhere

dull grail
#

I don't have any OnValidate methods in any script and there's whole SO script

using UnityEngine;


[CreateAssetMenu(menuName = "SO/InventoryObject")]
public class InventoryObjectSO : ScriptableObject
{
    public Sprite itemSprite;
    public string itemName;
    [TextArea] public string itemDescription;
    public int maxStack;
    public int curAmount;

    public virtual void Use()
    {
        Debug.LogWarning("Base items have no use method");
    }
}
polar acorn
#

If anything modifies the values on the SO asset in the editor, it saves to the SO file, meaning anything else that uses the same asset gets modified in turn

sour fulcrum
#

Just for the reverse kinda info, unless it’s a rare bug Unity won’t be the one doing this

slender nymph
#

or if any code is modifying it at edit time but not also dirtying it that could also make it reset

dull grail
#

I don't think i did something to change it before game start but will check it, thank you

slender nymph
#

if you're certain no code is modifying it then try restarting the editor and see if it continues happening

dull grail
#

Nah, it's probably flawed code bc i've same error few days ago and it's still here

slender nymph
slender nymph
heavy steeple
#

Short question (I think) - for a game like ping pong with touchscreen, what's the approach to making the ball go faster the "harder" you hit it? By indexing where you've started touching the screen and how fast you moved it?

polar acorn
rocky canyon
twin plank
#

alr thanz

rocky canyon
#

figure out what exactly it is u want to do. and go find resources and try it out asap

dull grail
#

Guess i found out reason of reset but can't say for sure until i'll see if error persists or not

rocky canyon
#

more velocity = stronger hit (if u wanna do it taht way) input mode would be irrelevant

heavy steeple
vague sequoia
rocky canyon
rocky canyon
# rocky canyon https://www.youtube.com/watch?v=b7bmNDdYPzU

i used this video to understand the slope issue and solved it by applying a constant downward force

if airbourne my gravity was downwardVelocity += gravityConstant;
if i was on ground or (slope) my gravity was if(downwardVelocity < stickyGravity){downwardVelocity = stickyGravity)

so when im grounded my gravity is = usually around -14 or so.. (helps smooth slope walking)
and when im not grounded (say i fall off the top of the ramp) it zero's out the velocity and starts applying the += gravity

vague sequoia
#

ooo TY

karmic valley
#

Hello I have a question, i am trying to instantiate an object using Instantiate(smallfish, transform);

#

How can I make it so the object spawns higher than the reference

timber tide
#

Whatcha mean by reference? Hierarchy?

karmic valley
#

the thing the script is attached to

wintry quarry
timber tide
wintry quarry
#

simply omit the second parameter and it will spawn at the root of the scene

karmic valley
#

basically i have a fishing rod and I want a fish to spawn a bit lower than it is now

timber tide
#

Sure, but you need to get the reference to it or grab it from the transform

wintry quarry
#

or do you mean the order in the hierarchy window

karmic valley
#

yes

wintry quarry
#

then you can pass in whatever position you want

#

refer to the docs

teal elk
#

My Unity grabbable object's mesh collider is interfering with the rigidbody physics during the drop animation - the collider gets enabled while the object is still transitioning to its drop position, causing collision issues with the player, and the player mesh goes below the ground somehow while the collider stays the same . How can I fix this. ``` private void StartDropAnimation(Vector3 dropPosition, Action OnComplete)
{
Vector3 targetScale = Vector3.zero;
LeanTween.scale(gameObject, targetScale, pickupDuration)
.setEase(pickupEase)
.setOnComplete(() =>
{
transform.SetParent(null, true);
LeanTween.move(gameObject, dropPosition, 0.1f)
.setEase(LeanTweenType.easeOutQuad)
.setOnComplete(() =>
{
rb.isKinematic = false;
rb.useGravity = true;

                    if (meshCollider != null)
                    {
                        meshCollider.enabled = true;
                    }

                    ResetToOriginalState();
                    OnComplete?.Invoke();
                });

            LeanTween.scale(gameObject, originalScale, pickupDuration * 0.3f)
                .setDelay(pickupDuration * 0.1f)
                .setEase(popEase);
        });
}``` If I set the duration to 1.5 in the move tween, I don't face this issue.
karmic valley
#

public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);

#

this one?

wintry quarry
#

yes

timber tide
#

Oh yeah you probably want to add some offset the the position

#

so transform.position + Vector3(0, -1, 0)

#

or if it's 2D

wintry quarry
wintry quarry
# teal elk okay

LeanTween probably has a way to pass in a lambda to run code at the end of the tween

#

I know DOTWeen does

teal elk
karmic valley
#

Instantiate(smallfish, Vector3(0,-1,0), Quaternion(0,0,0,0));

#

will this work

wintry quarry
karmic valley
wintry quarry
#

no

#

Instantiate is a static function

#

it has no idea about anything like that

#

it only knows what you give it

karmic valley
#

how can I get the transform from the spawning object?

wintry quarry
#

transform

#

as you have already been doing

#

if you mean the position, that's transform.position

#

Don't confuse the Transform component itself with things like the position and rotation

karmic valley
#

Instantiate(smallfish, transform.position + Vector3(0,-1,0), Quaternion.identity);

#

Why is there a red line under Vector3

timber tide
#

new it

karmic valley
timber tide
#

new Vector3(0, -1, 0)

karmic valley
#

hm ok

#

Idk what that means

timber tide
#

Good time to learn some c#

teal viper
#

It's calling a construvtor/creating new instance.

karmic valley
#

i remember learning a bit of this in ap comp sci a

#

But i forgot

#

fuck its lowkey just not working anymore

#

😔

timber tide
#

Well, see if you can debug the problem, otherwise feel free to post the script

karmic valley
#

All i did was change Instantiate(smallfish, transform);

#

To Instantiate(smallfish, transform.position + new Vector3(0,-1,0), Quaternion.identity);

#

;-;

teal viper
#

What about it doesn't work..?

karmic valley
#

the fish is not showing up anymroe

teal viper
#

Do you get any errors?

karmic valley
#

no

#

Yeah i just changed the code back to original and it is working

#

So idk

teal viper
#

Then it must be instantiating somewhere. Pause your game after it's instantiated and inspect the scene/hierarchy

karmic valley
#

ok

#

oh wait

#

I found the fish

#

But this is not doing what I intended it to do

#

Now the fish is just spawning at that slightly transformed position and staying there

#

I want the fish to spawn slightly tranformed but continue moving with the hook

teal viper
karmic valley
#

It isn't in the hierarchy right now

teal viper
#

Via code..

karmic valley
#

hm how to

teal viper
karmic valley
#

player.transform.parent = newParent.transform;

#

transform.parent = smallfish.transform;
?

teal viper
teal viper
karmic valley
#

what do i refer to the hook as?

#

The script is attached to the hook btw

#

things need tags to be referred to in code right?

teal viper
#

I also suggest you go over the beginner pathways on Unity ! learn as they cover all of these basics.

#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

teal viper
karmic valley
#

so smallfish.transform.parent = transform;

#

hm that didnt work

teal viper
karmic valley
#

i got this error

#

I think it might be bc of this

slender nymph
#

you need to modify the instantiated object not the prefab

karmic valley
#

ok

slender nymph
#

also ideally you would use the SetParent method rather than assigning to the parent property

karmic valley
slender nymph
#

Instantiate returns the object, store that in a variable for reuse

#

and like dlich said, Instantiate also has an overload that allows you to assign the parent

worldly snow
#

why keep coding when you can ask Copilot ? Unity

slender nymph
#

typically people want their code to work

karmic valley
#

yay it worked

#

🐋

silk vale
#

someone can help me i have been all day trying to place a 3d trree in unity and not mater how matter i try every free i dowload say that there is not a render or there is not prefeb i do not know if it is a bug or what to do. I already downlaod universal render pipe converter and nothing

worldly snow
silk vale
silk vale
karmic valley
#

why am i getting this

#

I thought a double could store a decimal

slender nymph
#

there are beginner c# courses pinned in this channel, perhaps you should start there if you don't know how to declare a float literal

teal viper
karmic valley
#

Anyone know why this is happening

#

So i added a fish to the scene and made it a child of the hook, i transformed it until I got a position i liked

#

and i got these coordinates

#

but when i add this to the code it spawns like insanely far away from where i want it to

bright zodiac
# teal elk My Unity grabbable object's mesh collider is interfering with the rigidbody phys...

dont deep nesting tweens for the purpose to chain them with OnComplete, chain them properly using LTSec api

LTSeq sequence = LeanTween.Sequence();
sequence.append(LT.value()/scale/orWhatever);
sequence.append(LT.move()/scale/orWhatever);
sequence.append(LT.delay()/scale/orWhatever);
squence.start()

much easier to manage, and you can do LT.cancel(obj, true) without messing up the tween continuation

teal viper
karmic valley
#

I think so, thats what the line below is supposed to do

north kiln
#

You're positioning it with a world-space offset

karmic valley
#

Ok thank you

#

bruh my fish is still tweaking mad hard

#

😭

teal viper
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

polar acorn
sour ruin
#

Hi, I have some quaternion that rotates something clockwise when looking down at it from above but the angle axis vector points up. Are quaternion axes opposite to the axis of angular velocity?

teal elk
hard crescent
#

To anyone who just got stuck like I did, especially with mouse not being detected even with a collider to some objects:
Edit -> Properties -> Player -> Active Input Handling -> Both

teal elk
sour fulcrum
#

How can I constrain a generic to just if it implements a given interface? i don't care if its a class or struct etc. but i don't want new() because it has param constructors

teal elk
wintry quarry
#

anyway you can do:

void MyMethod<T>() where T : MyInterface```
karmic valley
#

hello

#

how do i use the quaternion.euler

#

Can i simply just do quaternion.euler(0,0,90f)

wintry quarry
north kiln
karmic valley
#

the thing is i tried this but it did not work

#

Like why does this not work

#

GameObject fish = Instantiate(smallfish, transform.position + new Vector3(0,0,0), quaternion.Euler(0,0,90));

fish.transform.parent = transform;

north kiln
#

because you're not capitalising things correctly? Does your IDE have proper autocomplete and error highlighting?

karmic valley
#

wait is it literally just the q not being capitalized

#

😭

north kiln
#

!ide

eternal falconBOT
karmic valley
#

holy fuck im gonna crash out

#

20 minutes for that and all i had to do was capitalize the q

#

💔

karmic valley
#

And start moving an object around

#

Is that local or world

north kiln
#

What you see in the inspector is always the local position

karmic valley
#

and in code its world?

north kiln
#

the position local to the coordinate system of the parent

#

position is world/global. localPosition is local

karmic valley
#

local or global

north kiln
karmic valley
# north kiln

from my understanding, if I transform the fish in the inspector, im getting local positions. Then i input those local positions into the code that i just sent and it should transform the fish as much as it did in the inspector?

#

I did it

#

and my fish is in the middle of nowhere

#

Wait wouldnt it need to be +=

#

Because rn when i set it to 0,0,0 it just puts it at the 0,0,0 in the game

#

@north kiln brotato chip pls help

#

i tried everything that i think makes sense and its still so off

north kiln
#

Please refrain from continually pinging me into this, and post your updated !code

eternal falconBOT
karmic valley
#

The code is hella cooked

#
    {
        GameObject fish = Instantiate(smallfish, transform.position + new Vector3(0, 0, 0), Quaternion.Euler(0, 0, -90));
        fish.transform.localPosition += new Vector3(0, 0, 0);
        fish.transform.parent = transform;
        //0.425f, -0.013f, 0
    }
#

I think this is the only section u need to look at tho

#

the rotate works but the transform doesnt

north kiln
rich ice
#

+= new Vector3(0, 0, 0);

1 + 0 is still 1.

this line is pointless

north kiln
#

except with the position mentioned in your first screenshot

karmic valley
#

But even when it was it still didnt work

karmic valley
#

Quaternion

north kiln
#
GameObject fish = Instantiate(smallFish, transform);
fish.transform.localPosition = new Vector3(0.425f, -0.013f, 0);
fish.transform.localRotation = Quaternion.Euler(0, 0, -90);
karmic valley
#

yeah idk its not working

north kiln
#

what's it doing then?

karmic valley
#

the rotate works but its not tranforming

north kiln
#

then you are transforming it elsewhere

nova kite
#

Are state machines used only for AI?

rich ice
nova kite
north kiln
#

UI, etc. Anything that has state could use a state machine

nova kite
#

Ouu I see

#

So if I learn state machines I could understand the animation sub state machines? Cuz once I used them it broke many animations lol

#

There are barely any videos on that tho🥲

karmic valley
#

is local rotation cooked

#

ok somehow when i delete the rotation it works now

timber tide
#

state machines are just a way to group your logic so you're not running around with thousands of if statements

karmic valley
#

🙏

nova kite
timber tide
#

you can actually run into similar issues you find with OOP with state machines if you don't group it all correctly

nova kite
#

Damn I’m gonna have to re write everything🤣

#

I’ll see if I can find somewhere to learn about it

#

Does the official Unity tutorial cover it by any chance? I really liked all the lessons I did there

timber tide
#

You'd want a combination of both, states and methods

nova kite
#

How’d you choose what to use for what? Or that comes from experience?

#

Also would that make the code less messy? Because grouping logic sounds like it’d look nicer

rich ice
timber tide
#

I'd look at it as an alternative to just doing if-else statements as for one it's much cleaner that's for sure.

karmic valley
#

Anyone know why my line is behaving like this

#

I have the 1st point set to the tip of the fishing rod and the 3rd point set to the hook

#

But for some reason it is so far away from where i want it

nova kite
#

I see I’ll definitely look into that then because my code is so messy with so many functions and interconnected scripts haha, getting hard to manage🥲

#

Thank you both❤️

rich ice
# karmic valley Anyone know why my line is behaving like this

you still seem pretty new to all this. maybe consider checking !learn or some other courses before jumping right into making your own game. learning each of the components one by one is going to make it a lot easier to spot which is causing the issue.

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich ice
#

but there's also a lot of things that could be causing it and it depends on exactly what you mean by that

#

if you mean why it looks that way then it's the material

#

if you mean the part that's clipped off then it's probably some object in front of it that's blocking it

karmic valley
#

Like i need this thing done in 2-3 days

#

otherwise i would try to actually learn

rich ice
#

i highly doubt you're going to have this done in 2-3 days

karmic valley
#

I just need it to be the best i can

nova kite
#

Yea tbh as a beginner it takes a lot of time, today I implemented 6 animations and player movement logic and it took me 15 hours💀

nova kite
karmic valley
#

Kinda

#

For a class

rich ice
nova kite
#

If you don’t care to understand what the code does then chat ChatGPT and pray I guess😅

rich ice
karmic valley
#

Chat gpt is buns

nova kite
#

Most of the time today of these 15 hours went to learning the whole animator thing because I was scared to touch it before 🤣 but I found a website where you can import animations so that gave me a head start

#

I don’t even wanna think about touching Blender😭

sour fulcrum
#

animation stuff is scary and cursed

nova kite
#

Fr I hate it😭

#

Connecting it with all the arrows was hell so I used the trees and state machines and then it broke

rich ice
nova kite
#

And I spent too much time and wanted to get other issues done so I can make progress lol

karmic valley
#

Like even stuff that doesnt need to have measurements or anything

#

Idk why blender is so complex

nova kite
#

Is that like a 3D design software?

karmic valley
#

cad software

timber tide
#

blender is pretty crazy to jump into

nova kite
#

Ooo imma look that up thank you

rich ice
karmic valley
nova kite
#

Oh god haha, how is it going?

#

I guess if I ever sell a video game I’d just outsource modeling and animation

#

I just wanna code🥲

rich ice
# nova kite Oh god haha, how is it going?

well, it's going a lot better now that im doing simpler models that i actually need. i used to keep trying a bunch of stuff that were way out of scope like animals or big detailed buildings. I'm finding it a lot easier to just do some basic things like furniture, tables, chairs, ect.

rich ice
nova kite
#

That’s amazing! I’d be surprised if I can pull off a stick man🤣

nova kite
sour fulcrum
#

kenneynl's license is so unrestricted you can re-sell it all directly iirc

nova kite
#

Woah

sour fulcrum
#

(dont do that lol)

nova kite
#

🤣🤣

obtuse knoll
#

if unity runs on C# does that also mean that switch are better than if statements if they get too long?

nova kite
#

I can’t sell anything anyway I’m on a student visa🤣🤣

sour fulcrum
eager spindle
nova kite
#

F-1

sour fulcrum
#

but yeah highly recomend kenneynl's and kay lousberg's assets for prototyping

karmic valley
#

confused whats going on here, i pretty much just copied the documentation

nova kite
#

I’ll look into that too thank you! I imported a model and some animations from Mixamo

sour fulcrum
#

mixamo cool too yeah, you can even chuck some of their stuff into mixamo 😄

polar acorn
rich ice
sour fulcrum
#

Some of their stuff is paid though

#

they do free packs + cheap paid bonus versions

#

looks gorgeous though

nova kite
#

Wow that’s insane

polar acorn
sour fulcrum
rich ice
#

oh yeah for sure. i think i remember seeing another game that uses that.
-# i'll try not to drag this on aswell since we're getting a bit off-topic OhNo

polar acorn
#

Jesus only $15 for even the blender files?

What the hell have I been paying Synty for

sour fulcrum
#

50% right now too

polar acorn
#

If this sale is still going on tomorrow I'm gonna go absolutely buck wild on those asset packs those would make for some fantastic prototypes

obtuse knoll
#

pain?

sour fulcrum
#

They also do this weird but cool patreon exclusive thing where they drop characters monthly but also you can just buy a seasonal pack outright. some of them are pretty specific but if it happens to cover a relevant project it seems goated

#

i have this santa's workshop prototype i was cooking for government funding that i really need to go back to now that Kay made these really cute elves

polar acorn
# obtuse knoll what are you paying for?

As a programmer without much in terms of artistic skills, most of my concepts are in the form of graybox pitches and better looking prototypes means better first impression and potentially more funding

sour fulcrum
#

cool peoples

timber tide
#

Kay's got some cool stuff. I heard they made it all using Kenney's asset tool

#

also all their assets use vertex colors, no texturing at all

karmic valley
#

Does the fish instantiation only exist within the ontriggerstay?

#

I wanna delete the fish once its been reeled

modest dust
#

fish is a local variable within OnTriggerStay, make a class field out of it.

gentle bone
#

you make it local here but not in the exit method...

karmic valley
modest dust
#

Same way as with your timeFishing or hasFish, these are class-level

gentle bone
#

in ontriggerstay you create a local variable with GameObject fish =...

#

but this var doesnt exist in thex on exit method down

eternal needle
karmic valley
#

Why does it say missing (game object)

modest dust
#

Make it private instead of public.

#

You don't need it exposed to the inspector

#

You set the value via instantiate in code

karmic valley
#

i can just make it private by not putting public right?

#

Why does time fishing start at 3 when i start the inspector

modest dust
#

Because that's what you must have set it to initially, or it changed if it's during playmode

sour fulcrum
#

changed during playmode would not affect it if they are not in play mode

modest dust
#

Do these fields even need to be public? Besides the 3 prefabs.

karmic valley
#

in my code

#

But if i stop my playmode and start it again, shouldnt it go back to 0?

modest dust
#

Doesn't matter what's the default value in code if you serialize it

sour fulcrum
# karmic valley I have it set to 0

field declarations like that run when the object is originally made, which is when you added that monobehaviour as a component
reasonable confusion

modest dust
#

Make it private if you don't want the serialized value in the inspector affect it

karmic valley
#

wdym serialize it

modest dust
#

public fields are by default serialized, in simple terms exposed to the inspector and editable from there

#

Whatever value is there it will replace the original value when the game starts/object spawns in

karmic valley
#

I just like public variables bc i can see whats happening easier

modest dust
#

To explicitly serialize a field you'd use the attribute [SerializeField]

#

You can also see what's happening if you debug the value or switch the inspector to debug mode.

modest dust
#

What will be?

sour fulcrum
#

if you switch the inspector to debug mode

#

those have to be serialized

modest dust
#

First time I ever hear about that

sour fulcrum
#

nevermind my thing was in a weird state

#

apologies

grand snow
#

Ideally you use a debugger to debug instead of making rando things serializable.
Or use a custom inspector/naughty attributes/editor attributes to show some var

twin plank
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

coral crater
#

is there a go-to way to serialise a Tuple? I just can't seem to get it down. neither of these seem to work

public class PeoplePageManager : MonoBehaviour
{
    [System.Serializable]
    public class peopleBios
    {
        [SerializeField] public (Sprite, Sprite, TextAsset)[] peopleBioss;
        [SerializeField] List<(Sprite, Sprite, TextAsset)> peopleBiosss = new();
    }
}
naive pawn
#

no, just use structs, that way you get names too

frail hawk
#

you can make a custom class with all the fields you need then Serialize this insead. a List<YourClass> would then hold all of these objects

naive pawn
#

something like this would probably be better as a struct that a class though fwiw

coral crater
silk night
#

and make the fields public (or add [SerializeField] to them)

coral crater
silk night
#

and last one, as said above, use a struct instead of a class, as easy as just replacing "class" with "struct"

coral crater
#

I'm assuming when they said "that way you get names too" they meant that when referencing the items in code, you see their names as opposed to just "item 1" or whatever?

naive pawn
#

yeah

silk night
#

but yeah as it doesnt serialize you need the class/struct anyways

coral crater
#

good to know, thanks v much c:

naive pawn
#

yeah but it's not actually part of the tuple, this way you have consistent & forced names

slim tiger
#

heeeeello!

lofty mirage
#

Hi man

slim tiger
#

Complete begginer, no idea why this isn't working. The player sprite should be moving left and eight but isn't responding

#

Been staring at it for ten minute nowatwhatcost

lofty mirage
#

Did you assign the script to your gameObject?

north kiln
#

Is the script assigned to the object with the variables assigned, and are there no errors in the console?

lofty mirage
#

got burnt by this when I started Unity

slim tiger
lofty mirage
north kiln
#

screenshot your player

slim tiger
#

on it

frail hawk
#

unity version?

slim tiger
lofty mirage
#
private void Move() {
        if (!isKnockbacked && !animator.GetBool("IsRolling")) {
            Vector2 curMove = new Vector2(0, 0);
            curMove.x = Input.GetAxisRaw("Horizontal");
            curMove.y = Input.GetAxisRaw("Vertical");
            float curMoveAbsX = Mathf.Abs(curMove.x);
            float curMoveAbsY = Mathf.Abs(curMove.y);
            if (curMoveAbsX == 0 && curMoveAbsY == 0) {
                animator.SetBool("IsMoving", false);
                return;  // skip frame since no movement this frame
            } else {
                animator.SetBool("IsIdle", false);  // MC moving thus not idle
                animator.SetBool("IsMoving", true);
                lastActionTimer = 0f;
            }
            // Change MC Sprite to Move Direction (priorize Vert > Horiz)
            bool isHorizRight = curMove.x > 0 ? true : false;
            bool isVertUp = curMove.y > 0 ? true : false;
            // Move Up
            if (isVertUp && (curMoveAbsY >= curMoveAbsX)) {
                SetDirection(Direction.Up);
            }
            // Move Down
            if (!isVertUp && (curMoveAbsY >= curMoveAbsX)) {
                SetDirection(Direction.Down);
            }
            // Move Left
            if (!isHorizRight && (curMoveAbsX > curMoveAbsY)) {
                SetDirection(Direction.Left);
            }
            // Move Right Prio
            if (isHorizRight && (curMoveAbsX > curMoveAbsY)) {
                SetDirection(Direction.Right);
            }
            rb.MovePosition(rb.position + curMove * moveSpeed * Time.fixedDeltaTime);
        }
    }
slim tiger
lofty mirage
#

That's my logic for top down move

#

I use rb.MovePosition()

#

try this maybe

frail hawk
#

yeah but then you should have error messages unless you changed the input system to old

lofty mirage
#

(you can ignore the SetDirection() helper)

north kiln
slim tiger
frail hawk
#

did you change input system to use the old one?

north kiln
#

notlikethis that's the same screenshot

slim tiger
hexed terrace
slim tiger
#

This one

north kiln
#

My guess is you do have errors in the console when you enter playmode and try to move

slim tiger
#

I'll switch to imp

lofty mirage
#

CTRL+Shift+C for Console fyi

slim tiger
frail hawk
#

yep so you are using code for the old input

#

and unity6.1 uses the new input system

north kiln
#

Great. That's because your tutorial is using the old input manager and not the new input system'

slim tiger
#

fuuuuck

#

The guy said it still worked

#

Gotta find another one then

lofty mirage
#

Unity 6000 doesn't allow Input.Axis("Horizontal" / "Vertical")?

north kiln
#

No, it just uses the new system by default

naive pawn
slim tiger
#

Does Unity change a lot through updates?

north kiln
#

Seems self evident from the previous statements

naive pawn
#

depends on your perception of "a lot"

slim tiger
naive pawn
north kiln
#

You can switch the active input handler to the old system or to use both systems.
Go to Edit > Project Settings > Player > Other Settings > Configuration.
See Active Input Handling.
It doesn't matter that much to just use the old system if you're just learning

naive pawn
slim tiger
naive pawn
north kiln
#

If it just gets in the way of you starting to learn then it's not really worth dealing with that now

solemn bobcat
naive pawn
#

and then the character says what kind of release it is

slim tiger
#

Alright, switched! Thank you all

rough granite
hexed terrace
#

no, they've changed the naming for versions. Rather than get tied into yearly

rough granite
hexed terrace
#

yep

solemn bobcat
sour fulcrum
rough granite
hexed terrace
#

and now we're stuck with "6000" instead of "6" because of the yearly numbering

solemn bobcat
#

I wonder if we will switch to 20290 in a few years. 😄 And then to 70000.

wide rivet
#

is there a better way to adding on-hover size increase to ui other than just increasing the transform size when its hovered on

#

is there like a special gimmick i can do or something where no code is necessary at all

grand snow
#

changing scale sounds like the way to go to me

hexed terrace
#

it's how I always do it (for animating UI, otherwise everything should remain at 1,1,1)

sour fulcrum
#

i mean its either your code or someone elses

#

could animate it

grand snow
#

yea an animation changing scale works too

solemn bobcat
#

In the past, animators were known for creating performance issues for UI objects. I don't know if they fixed it.

grand snow
#

probably because it constantally makes the canvas dirty (requiring mesh rebuilding) and most dont structure things correctly to account for this

rough granite
grand snow
#

changes to any graphic in a canvas causes recalculation of meshes and layouts. Its recommend by unity to use additional canvas components within a canvas to reduce how much is made dirty

rough granite
#

I assume changes to a text field wouldn't count through right?

grand snow
#

ofc it does, the mesh changes to show the new text

#

So if you have everything in 1 canvas and you have some small popup that changes a lot, perhaps that needs its own canvas component

rough granite
#

Oh yeah i have like 20 different text fields that update on Update()

rough granite
#

Never noticed much for the canvas in the profiler though

solemn bobcat
# rough granite Never noticed much for the canvas in the profiler though

An easy way of checking Canvas' performance is to toggle it on and off, while looking at the profiler. If the difference is noticable, then some issues exist. The problem is bigger if you're working on mobile apps, as they have worse hardware and you need to be more careful with optimizations.

rough granite
fair nymph
#

Hello, I have a problem with the level generator. When I drag brick (prefab) into the level generator and then start it, I don't see any bricks.

slender nymph
#

what is "the level generator"

fair nymph
slender nymph
#

oh in that case you're missing a semi colon on line 42

rich ice
# fair nymph

we cant do anything to help fix the code if you dont send the !code

eternal falconBOT
fair nymph
slender nymph
#

if you are certain this code is running and that there are no exceptions being thrown then if i had to guess, i'd say this is probably 2d? and your camera is probably at the same position on the Z axis so it just can't see it. make sure you actually look at the hierarchy to see if anything is being instantiated

solemn bobcat
# fair nymph this is the code, but the code shows no errors

You can add Debug.Log(newBrick.name, newBrick); at the end of the inner loop. It will create logs displayed in your Console window for every instantiated object. After clicking on such log a corresponding GameObject should become highlighted in the hierarchy, making it easy to find it.

slender nymph
#

it will make exactly 1 loop because 0 is less than 1

naive pawn
#

the loop keeps going if the condition is fulfilled, this is not an until

solemn bobcat
silver fern
#

Unity is ignoring changes to default values in variables in the script, but when I make other changes to the script like adding a print() that works fine. Why does this happen?

naive pawn
#

because it's a default value, not the active, serialized value

slender nymph
#

by "default values" i'm assuming you mean the field initializer for a serialized field? and it's doing that because the values are already serialized so you'd need to reset the component if you want to return them all to their default values

naive pawn
#

the default is only used when you create the component or when you reset it

silver fern
#

wtf

grand snow
#

yea just how it is

silver fern
#

what do I do about that?

grand snow
#

sometimes it will update if that var isnt serialized yet but once it is it wont magically change

silver fern
#

do I just right click and reset on the script component?

naive pawn
#

or you can just.. use the serialized field

#

change it in the inspector

silver fern
#

ah so I have to change the default value both in the script and in the inspector?

strong wren
#

You can add [NonSerialized] attribute if you don't want the value serialized.

silver fern
#

I thought serializeField is just to make it visible in the editor

grand snow
#

Ha no, its to let you edit the var value in a scene or prefab and save it...

naive pawn
#

it also saves the value in the scene/prefab file

silver fern
#

ahh

naive pawn
#

if you have a prefab, use the field there as the default rather than the field initializer

silver fern
grand snow
naive pawn
#

but do you need the code one in the first place

silver fern
#

alright thx

grand snow
#

but plz make sure you understand what serialized variables are

silver fern
#

Is there a way to make the variable visible in the editor without serializing and without making it public?

naive pawn
#

serializing lets unity control the value

grand snow
#

can be constant instead:
const float BulletSpeed = 19f;

naive pawn
#

but sounds like you want to control the value in code only (which you shouldn't do)

silver fern
naive pawn
#

these kinds of things should be serialized though to make editing easier

silver fern
#

its easier to edit in code because I don't have to switch around windows and click around a bunch

tulip herald
#

Its better to have it serialized

#

You can change the value while in play mode and you won't have to recompile all of your code just to change a value

#

Especially if its a value you'll be tweaking alot IE: The speed of the bullet

polar acorn
#

The entire point of the inspector is to be the actual final say

naive pawn
#

damn i just said what genesis said

dull grail
#

Is it normal that sprite of scriptable object require almost 2k lines to store? Here the code i use to save it

public void Save(GameData gameData) 
    {
        var fullPath = Path.Combine(_dataPath, _fileName);
        
        if (!Directory.Exists(_dataPath))
            Directory.CreateDirectory(_dataPath);

        var dataToStore = JsonConvert.SerializeObject(gameData, Formatting.Indented, 
            new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });
        using (var stream = new FileStream(fullPath, FileMode.Create))
        {
            using (var writer = new StreamWriter(stream))
            {
                writer.Write(dataToStore);
            }
        }
    }

public class InventorySlotData
{
    public int slotIndex;
    public bool isActive;
    public InventoryObjectSO inventoryItem;
}
silver fern
#

ok thanks everyone

grand snow
#

you cannot do this, you have to save data in a way that can actually be loaded again later, meaning you "save" a sprite by some id or address you use to load it again later.

dull grail
#

So i should save some sort of key and changeable variables?

silver fern
slender nymph
#

use an enum, not a string