#💻┃code-beginner

1 messages · Page 685 of 1

hollow field
#

this is my log

#

(i edited the Debug.Log but forgot to save but it's the same thing)

wintry quarry
#

sounds like you've got two copies of the same script in the scene probably?

rich adder
#

click both logs and see if they take you to 1 object / script

hollow field
#

Dont code at 2am kids

#

I literally moved the script from an empty game object to different object but didnt delete the empty one

rich adder
hollow field
#

thanks @rich adder and @wintry quarry

#

im gonna head to bed before i break anything else ❤️

rich adder
eternal needle
#

<@&502884371011731486>

#

(and in code general)

wise cairn
#

making a basic jump script, how do i make it only work when touching the ground? here's my code

public Rigidbody2D rb;

private void Start()
{
    jumpAction = InputSystem.actions.FindAction("Jump");
}

private void Update()
{
    if (jumpAction.WasPressedThisFrame()) { rb.linearVelocityY = jumpPower; }
}
cosmic dagger
rich ice
wise cairn
cosmic dagger
wise cairn
#

ok thanks

cosmic dagger
#

There are tons of resources for that. Just search using the same question you asked us . . .

radiant ferry
#

Does anybody know any good ways to check when there are no active instances of a prefab in a scene? I'm making an asteroids clone to learn the ropes of Unity and I'm trying to detect when all the asteroids are destroyed so I can instantiate another round.

ivory bobcat
#

You could probably use object pooling with the asteroids and be able to tell how many asteroids you've got with it's collection/array implementation. I wouldn't recommend searching the hierarchy for objects unless you really have no other choice. If they share a single parent, you could probably use this to get the number of children https://docs.unity3d.com/ScriptReference/Transform-childCount.html

radiant ferry
eternal needle
# radiant ferry Huh, I didn't think about that. I'll try that out thanks 👍

you don't need to check the transform child count tbh. if you go the object pool route, unitys object pool has properties you can use to get the number of objects active/inactive or both https://docs.unity3d.com/6000.1/Documentation/ScriptReference/Pool.ObjectPool_1.html
Or if you dont go the pooling route, you need to store these objects in a list. Instantiate returns the spawned object. either remove it from the list when the objects are destroyed or just check if the list elements are null every so often.

#

getting the child count forces you to have these asteroids as children of a specific object which is a bit fragile and not needed

radiant ferry
jade cosmos
#

hey guys, so basically I am trying to see if a player has pressed a button while inside of a trigger using the if (Input.GetButtonDown) function but whenever I run it it errors with this error ArgumentException: Input Button Interact is not setup. To change the input settings use: Edit -> Project Settings... -> Input Manager UnityEngine.Internal.InputUnsafeUtility.GetButtonDown (System.String buttonName) (at <44a762dafa6b4e0ca8423d645d61ba11>:0) UnityEngine.Input.GetButtonDown (System.String buttonName) (at <44a762dafa6b4e0ca8423d645d61ba11>:0)

but how can this be whenever it is

keen dew
#

It says Input Manager, not Input System Package

jade cosmos
#

ohhhh

#

yea im illiterate

north kiln
#

the Input class is not the new input system

jade cosmos
north kiln
jade cosmos
#

because I am using all the correct packages

#

sorry for ping forgot to turn it off

north kiln
#

It's a completely different API you have to use, you write completely different code

jade cosmos
#

because I have to use a controller?

#

like a player movement controller

#

uhh input controller

#

idk what its called

rich ice
#

the new input system is just a completely separate thing from the old input system. the input methods are still the same they're just handled and coded differently

#

i'd reccomend looking at docs or finding a tutorial online if you don't understand how it works.

jade cosmos
#

and lemme guess the new one is better?

rich ice
#

i personally think so, I don't know the specifics of it. but if you plan to add controller support then it definitely makes the process a lot easier.

umbral bough
#

Hi, is there a way to log an exception with the clickable stack trace and a custom message?
I tried this:

Debug.LogException(new(
    $"(Audio Manager) Failed to get or create source for '{audioItem.Name}'", e));

However, that logs the inner exception first, and the exception message later.
That's quite annoying and makes no sense.
Is it possible to somehow work around this?
Please @ me and thanks in advance!

lament drum
#

Hi I'm trying to have a game button that when I press it it loads the game so basically here's the code that i have and it doesn't work pls help
Error Message from Unity : Assets\MainMenu.cs(6,21): error CS0246: The type or namespace name 'MonoBehavior' could not be found (are you missing a using directive or an assembly reference?)

Code :

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

public class Play : MonoBehavior
{
// Update is called once per frame
void Update()
{

}
// une fonction de "public" qui genere la scene choisi
public void PlayGameScene ()
{

    SceneManager.LoadScene("Quarry");
    
}

}

lament drum
#

it works let's gooooooooooo

#

dosn't load the scene though 😂 I'm going to work on that now

twin pivot
lament drum
#

yes

lament drum
#

found the problem it's on me i forgot to put the working code in unity my bad

#

it was set on no function😅

earnest wind
#

Is this how u would make a SceneLoad without having the script on any gameObject?

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
    static void InitOnLoad()
    {
        SceneManager.sceneLoaded += OnSceneLoaded;
    }

    private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
        TexturesLoaded.Clear();
        Debug.Log("TexturesLoaded cleared on scene: " + scene.name);
    }
#

im guessing i can just have it like this too?

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    static void InitOnLoad()
    {
        TexturesLoaded.Clear();
    }
#

actually im just going to make a gameobject and just have it a reference since that would be easier for my life

lament drum
#

hy guys could somebody pls tell me how to show a menu in a game by pressing a button.
As of right now I have a little game project that works and the menu pannel that lunch at the start of the game from wich I can lunch it or exit from it.
How can I go to that pannel by pressing "M", while being in the game, I only understood that it's by the event system but I don't know how to do it.
Pls help

Here's my code for now :

function Update()
{
if (Input.GetKeyDown("m"))
{
SceneManager.LoadScene("MainMenu");
}
}

#

here's my error warning

#

using UnityEngine;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class MainMenu : MonoBehaviour {

void Update(){
if(Input.GetKeyDown(KeyCode.M)){
SceneManager.LoadScene("MainMenu");
}
}
}

wintry quarry
#

Also !code

eternal falconBOT
ruby python
#

Hey all,

Could anyone help me out with a little Logic & Maths please, my head is spinning a little. 😕

Basically trying to generate a black and white image (using red atm cause of another issue) at runtime with a couple of 'bands' of white on black based on input values between 0 and 90 for use as a mask elsewhere.

https://hastebin.com/share/jagopilofo.java

This is my current code. I'm certain there's a maths error in the ConvertLatitudeRange as my results don't seem to make sense (ie, I believe minMaxLatitude.y should be 614.4f.)

(Current Vector2 input is 30,60)
width is 1 (doesn't need to be bigger than that)
height is 1024
equator is height/2 (=512)

Couple of images for reference

1, input settings (Ignore Terrain layers section in Inspector, all that is disabled for now
2, current results
3, Highly detailed engineering schematic of what I'm trying to achieve.

scarlet skiff
#

colliders are starting to piss me off.

i use a grid collider on my grid map, i get stuck in nothing, same for enemies, cuz its "uneven" fir some stupid reason.

i use a composite collider, some raycast fail because they are cast inside the ground, bu dont detect it cuz composite collider is like not filled, additionally, it doesnt work well with astar pathfinding graphs.

wth am i supposed to do?

sharp bloom
#

What is a "grid collider"?

#

You mean a tilemap collider?

#

Make sure your physics shapes are right

oblique chasm
#

Best practices for modular architecture question
I have a ball and a zone. I would like the ball to destroy once it touches the zone.
My "Death" code goes on the ball. The zone however, should hold what it does independently of that right?
Should the zone, once collided with, tell the ball to run the Death code? This way if I have another zone that, lets say increases the amount of points you get or something, I could have the zone do both by having them be separate scriptable objects attached to the zone.
Otherwise, if I have the zone just say "hey, you hit me, I have x tags) and the ball read those tags then fire off the appropriate methods, the ball would end up containing a ton of code for each possible interaction with a zone. Even if the method doesn't affect the ball (Similar to the points example.)
Am I thinking correctly about this? I'm a bit mixed up cause I'm under the impression that the zone shouldn't talk to the ball, but this might be from previously working in godot where you "call up, signal down", or is this the same thing?

wintry quarry
sharp bloom
#

Maybe the zone could have an interface with some method like Interract() that does some different logic depending on what type of zone is it.

#

That way the ball script doesnt care about what type of zone it is, it just automatically calls Interract() if it enters any kind of zone

lament drum
#

hi so I've got this code to be able to go back to my menu if the character is inside the trigger zone, however for some reason when I press "m", it doesn't do anything and I am stuck in the current scene, how can I change scene by pressing "m", what is wrong in my code?

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

public class MoveScene_OnKeyPress : MonoBehaviour
{
    [SerializeField] private string MainMenu;
    [SerializeField] private GameObject uiElement; 
 
    private void OntriggerStay(Collider other)
    {
        if(other.CompareTag("Player"))
        {
            uiElement.SetActive(true);

            if(Input.GetKeyDown(KeyCode.M))
            {
                SceneManager.LoadScene(MainMenu);
            }
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if(other.CompareTag("Player"))
        {
            uiElement.SetActive(false);
        }
    }
}
oblique chasm
#

@sharp bloom If I have 5 types of zones though, wouldn't the ball need code for what each zone types does?

slender nymph
lament drum
slender nymph
#

what calls OntriggerStay

lament drum
#

my collider object

#

i didn't put it's name sorryyyy

slender nymph
#

how, it's a private method and isn't a unity message

lament drum
#

so if i put my collider object name it should work?

slender nymph
#

no

#

nothing is calling OntriggerStay

lament drum
#

oh

lament drum
#

mm so I corrected and put the Trigger instead of trigger

#

but still same problem

rich adder
#

yea maybe thats a bit much

rich adder
#

which part isn't working

lament drum
#

so when I load the game and I go to my trigger it doesn't show the text to change scene

#

and even if i press m it still doesn't change scene

rich adder
#

forget the keypress, is the UI appearing

slender nymph
#

have you fixed the logic issue i pointed out

lament drum
lament drum
rich adder
#

do you have at least 1 rigidbody or your tag is not set

slender nymph
lament drum
#

it's in rigid body but it's not set

lament drum
rich adder
lament drum
#

my trigger has box collider but uiElement is not checked here's screen shot

#

or was it not the question?

rich adder
#

show Player that walks in this trigger has
a Rigidbody/CharacterController & tag set as "Player"

lament drum
sharp bloom
#

I imagine something like this

rich adder
# lament drum
  1. how do you know you're in the trigger at all ? you can't see the collider when testing
  2. are you moving the rigidbody with AddForce/Velocity in code ?
  3. is that box collider actually set to IsTrigger ?
polar acorn
lament drum
#

and yes it's set to is triiger

#

I juste changed the name of my character to Player and the text appears in the game test by unity but when I build it it doesnt show

rich adder
oblique chasm
# sharp bloom I imagine something like this

maybe I'm having a hell of a time wrapping my head around this.
Lets say I have 2 zones, a destroy zone and a level up zone. If the ball hits the destroy zone it destroys itself, if it hits the level up zone it's "XP" variable goes up by 1.
In this case, the ball would have the "dostuff" method, but thats only one method. How is it supposed to handle multiple possibilities outside of doing somthing like tagging the zones?

lament drum
#

when i say to unity build and run it like that

rich adder
# lament drum

whatever you did it was def not changing the name, maybe something else save and it started working again.. either that or youhave poorly anchored UI so you can't tell as well when it appears somewhere else..

#

no where in the code you sent there is anything about gameobject name checks

lament drum
#

most likely, but i don't know anymore cause it works in unity but not when I say build and render

rich adder
#

why not center the text? just for testing because on the edge is difficult

#

or better yet make something really obvious happen for testing..

lament drum
#

I will try that

#

good idea

lament drum
sharp bloom
#

https://youtu.be/2LA3BLqOw9g?si=wL8F6K4U0acOqu1T Nice quick video on interfaces

Sign up for the Level 2 Game Dev Newsletter: http://eepurl.com/gGb8eP

In this video, you'll learn how to use interfaces in Unity3D and Game Development.

#Interfaces #Unity3D #GameDevelopment

The Interface is one of many programming concepts that can be utilized in both Unity3D and Game Development, in general. It's a powerful construct in obj...

▶ Play video
rich adder
#

You have to use update to capture inputs

#

so you either make a bool that you are insideTrigger with OnTriggerEnter/Exit then use that in update with keypress like if(insideTrigger && Input.GetKeyDown(KeyCode.M)
or
you can make a bool for KeyDownPressed, capture it in update then use it in the trigger.
sceneSwitchPressed = Input.GetKeyDown(KeyCode.M)
former is the cleaner option IMO

sharp bloom
lament drum
# rich adder You have to use update to capture inputs

so let's say I do

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MoveScene_OnKeyPress : MonoBehaviour
{
void Update() {"rest of code"}
}
rich adder
rich adder
#

but try it and see I guess

lament drum
#

I will go to option 1 cause if you think it's better I will try it first

#

and if it work i will try option 2 later

rich adder
rich adder
#

classes can't inherit multiple classes , but classes can implement multiple interfaces (their major strength)

sharp bloom
#

Ye good point

#

I started coding in Python which actually support multiple inheritance, kind of cursed to think about when I've only used C# for the longest time now

rich adder
#

Python is weird

sharp bloom
#

I can't use it anymore lol, just too much weirdness

lament drum
slender nymph
#

there are beginner c# courses pinned in this channel. you need to start with those.

lament drum
#

i'm lost

rich adder
#

yes you lack the basic c# probably something you want to be doing before anything

sharp bloom
lament drum
rich adder
#

IDE not even configured but thats the last of your problems right now, you wrote some nonsense syntax lol

#

insideTrigger is a variable that doesnt currently exist... the IDE / compiler would tell you but your syntax is completely fucked..

lament drum
#

oh

sharp bloom
#

So yeah line 13 is nonsense, you're trying to assign the value true to a function, I don't even know what it's supposed to be doing

rich adder
sharp bloom
#

You use it like

private void OnTriggerEnter(Collider other)
{
  //do stuff
}
rich adder
#

it would be one thing if it was slightly wrong but this is like beyond that lol

sharp bloom
#

Oh you have the other event functions set-up correctly 🤷

lament drum
sharp bloom
#

Maybe use a pre-built character controller?

#

There are free ones

rich adder
#

thats probably what they did, but now are in the classic "what did I get myself into, this is harder than I thought " when you have to meld different systems together

polar acorn
eternal falconBOT
cinder spruce
#

Hello, i took a webGl build of my game, when i click on the game window in browser it highlights the game window, turns to blue, and disables controls. It goes back to normal when i double click. How can i fix this?

rich adder
#

also would test different browser and see if its isolated issue

cinder spruce
rich adder
#

tahts why I linked it

cinder spruce
#

this felt to me like a code related issue but okay, thanks

rich adder
#

if you think its somehow code related, you should probably show any relevant code

lament drum
cinder spruce
#

No, i haven't wrote a code to create this issue but i meant the solution of issue could be the adding a right code. Like cursor focus options. Anyway, i'll try this on another browser first

ruby python
void dawn
#

So I'm working on this single player fps game and Im having a lot of issues making enemies for it, to start many enemies seem to not have a concept of front they just move around and shoot in whatever direction they want to , and that only happens when the enemy AI work , even with nav mesh and everything some enemies won't even move or detect the player, some won't even play the animations correctly

Now that I think about it I think i haven't made a enemy that works as intended , can anyone tell me how do get out of this hole ?

fallow wind
#

how to code

sharp bloom
ruby python
#

I'm actually making progress, just trying to figure out the maths to correct the second 'bar' (Right Side) at the moment (and then need to figure out why the texture isn't displaying red&white like it supposed to. lol.

https://hastebin.com/share/yaruqakudu.java

#

Texture assigned in inspector via code.

pallid nymph
#

I don't see width, height and equator in code and how are they set and whatnot... code otherwise seems fine 🤔

#

I'd probably just do it all in a shader, but hey

ruby python
pallid nymph
#

Feels likq equator is not the correct value, but I don't know

#

oh, it's visible in the logs...

ruby python
#

Yeah it is. textureheight/2

pallid nymph
#

oh, stupid me...

#

of course that's wrong... it only works if the middle of your min-max is the middle of the side

ruby python
#

This is an illustrated example of what I need to fix.

pallid nymph
#

you need to check if it's between height - max and height - min

#

in the else if

#

what you made is "repeat after mid point", what you need is "reflect after mid point" if that makes sense

ruby python
#

Yeah, it's the translating from 90-0-90 (top, middle, bottom) to 0-1024 (top - bottom) that's getting me. lol.

scarlet skiff
# sharp bloom Make sure your physics shapes are right

Yes, tile map collider. Also wdym make sure my physics shapes are right? I use click "used by composite" on the tile map collider. That's what I mean by using it, and those were the cons of using it, likewise if I just don't use it, I get the other cons

willow iron
#
        float Angle = Mathf.Atan2(look.y, look.x) * Mathf.Rad2Deg;
        float fAngle = Mathf.Clamp(Angle, -30, 30);
        transform.Rotate(0,0,fAngle);```
my value is not being clamped?
#

its currently at -84 as we speak

modest dust
#

And what are you trying to do?

willow iron
#

get the gameobject the script is attached to to face a transform (this transform being the player variable). If the player transform is more than 30 degrees away from the front of the gameobject, it will be considered out of sight and the gameobject will no longer rotate towards the player. This is a 2d game, and the code works perfectly except for the fact that fAngle seems to not be getting clamped at all.

modest dust
#

transform.Rotate changes the rotation of the transform by the given amount, that is, for example similar as if you did current_rotation = current_rotation + your_angle

#

You're just clamping your_angle but the rotation still occurs, there is no code preventing that

#

If executed several more times it eventually face the player

jolly stag
#

Heya I was wondering if I could get some help, I'm trying to get something to spawn either on the left side or right side of the screen. The code seems to work when forced to pick a side by changing the range random can do to either 1 or 0 but when given the option it only picks left.

    {
        if (Input.GetKeyDown(KeyCode.J))
        {
            Instantiate(powerUpMGPrefab, RandomPowerUpSpawn(), powerUpMGPrefab.transform.rotation);
        }
    }

    private Vector3 RandomPowerUpSpawn()
    {
        float limits = 4.24f;
        int leftRight = Random.Range(0, 1);
        if (leftRight == 0) 
        {
            Vector3 spawnPos = new Vector3(-limits, 1, 1); //Spawn Left
            return spawnPos;
        }
        else { 
            Vector3 spawnPos = new Vector3(limits, 1, 1); //Spawn Right
            return spawnPos;
        }
    }```
polar acorn
jolly stag
#

Well from playing about rasing the number to 2 worked. Thank you for your help :)

rich adder
jolly stag
hidden fossil
#

guys where is the use composite checkbox?

#

used by composite

rich adder
hidden fossil
#

do newer versions not have the checkbox and it just becomes composite operation

rich adder
#

yes it was changed in newer version

hidden fossil
#

thx

boreal night
#

!Learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

hardy bobcat
#

Is there a way to pull all the api documentation for just the packages you have installed? usually when I am coding I have the documentation in a folder somewhere, and I just search within files the method I need info about and I can just get that info inside my IDE. heck sometimes I don't even have to click on anything

#

Anyone have a good way they get all the stuff in the same place to reference?

glad ibex
#

Hello dear Uniticians,
Im using the code below, to draw a ray to where the player is looking, and to move an empty object (that is marked by the sphrere), however even in play mode the ray and the empty object is somewhere in the very wrong place, where the player is clearly not looking. Thank you in advance for any help.

using UnityEngine;

[ExecuteAlways]
public class RaycastVisualizer : MonoBehaviour
{
    public Camera playerCam;
    public Transform marker;

    void Update()
    {
        //nre check
        if (!playerCam || !marker) return;

        Ray ray = playerCam.ScreenPointToRay(new Vector3(0.5f, 0.5f));
        if (Physics.Raycast(ray, out RaycastHit hit))
        {
            marker.position = hit.point;
        }
    }

    void OnDrawGizmos()
    {
        //nre check
        if (!playerCam) return;

        Ray ray = playerCam.ScreenPointToRay(new Vector3(0.5f, 0.5f));
        Gizmos.color = Color.red;
        Gizmos.DrawRay(ray.origin, ray.direction * 100f);
    }
}

rich adder
glad ibex
rich adder
#

might be the same thing but worth a shot, can you show gizmo for the camera transform in local pivot mode ?

hallow acorn
#

can someone tell me why i get the error "The call is ambiguous between the following methods or properties" in visual studio on playerControls = new PlayerControls();, playerControls.Enable(); and playerControls.Disable();? heres the code: ```cs
public class playerController : MonoBehaviour
{
private PlayerControls playerControls;

[Header("Values")]
[SerializeField][Range(.01f, 10)] private float speed;

private void Awake()
{
    playerControls = new PlayerControls();
}

private void OnEnable()
{
    playerControls.Enable();
}

private void OnDisable()
{
    playerControls.Disable();
}

private void Update()
{
    Move();
}

}

#

ignore Move(); in Update i deleted it to shorten the code a bit

glad ibex
hallow acorn
glad ibex
#

Better use gameObject.AddComponent or add it initially if u dont need it on awake and need it allways

hallow acorn
rich adder
#

if it was generated class from input asset its not a MB

glad ibex
hallow acorn
#

wait i think ill try to regenerate the class as i now get errors in it too after opening

#

ah yes

#

good old unity bug

#

didnt know what happened but it worked after regenerating it

hallow acorn
#

thanks for the help even tho it fixed itself haha

glad ibex
#

Np lol

rocky gale
wicked fiber
#

Hello! I need help figuring out a collision error with my player to the wall.

#

using UnityEngine;

public class playerMovement : MonoBehaviour
{
[SerializeField] Rigidbody2D rigidBody;
public float Playerspeed;
float moveSpeed;
float moveSpeed2;

// 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()
{
    moveSpeed = Input.GetAxis("Horizontal") * Playerspeed;
    moveSpeed2 = Input.GetAxis("Vertical") * Playerspeed;

    transform.position += Vector3.right * moveSpeed * Time.deltaTime;
    transform.position += Vector3.up * moveSpeed2 * Time.deltaTime;
}

}

wicked fiber
#

oh...

rich adder
#

moving transform will teleport through walls , you need to use the rigidbody component methods

wicked fiber
#

what would be that scripts name?

#

sorry i started 3 day ago

rich adder
# wicked fiber what would be that scripts name?

Rigidbody2D component you have to access the values with the . if you just started recently I would suggest you go through the unity !learn 👇 starters/junior courses they guide you through learning rigidbody movement and more.

eternal falconBOT
#

:teacher: Unity Learn ↗

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

wicked fiber
#

ok, so theoretically, it would be something like "RigidBody2D.movePosition" right?

wicked fiber
#

ok thanks!

lilac fractal
#

In my game, waves of enemies can spawn. There can be different enemy types within each wave.
If I wanted control over spawn patterns (for instance, one large enemy in the middle with 3 small enemies in front), how do folks go about modeling this? I could quite literally have several code files that denote enemy type and location to spawn them in, but I'm wondering if there's a prettier way

#

It almost feels like I could be doing a prefab and building this in the editor drag/drop

shell sorrel
#

would create some sort of data structure that defines that

#

store it in scriptable objects or something like json that your system ingests

modern aurora
#

Could use some help here


using UnityEngine;

public class TileScript : MonoBehaviour
{

    TileController tileController;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    private void Start()
    {
        tileController = GameObject.FindFirstObjectByType<TileController>();
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            print("it works!");
            tileController.SpawnTile();
        }

    }

}

trying to spawn a tile when the player leaves a box collider trigger area. neither printing nor spawning occurs. i have a feeling i just didnt implement my trigger correctly but im not sure. player has player tag and has a rigidbody, the collider in the tile is marked as a trigger, so idk

The SpawnTile function is a public function in the tilecontroller if you need to see that as well.

#

that embed didnt work at all lmao

#

!code

eternal falconBOT
rich ice
#

` not ' cat_thumbsup

rich adder
modern aurora
#

fixed. i had a box collider attached to a cube as a child of the tile, rather than the collider being a component of the tile itself. worlds biggest idiot award goes to me 🤡 thank you for your help tho i appreciate u

eager scarab
#

where should i get started in learning c#, there are alot of videos and idk what one would be the best to get started with (i do have prior knowledge in code, so i know the basic functions, loops, variables and all that)

wise cairn
#

any idea why my game view is just all blue? please tell me if you need more information

eager scarab
eager spindle
wise cairn
eager spindle
#

Yep, show us the Transform

#

What's the position of the sprite?

twin pivot
#

Change the color of ur skybox if u dont like the blue color

eager spindle
wise cairn
#

and also the ground

eager spindle
#

Hmm what's the position of the camera then?

twin pivot
#

Is the sprite supposed to be a ui thing or a world thing

wise cairn
eager spindle
#

The camera needs to be "behind" the sprite(z position is -10) in order for the camera to see the sprite

eternal falconBOT
#

:teacher: Unity Learn ↗

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

eager spindle
#

Run the game and help me check the position of the camera

eager scarab
#

ty

wise cairn
twin pivot
wise cairn
#

yeah thats what i was doing

lost maple
#

HI

#

how to declare array of arrays in correct way?

#

i tried Vector3[][] myArrays={new Vecto3[],new Vector3}

#

but it didn't work

teal viper
candid garden
#

I've got this script for managing stats on my characters but I can't get the _basevalue and _modifiedvalue to show in the inspector, any idea's why not?
The BaseValue and ModifiedValue show up but if I set the BaseValue in the inspector the game just ignores it and when I try to fetch the data it resets to 0

eternal needle
candid garden
#

This is where I create the attributes
[System.Serializable] public class Attribute { [System.NonSerialized] public RemnantEquipmentAndStats parent; public RemnantStats statType; public ModifierInterface modifierValue; public void SetParent(RemnantEquipmentAndStats parent) { this.parent = parent; modifierValue = new ModifierInterface(AttributeModified); } public void AttributeModified() { parent.AttributeModified(this); } }

eternal needle
candid garden
#

it shows up like this

#

I have a list of modifiers for adding modifieres to the stats non destructively, but I've been getting a null error for this list, could that be the issue?
public List<IModifier> modifiers = new List<IModifier>();
this is where it returns null
public void UpdateModifiedValue() { var valueToAdd = 0; if (modifiers == null) { Debug.LogError("Attempted to update null modifier"); return; } if (modifiers.Count > 0) { for (int i = 0; i < modifiers.Count; i++) { modifiers[i].AddValue(ref valueToAdd); } } _modifiedValue = _baseValue + valueToAdd; ValueModified?.Invoke(); }

ruby python
#

Okay, very confused. Not a coding question but tbh, I can't really see anywhere to post.

But, CharacterController step offset is weird and I really don't get it.

Calculator result is Height + Radius * 2 of the Character Controller height & radius, as the error says. But i'm still getting the error.

It's truly baffling how this works tbh. The errors only disappear when I put the step height to around 0.2 😕

orchid swallow
#

Attack 2 is not working after Que attack, what is the cause

orchid swallow
ruby python
#

!code

eternal falconBOT
ruby python
#

LMAO. Even doing that, calculator result = 0.23998908
enter 0.23, still get the error.

#

Anything above 0.2 I get the error. (even 0.201), sod it, 0.2 will do for now.

#

wtf? Now it's changed its mind and anything above 0.195 throws the error.

pallid nymph
#

Is there any scaling going on?

ruby python
#

Okay, this is massively weird.

Because the 'working' step offset value was so close to the 'height' I tried this.

and yeah, weird but if the step offset is higher than the height, it throws the error. lol.

#

Okay, I'll go sit in the corner. my main root object isn't scaled, but the actual character model is, so I'm guessing the value of 0.23 should actually be 0.023

#

I forgot I'd done that. lol.

coarse stag
lost maple
grand badger
#

Anyone needs help? :p so many unanswered questions above

eternal needle
# candid garden it shows up like this

Those seem to be the correct fields showing up. Your property BaseValue isnt what youre seeing here because properties arent serialized. Same with modified value.
I dont really know what your IModifier is because you never showed it or a class that inherits it. I assume a unity object is inheriting it (like a monobehaviour). In that case, your null check isnt using unitys null check and you'd need to cast it to a unity object

rich ice
grand badger
#

assuming you mean on a button, myButton.onClick.AddListener(() => MyFunction(parameters));

#

or if it's a standard C# event, myEvent += () => MyFunction(parameters), or even just myEvent += MyFunction if the event parameters match the function's

pallid nymph
#

I sometimes come here when I'm bored too 😅 (bored = procrastinate-y)

umbral bough
#

Hi, I have this struct in Unity:
https://hastebin.com/share/gozotevuvu.csharp
I have to have the constructor with all the optional parameters but would also like to have default serialized values in the inspector.
Is that possible?
Thanks in advance and please @ me.

rich ice
eternal needle
#

If you want it to have specific values in inspector too by default, you do the same thing you would do in component. Assign the value on the same line where you declare the variable

pallid nymph
umbral bough
#

ah, my bad, I said struct instead of class, p fried atm

pallid nymph
#

where does this "serialized bla bla ignored during serialization" come from? normally doing public Vector2 VolumeRange = Vector2.one; works fine

#

do you have a list of those classes by any chance?

umbral bough
eternal needle
umbral bough
pallid nymph
#

This is what I get without the attributes, so I blame them 🤷‍♂️

umbral bough
#

odd, let me try it on my end rq

eternal needle
umbral bough
pallid nymph
#

What version of Unity? 🤔

#

Oh, also it only works for new instances maybe

umbral bough
#

and also, wdym by works for new instances?

rich ice
#

or just extended the message some other way

umbral bough
#

ye, anyways, if you got ideas as to why I can't have default values on these fields just @ me

#

it's 99% not the attribtues as I removed them, and rider also suggests that there's a deeper issue

rich ice
#

according to this thread, it's a bug.

umbral bough
rich ice
rich ice
#

although, let me try it on my end real quick. i'll see if i can come up with anything new

umbral bough
#

This seems like a major issue, odd that it hasn't been taken a look at for so long.

pallid nymph
#

That's why I asked if it's in a List. They tend to not work in lists. I tried to do a workaround before, buut I think it was getting way too hacky or something and I noped out.

umbral bough
#

nope, not a list, it's always a field, or a field of a field

pallid nymph
# umbral bough and also, wdym by works for new instances?

If you have a serialized object and you add an initializer value, the objects that are already serialized won't get the new value. Won't even work if you add a new field that's initialized.
Or at least I think it might be the case. I can test it later.
My point was to do it without the attributes and make a new instance of the thing that contains the field or at least reset it. See if that makes it work.

tepid urchin
#

I'm moving items from inventory to chest...
When I have a stack of existing items to fill, this means changing the amount number in chest and deleting the item from inventory.

Items are just game objects with a script and child object that has canvas renderer + image (which has child for amount text).

In method for filling partial item stacks, I do "Destroy(sourceItemUI.gameObject);", but nothing happens. The game object is not being deleted ever.
If I do DestroyImmediate, it will get removed as expected.

What is happening here? As I understand, DestroyImmediate should not be used if possible due to potential unexpected issues (that I didn't investigate too closely atm)

umbral bough
#

yeah that was it, excellet :/

rich ice
#

got there in the endDuck

pallid nymph
#

Oh wow 😄

spiral night
#

im only on understanding methods of the book at the moment. I must say it is quite hard to not worry if i am wasting my time trying to learn it. I am worried im not smart enough for later in the book 😅 I struggle with a learning disability but I am so determined to acquire this skill. Sorry I know it is not a coding question I just thought I may feel better after talking with people who are good at this hahaha.

frail hawk
spiral night
#

that is true, thank you I appreciate that. Hope your projects are going well

kindred iron
#

guys i wanna add in day versions and night versions the day scripts (for example day1 script for the first day) and i will have like 50 days but the problem is that i cant put the scripts inside of these can someone help me?

rich ice
kindred iron
#

and if i attach the scripts to the gameobjects it will be soo massy

#

i dont want that

past yarrow
kindred iron
past yarrow
kindred iron
#

in this box will be wrote the texts of the each day like in day 1 there will be text options for day2 script the options will be different

past yarrow
queen adder
kindred iron
kindred iron
#

how can i make options like for each options

rich ice
past yarrow
kindred iron
past yarrow
#

Could you explain what kind of text are we talking about ? Is it just "Day 1", "Day 2" written on your HUD screen ? or some dialogue (with or without answers for the player to click) or quests ?

kindred iron
#

there will be a lot of text in each day

kindred iron
#

On Day1 there it will be like
string[] dialogue;
dialogue[0] = {
text = "hello world";
type = Types.NotQuestion
};

kindred iron
past yarrow
kindred iron
#

like the video?

past yarrow
past yarrow
kindred iron
#

ok

#

ty

rich ice
past yarrow
rich ice
#

at first it was, that was mostly just writing the script though. only problems i have with it now is that i forgot to add comments lol

kindred iron
#

and i wanna make my own dialogu system which is not messy and not hard to make

past yarrow
kindred iron
grand badger
#

It's fun when it's busy and there are questions to be answered, but yeah at "I'm bored" times every server just seems to be empty 😛

pallid nymph
#

It's the worst! AI is stealing our fun, our opportunity to escape from boredom! 😂

shadow spear
#

Can anyone tell me why I can't see my hands but I can see my weapon?

rich adder
pearl current
#

Does anyone have any useful tips on how to deal with enemy cluttering? To give more context the tracking script is fairly simple:

private void MoveTowardsPlayer()
{
    transform.position = Vector2.MoveTowards(transform.position, player.transform.position, speed * Time.deltaTime);
    animator.SetBool("isAttacking", false);
}```
frosty hound
#

You'll need to look up the implementation of boids

#

Also known as flocking

night mural
pearl current
night mural
#

if you look at games like doom, the generic melee enemies are really slow so that they mostly don't end up clumping before they die

night mural
#

2 enemies in the same level shouldn't clutter up? what does that mean?

#

oh you're just moving their posisions so they are literally inside each other

pearl current
#

yes

night mural
#

you could probably toss colliders on them

#

otherwise yeah, roll your own spacing system, but it depends on the kind of game whether that makes much sense

pearl current
#

they do have colliders

night mural
#

you need it for an RTS but in an FPS you are probably better off designing enemies that don't swarm the player so effectively

#

hmm well my recollection is that that should work but you might need to move them via their rigidbody instead

graceful horizon
#

Hey im new to unity, anybody knows how to make a simple 3d Map?

#

im trying to make a simple game similar to schedule 1 but with completely different mechanics

frosty hound
eternal falconBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
Collaboration & Jobs

graceful horizon
#

💔

pearl current
rich adder
hollow field
#

is there a way to make a UI Toggle button show 2 different icons on click? I want to have a thumbs up for on and a thumbs down for off

graceful horizon
rich adder
eternal falconBOT
#

:teacher: Unity Learn ↗

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

polar acorn
#

If it's a coding question, post !code

eternal falconBOT
lament drum
# rich adder Okay well you asked in the wrong channel.. this is a code chqnnel... if you want...

Hi nav just wanted to tell you I was able to finally do what I was looking for yesterday with this code bellow, and thanks a lot for your time it really helped me a lot just a quick thing about the key down, when I said press "M" it would'nt do anything and when I said "A" it only worked when I pressed the "Q" key is it because I'm on AZERTY or is it something else, cause I then put it on "P" since it's the same position in AZERTY and QWERTY.

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

public class ForMainMenu : MonoBehaviour

{
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.P))
        {
            SceneManager.LoadScene("MainMenu");
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible = true;
        }
    }
}

#

and also thanks for all the other that also helped me and pointed other things

hollow field
#

is there a way to change a toggle button so the checkmark doesnt disappear when you click it?

rich adder
ancient oak
#

Hey I'm trying to use the 2d multiplayer prefab but I cant figure out how to edit the scenes/make new ones, can someone help me?

rich adder
queen adder
#

Could anyone recommend a video or article explaining the weighted list class? (the simpler the better)

grave frost
#

is this in a build?

queen adder
#

class WeightedList<T>

grave frost
queen adder
#

oh is it not?

grave frost
#

In general: if I first launch the game,

naive pawn
queen adder
#

ouch, that was a perfect solution

naive pawn
#

you could make it yourself

#

but it doesn't really sound like it needs to be its own class

#

ah wait i misunderstood the "weights" aspect, i was thinking of priority

queen adder
#

and now i cant find anything on it

naive pawn
#

lol lesson learned real quick, eh

#

googling "weightedlist unity" gave me plenty of results though

queen adder
#

yeah just not a class

#

i think im fine then

#

thanks

wicked fiber
#

does anybody understand why this collision isn't working?

#

private void OnCollisionEnter2D(Collision2D collision)
{
Destroy(gameObject);
}

wicked fiber
#

thank you

queen adder
#

Hello! I have a few questions regarding setting up Unity for coding.

I am using the version 6.1 right now.

  • How do I set it up for Visual Studio Code as I don't see the package in Package Manager.
  • Everytime I try to work with Input.GetAxis("Horizontal"); it gives me an error that, that way of doing things is old.
slender nymph
#

!IDE

eternal falconBOT
slender nymph
#

as for the error you are getting, it isn't saying that is old. it is saying that your project is currently set up to use the input system in the active input handling settings. it even tells you that setting is in the Player settings so you can go and change it if you intend to use the input manager

hollow field
#

I'm at my wits end with UI stuff. I have a game object with a box collider and several children. I have a script that has both OnMouseEnter and OnMouseDown but neither of them are activating

edgy tangle
slender nymph
edgy tangle
#

In other words those event functions will not run as a result of the mouse entering colliders in child gameobjects

hollow field
slender nymph
queen adder
slender nymph
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

edgy tangle
edgy tangle
edgy tangle
#

Using the IPointer interfaces are better in most ways anyway. Just not automatic so it requires more setup

hollow field
#

everything here except camera and eventsystem is on the UI layer

edgy tangle
hollow field
#

I dont know what Input System vs input manager means

ripe lotus
#

I know that some fix is to use raycast or idk but i rly want to udnerstand wtf is happing here

#

thx !

grand snow
#

Id replace this and use Pointer events with an event system instead

#

I use this a lot and im happy with how it works in 3d and 2d

frail hawk
#

do we have ui elements here

#

just asking

naive pawn
#

there are 2 channels with "ui" in the name

frail hawk
#

nono i am asking because rob mentioned IPointerEnterHandler

slender nymph
#

that can be used for world space objects

frail hawk
#

then this is new to me

slender nymph
#

did you not think it was odd that rob said they needed a physics raycaster component? that is obviously unrelated to UI, it's what makes it work for detecting colliders in the world

frail hawk
#

fair enough, did not see that part

grand snow
#

Yea its used with ugui but also works with 2d and 3d physics

#

ugui elements DO block the raycasts too which is usually a good thing too

#

as its all the same system, meaning no dumb work arounds checking "is cursor over ui element"

lilac fractal
#

What's the general vibe for those who want to use SOAP to reduce the dependencies of GameObjects to each other?

grand snow
#

Using events or interfaces or sub classes should solve this

lilac fractal
#

I'm struggling to do something like... I have a ProjectileController with a ProjectileHItboxBehavior on it, and an EnemyController with an EnemyMovementBehavior on it. Behaviors are children, controllers are the "root".

When a projectile collides with an enemy, it should raise an event that a collision occurred. Right now, this event exists on the EnemyController, so I have to have a behavior reference another controller, to invoke the event.

When the event is invoked on the EnemyController, and can then inform its behaviors (e.g. MovementBehavior, VisualBehavior, AudioBehavior) about the collision

#

This feels like a lot of knowledge sharing and boilerplate and I don't quite know a better way. It seems like it could "all be solved" if every involved party (ProjectileHitboxBehavior, EnemyMovementBehavior, EnemyVisualBehavior, etc..) could just reference the same event scriptable object.

grand snow
#

if you split things up too much you may be inventing the problem

lilac fractal
#

You think what I'm doing is somewhat overkill?

grand snow
#

maybe, if its not helping or providing benefit having things be separated soo much, why do it?

lilac fractal
#

I know it will

grand snow
#

A projectile probably will deal with collision so why does it need a seperate component to handle collision?

lilac fractal
#

The movement/physics in my game alone is quite a lot of code, I don't want to mix in audio, sprites, particles, etc..

#

Essentially what I'm trying to do is have a system of parent/children, where the parents orchestrate and the children get fed data

grand snow
#

Then its either manually made events, some event bus or explicit dependencies passed around

lilac fractal
#

That's why I think SOAP aligns with how I think

#

I can define an event as a first-class asset in my prefab to be invoked by others

valid violet
#

You can use public Action MyEvent; as field in any class and then asing it from any place

eternal needle
# lilac fractal That's why I think SOAP aligns with how I think

at first i was thinking you were talking about SOAP like the message protocol.
ive never seen a proper use for scriptable objects as events. it really doesnt provide you anything here other than just moving where the event happens from. You aren't reducing the dependencies, you're just hiding them

lilac fractal
#

Hah, no, I deal with wcf and SOAP enough at my job I have no intention of willingly touching it

#

Ultimately I just want to see if I can reduce my boilerplate and the fact that references to my root controllers need to be shared to trigger events

eternal needle
lilac fractal
#

And my children subscribe to the toot controller’s events

#

I’m not using scriptable objects yet, everything is a mono behavior

#

So I guess - assume for simplicity's sake that every gameobject look ssomething like -

FooController
  FooAudioBehavior
  FooVisualBehavior
  FooCollisionBehavior
  FooMovementBehavior
#

Everything here is a MB

eternal needle
#

then tbh i dont see what the problem is or how "it could all be solved if every involved party ... could just reference the same event scriptable object". Every object here can also just reference the FooController

lilac fractal
#

So if I want something like the ProjectileCollisionBehavior to be able to notify the EnemyController that it just hit, to say "hey mate you just got bumped, here's how hard"

#

e.g.

    public void OnCollide(ProjectileController projectile, GameObject target, Vector2 relativeVelocity)
    {
        if (target.TryGetComponent<EnemyController>(out var enemyController))
        {
            var direction = (projectile.transform.position - enemyController.transform.position).normalized;
            var velocity = relativeVelocity.magnitude;
            var pushForce = Mathf.Min(velocity * ForceMultiplier, MaxPushForce);

            enemyController.OnCollide.Invoke(direction * velocity * pushForce);
        }
    }
#

Now all of my behaviors in the EnemyController like audio, visual, movement, need to subscribe to the OnCollide event

#

The way I see it, it makes my behaviors dependent on their parent Controller, and it requires other components to resolve a reference to the Controller they want to notify

#

Maybe I'm overthinking it and that's just "okay"

#

Maybe I could define the OnCollide event at the root level of my Enemy prefab, and instead of resolving the controller, I can try to resolve ICollidable on the target of my collision

#

And then my enemy behaviors could subscribe to that, instead of it being on the controller.

eternal needle
# lilac fractal The way I see it, it makes my behaviors dependent on their parent Controller, an...

they are dependent because they depend on it existing. Think about it like this, would EnemyVisualBehavior or EnemyMovementBehavior ever exist without a EnemyController? your game probably would feel wrong if an enemy made no noise, so to some degree you also rely on every character having some kind of AudioBehaviour.
for that method above, idk where you would really be putting this. It doesnt make sense that a projectile would be hitting a target and then have to call that method above. The projectile should know its direction already and should try getting the enemy controller from the beginning to notify it was hit through calling a method. You ideally wouldnt be invoking a characters OnCollide method yourself, the character should do this by themselves

#

the only other concern id have would be that you have a projectile specifically trying to target an EnemyController rather than some base Character which can apply to your player as well. Right now you would need separate code for the same projectile to hit a player

eternal latch
#

Hey! Genuine question: Do ya'll write most of your code without tutorials? It's been so tough writing code on my own even when it came to writing a CharacterController movement script...

#

I've been struggling lol

#

I might be in "Tutorial Hell" but I've tried creating the simplest games on my own and just couldn't

ripe lotus
modest dust
#

But of course, start with !learn if you haven't done so already

eternal falconBOT
#

:teacher: Unity Learn ↗

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

ripe lotus
polar acorn
formal tide
#

Do you guys recommend any unity c# book

valid violet
#

and for Unity there is a lot learning material on Unity3d site and Documentation

formal tide
valid violet
#

it was free

formal tide
#

Every method that exists in unity

twin pivot
eternal falconBOT
#

:teacher: Unity Learn ↗

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

formal tide
#

Until the end

valid violet
twin pivot
formal tide
#

Well i guess i need to do examples because i wanted to do my own code and i couldnt

#

I wanna make my camera follow my ingame character(cube)

#

I couldnt do it

valid violet
#

Just google there lot of such examples or use ChatGPT it can give you examples too

formal tide
#

Do u guys have any recommendation how can i writr my own code and learn it rather than followin tutorials and copyng pasting

valid violet
#

chatGPT give simple code but for something complex it is shit

eternal falconBOT
#

:teacher: Unity Learn ↗

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

sour fulcrum
#

its shit for simple stuff

formal tide
formal tide
#

Im learning so slowly

twin pivot
#

What do you mean watch it again theres over 750 hours of content

valid violet
formal tide
#

First one

twin pivot
#

Rolling a ball isnt the only thing there is

formal tide
#

Yea that one

#

And car

formal tide
#

The thing is im learning veery slow. Everyone said i can learn basics in 2 weeks. I spent 2 months for basics and not fimishrd

#

Finished

#

Is this normal

valid violet
#

You can spend years to start writing good code

formal tide
#

Yea

valid violet
#

and you can create somthing by following the tutorial and modify it in a months

formal tide
twin pivot
#

And also stop using ai for this

valid violet
#

When I started I watched only video tutorials I was able to create feachures I need for my games by just googling and add feature by feature to my game. If you start developing you should also google Scriptable Objects it is not oblivious Unity3d feature but useful

formal tide
#

I tried to write wasd controls and space for jump code. It works but i guess i wrote it too long

#

Is this good code or too long

rich ice
twin pivot
formal tide
valid violet
#

Yes you should start your own game and finish the prototype

valid violet
#

I usually use if (Input.GetKeyDown(KeyCode.A)) { } your mthod I see first time

formal tide
#

I should check what all that means

valid violet
#

You can also read the Unity3d tutorials there lot of things you can learn

formal tide
valid violet
#

honestly for me the old looks better 🙂 because u have class with all KeyCode, but it is okay to use any that works

rich ice
#

yeah the old input system is probably better for beginners. the new input just makes things like adding controller support easier (afaik atleast)

manic blade
#

Can someone help me i watch one video and i wrote the code for moving left and right but my player does not move but does not show me any kind of error

rich ice
#

!code

eternal falconBOT
rich ice
manic blade
#

Yes

valid violet
#

@manic blade You need to do Input.GetAxis("Horizontal") * Speed and check the Speed value that will move fine for you

#

I do not remember try 10f if to slow try 1000f

manic blade
#

I did that i put 100 still didn't move

rich ice
#

the script looks fine to me. the only issue i can think of is that it just isn't attached

manic blade
#

I can send you an picture it is attached

rich ice
#

sure CloverThumbsUp

#

could tell us a bit more about the scene aswell

manic blade
valid violet
#

speed is not needed

#

it is working fine without speed

rich ice
#

-# sidenote: use screenshots instead of another device. makes the image more clear

manic blade
rich ice
# manic blade

everything looks correct. you definitely entered playmode and then pressed A,D or the two arrow inputs

manic blade
#

yes

rich ice
#

oh

#

i think i spotted the error

rich ice
rich ice
#

if it's not that, im officially out of ideas guh

formal tide
# manic blade

In unity project settings from top left then player settings find activated input settings or whatever that called. I changed that to"both" And it worked. I had the same issue but idk if its same issue for u. Maybe u can try

manic blade
#

that was an old screenshot i fixed that

formal tide
#

Alright

valid violet
#

I recreated the logic it is working fine

rich ice
formal tide
#

here i changed this to both now both input system works

manic blade
formal tide
manic blade
#

no

formal tide
#

I would try that to see what is the issue

wise cairn
#

ok so i'm making a 2d side scrolling game and just working on basic movement, how should i move the player? i already have all my code calculating how much to move and rb.position += movement * Time.fixedDeltaTime was working, but apparently i shouldn't do that because it ignores physics? what do i do instead?

rich ice
# manic blade

why does the collider have a scale of 5.12? assuming that's the default square sprite, a scale of 1 on the collider should just automatically scale correctly with the object

rich ice
# wise cairn ok so i'm making a 2d side scrolling game and just working on basic movement, ho...

take a look at this video

DeltaTime. This video is all about that mysterious variable that oh so many game developers seem to struggle with. How to use DeltaTime correclty? I got the answers and hope this video will help to deepen your understanding about how to make frame rate independent video games.

0:00 - Intro
0:34 - Creating The Illusion of Motion
1:11 - Simple Li...

▶ Play video
wise cairn
#

ok thanks

rich ice
#

oh wait no

#

sorry my bad

formal tide
# manic blade

Also did u see that Awake() method? Can u change that to Start() Im beginner but i guess that method is not neccedary there

valid violet
#

Did you press the Play button to enter play mode before move object xD?

rich ice
rich ice
rich ice
formal tide
#

Hmm i never saw it thank u

manic blade
#

i can send an video because i don't know what to do

valid violet
#

delete the player create new one add The Sprite the Rigidbody2D then add the Playermovement hit play and try agian:)

manic blade
#

i will try if it dont work im gonna start some other way

rocky canyon
#

its actually better to have the graphics as a child gameobject

valid violet
#

@manic blade Rename script form playermovement to Playermovement

rocky canyon
#
  • Player - rigidbody, collider
    • graphics - sprite

but ya.. something like that

valid violet
#

Your script playermovement.cs it should have same name as inside script

rich adder
#

no longer is that a requirement

#

but yes its good practice to do so

rocky canyon
#

lol.. it angers me that my classes and scripts no longer have to match

rich adder
#

script.cs
public class PlayerMovement : MonoBehaviour

#

😆

valid violet
#

try to rename this one maybe will work in older unity it should match

rich adder
#

they are using Unity6 , that doesn't matter rn

#

what they should do though is not have the Console tab/window hidden

#

sum like this

manic blade
rich adder
#

put logs inside the script and see if thats running at all

manic blade
rich adder
# manic blade

you put logs inside update ? check the console after doing so, press some keys etc.

manic blade
#

how do i do that

rich adder
#

should've been the first piece of code you should've learned

valid violet
#

Debut.Log(Input.GetAxis("Horizontal"));

rich adder
#

better yet store it inside a variable

#

float horizontalMove = Input.GetAxis("Horizontal");
Debug.Log($"input value {horizontalMove}");

valid violet
#

when you press <- -> or A D it should log 1 or -1 if it log 0 mean input does not working

manic blade
valid violet
#

inside Update

valid violet
manic blade
#

like diss

rich adder
#

jesus..

rich adder
#

that tells the computer , this is the end of a line of code

manic blade
#

i forgot

polar acorn
#

If you won't even understand how to implement any advice you get here it's going to be hard to get any advice here

manic blade
rich adder
#

until the next problem

polar acorn
manic blade
#

thanks for trying to help i am going to learn more than try to make an game

tulip relic
#

How do you detect when a button is released with the input system?

rich adder
valid violet
#

@tulip relic In old Input.GetKeyUp

tulip relic
tulip relic
#

Also, my PlayerInput is created at runtime without a prefab, so I'm not sure how to assign UnityEvents to it

rich adder
#

wdym "PlayerInput is created at runtime without a prefab"

tulip relic
rich adder
#

if you're using the PlayerInput are you using SendMessages mode?

tulip relic
#

I believe so

rich adder
#

I usually use events, you can probably just check
inputValue.isPressed is false in the method for the action

tulip relic
rich adder
tulip relic
#

What is the name of the function

rich adder
tulip relic
rich adder
tulip relic
rich adder
#

pretty sure it gets called on both

tulip relic
#

It doesn't

#

I'm looking at it right now

rich adder
#

whenever I used it, it always called the method twice, once on pressed/held and once more released

tulip relic
#

I used

    public void OnAttack(InputValue inputValue)
    {
        print(inputValue.isPressed);
    }

and it only prints True

rich adder
#

you might have to switch the action mode then

tulip relic
#

Where and to what

rich adder
tulip relic
rich adder
tulip relic
valid violet
#

isnt it action.started += context => Debug.Log($"{context.action} started"); action.performed += context => Debug.Log($"{context.action} performed"); action.canceled += context => Debug.Log($"{context.action} canceled");

tulip relic
valid violet
#

InputAction class

#

like this var action = InputSystem.actions.FindAction("Move"); as I understand and action.canceled //triger when button Up

rich adder
rich adder
tulip relic
rich adder
#

it should give you the secondary event of released

rocky canyon
tulip relic
rich adder
#

actually for button iirc you can also add the Interactions for release

rocky canyon
#

you can also set up Interactions per action

rich adder
#

I was just sending that and you beat me to it @rocky canyon 😁

rocky canyon
#

💪 i just happen to have it open..

#

still dippin my toe in.. but darn is this thing universal af

rich adder
#

so many options 😵‍💫

rocky canyon
#

i know.. its quite overwhelming if im being honest

#

been practicing with just a couple of buttons only

valid violet
#

The new input system looks so heavy, not sure it is worth to use it.

rocky canyon
#

clear it out and start fresh.. and its not soo bad anymore

rich adder
#

technically new input can be just as straight forward if using traditional polling

rocky canyon
#

after a bit of fiddling i got a decent little system set up ^

#

and if u want.. u can still poll for inputs with it..

rich adder
#
Update(){
  if(Keyboard.current.spaceKey.wasPressedThisFrame)
        {
            // input.getKeyDown
        }```
rocky canyon
#

ezpz 🍋 squeezie

#

im still a bit intimidated by the axis' inputs but it'll be fine

#

"composites" rather

valid violet
#

Okay maybe worth for action pc games. And not worth for mobile games (custom control usually).

rich adder
#

you would need to code those manually with the old input

#

slowtap, multi-tap etc.

#

it also supports a variety of controllers and input devices

valid violet
#

Yes, I used to setup mobile input manually and it wasn't hard? So new input is easier to do such operations?

rich adder
#

In my opinion yes, and I used old input for years before taking the plunge and never looking back

#

it can be overwhelming because so many ways to do something in it

#

once you wrap your head around all the features you will pretty much love it

valid violet
#

For example won't u need to use native mobile control if you develop swipe combat system I think it won't be available for default in new input

rich adder
#

swipe is done the same way you do it with the old input system, track the magnitude between 1 point to another

#

many ways to get events such as TouchStart etc.

valid violet
#

So this is point I do not need any additional knowledges to create any mobile control I need, but I will need to study a lot to implement new input for mobile game, and I will need to know how to use native mobile input even if I use new input.

swift elbow
#

is there a way to negate the destruction of an object in OnDestroy() (or in a different built-in method)?

#

i ask this under the assumption that OnDestroy() triggers before the object is actually destroyed

rich ice
#

you could store an instance of an object and then instantiate that instance when it get's destroyed

#

i think i remember something about this causing issues though. so i'd avoid doing that if you can.

swift elbow
rich ice
#

oh good point, that would work with prefabs but not individual instances.

#

i think so atleast, might have to test that myself

#

if you dont mind me asking, why are you trying to do this anyway?

swift elbow
#

it was just a random thought that intrigued me. i dont really need this for anything

wise cairn
rich ice
eternal needle
wise cairn
swift elbow
rich ice
wise cairn
rich adder
wise cairn
#

yeah but the whole thing they were saying is to not set it

rich ice
rich ice
wise cairn
#

ok so still how should i move the object? adding to linearVelocity just makes it add up and move obscenely fast

rich ice
#

depends on what you're going for. honestly im not the best at this myself. but i think most people usually add to linearVelocity and then cap it on the required axis

wise cairn
#

rb.linearVelocity += movement; is what i was doing

rich adder
wise cairn
#

im trying to move the object by movement every frame

rich ice
#

i believe you would want something like this

if (Mathf.Abs(rb.linearVelocityX) < maxSpeed)
    rb.AddForce(movement);
rich adder
wise cairn
#

yes i'm aware that's why i'm asking what to do

rich adder
wise cairn
#

then we're back to the issue of overriding gravity though

#

i'll just do the above solution

rich adder
wise cairn
#

ok

rich adder
#

if 3d
rb.linearVelocity = new Vector3(horizontalMove, rb.linearVelocity.y, verticalMove)
or
Vector3 velocity = rb.linearVelocity ; velocity.x = horizontalMove; rb.linearVelocity = velocity;

#

if you're on 2D you can simply assign rb.linearVelocityX = horizontal

wise cairn
#

ok thanks

queen adder
#

Is it better to add RigidBody to the sprite rather than creating an object separately for it?

sour fulcrum
#

"it depends" but usually you'd actually wanna do the oppisite and have your visuals exist under the logic

sour fulcrum
#

Well usually the "logic" that actually does stuff like a rigidbody would be the parent

#

and as the visuals are kinda a "reaction" to that logic, they would be parented under the logic as a child

queen adder
eager spindle
#

Player gameobject has Rigidbody2D, ,Collider2D, PlayerMovement
Child GameObject has Sprite Renderer

Depending on your games structure you can also choose to put your Collider2D in the child gameobject

daring sentinel
#

Quick question but with unity timeline, is it possible to mute and unmute track groups via scripting. Pretty much I'm just sorting the dialogue for my game where I have the audio and text in separate track groups, and want to mute and unmute specific track groups, that contain different audio clips in the timeline - depending on the player's dialogue option selected.

#

I've been looking at the API and I'm so confused

sharp bloom
#

I mean having your Mesh Renderer on child object

eager spindle
daring sentinel
# eager spindle Yep

Hey sorry, if you're not too busy, would you mind answering my question?

What I'm confused about is how to go about muting and unmuting track groups via scripting, like I know that trackasset refers to tracks in timeline but I was looking on unity forums and they have code going on about timelineasset, but TrackAsset doesn't look like it inherits from TimeLineAsset in Unity's API?

eager spindle
#

to clarify this is about audio right?

#

hmm i havent come across this track groups yet

#

both TrackAsset and TimelineAsset inherit from PlayableAsset

#

It looks like muted can be set

#

set this to true

nimble apex
#

sry i got a little brainrotten now atwhatcost

currently i have a lobby UI , the UI will list out available rooms, because there will be many rooms, i had pooled the UI elements that display the room info , with unity iobjectpool

i have an option for players to display the amount of room info that they want , by 50/60/70/80/90/100 at a time , lets call it int maxQuery

one way the lobby UI works, is to clean out all existing element UI when player change their "maxQuery"

so , for cleaning the element UI , which is better

PoolManager.Instance.Clear(ObjectPoolType.SessionDetail);
AllRoomsAvailable.Clear();```

```cs
            foreach (GameObject element in AllElement)
            {
                PoolManager.Instance.Release();
            }```
#

or i dont need to clean out the maxQuery?

eager spindle
nimble apex
#

ty 👍

daring sentinel
# eager spindle to clarify this is about audio right?

So what I was trying to do was that I have the control and audio tracks in a group to represent each 'chunk' of the script. What I was trying to do was mute and unmute each of these groups through a script, depending on the player's option chosen, if that makes sense.

What I'm really struggling with is trying to understand how I need to access the tracks to mute them.

Let me know if I need to be more clear, soz.

#

At the moment I'm just trying to have it work with one dialogue option, because then I can just put it altogether after this and actually start building the game

#

I was thinking of doing it this way because if I have 3 choices per scene then I can just unmute and mute the groups accordingly.

shut flame
#

hello

#

so i wanted to handle input

#

and although following the documentation

#

it used an outdated method

#

is there any source that uses the new input method

#

preferably a website or in text format

eager spindle
#

input system?

shut flame
#

yes

shut flame
#

oh thanks

#

was using this

eager spindle
#

if you want to learn about input system youll need to look for that keyword specifically

shut flame
#

oh

#

thanks

queen adder
rocky canyon
#

the top if statements run.. thats fine.. (but then hwen u get down to crouching input it also runs... same frame..

#

so if ur not crouching.. its gonna go right back to 5,5,5

#

doesn't matter what ur horizontal input is

#

could do something like

if (horizontalInput > 0.01f)
    facingDirection = 1f;
else if (horizontalInput < -0.01f)
    facingDirection = -1f;```

and then use facing direction multiplied w/ ur X scale in the crouch method
#

or.. do all ur inputs together in a set of if elses

frigid sequoia
#

Hey, can I not get to see this list on the editor and add elements to it???

#

I was hoping I could

slender nymph
#

StatAttribute must be serializable

frigid sequoia
#

Like the class?

#

How do I declare that?

queen adder
queen adder
#

or is it?

rocky canyon
#

b/c its overwriting the X

#

ur horizontal makes it 5 or -5..

#

but then ur crouch overwrites it right back to 5

#

see both conditions are 5

#

soo.. it really doesnt matter what ur horizontal sets it to.. b/c u just overwrite it back to 5 anyway..

naive pawn
#

both the flip and crouch should probably just be modifying the relevant part instead of overwriting the whole thing

rocky canyon
#

true.. thats another option ^

#

new Vector3(transform.localScale.x, 5, 5);

#

or new Vector3(transform.localScale.x, 2.2, 5); for the other condition

#

the entire Update() runs in a single frame.. (all the code).. u cant set 1 thing at the top.. and then something different at the bottom.. and expect it to show different results

#

if u walk thru ur code one step at a time you'll understand the issue...
pretend ur pressing Left and Crouching at teh same time.. then write down what the X of the local scale ends up as.. and what it should end up as

nimble apex
#
    public GameObject Get(ObjectPoolType poolType, Transform parent)
    {
        GameObject obj = AllObjectPools[poolType].Instance.Get();
        obj.transform.SetParent(parent,false);
        
        return obj;
    }```
```cs
public void Clear(ObjectPoolType poolType) => AllObjectPools[poolType].Instance.Clear();```

this is the get and clear function of my pool , somehow the clear function is not working tho
#

it can get object properly

#

release is also working

naive pawn
#

wdym by "not working"

nimble apex
#

when i call the "clear" function, all the object that spawned from the object pool should be released or destroyed right?

#

but its not

#

wait

#

yep its not clearing

wintry quarry
#

it just makes the objects not associated with the pool anymore

nimble apex
#

ohhhh

wintry quarry
#

Although I do think it should run your actionOnDestroy if you provided one when you constructed the pool

#

did you?

nimble apex
#
private GameObject CreatePoolObj() => Instantiate(Prefab);

    private void OnGetPoolObj(GameObject poolObj) => poolObj.gameObject.SetActive(true);

    private void OnReturnPoolObj(GameObject poolObj) => poolObj.gameObject.SetActive(false);

    private void OnDestroyPoolObj(GameObject poolObj) => Destroy(poolObj);```
wintry quarry
#

what about the line where you create the pool?

nimble apex
#

i do have the basic 4 functions

#
    public IObjectPool<GameObject> Instance
    {
        get
        {
            if (constructedInstance == null)
            {
                constructedInstance = new ObjectPool<GameObject>(CreatePoolObj, OnGetPoolObj, OnReturnPoolObj, OnDestroyPoolObj, checkPool, DefaultPoolSize, MaxPoolSize);
            }

            return constructedInstance;
        }
    }```
naive pawn
#

what's with the .gameObject lol

#

leftover code?

wintry quarry
nimble apex
#

so the code are very different

nimble apex
#

!code

eternal falconBOT
nimble apex
#

the get function is working

#

also the filter are properly populated

nimble apex
#
        foreach (SessionDetail element in AllRoomsAvailable)
        {
            PoolManager.Instance.Release(ObjectPoolType.SessionDetail, element.gameObject);
        }```

i just gonna loop over the gameobject instead...
#

it does work this way tho

eternal moat
#

guys am new to this can anyone tell me what should i do to learn about coding i wanna get to a professionel level to create my own game with my friends

#

any tips?

eternal falconBOT
#

:teacher: Unity Learn ↗

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

eternal moat
#

is it all i need?

naive pawn
#

no

#

also see pinned resources in this channel

#

and docs, google, the forum will be very helpful as well

eternal moat
#

alright thank you

formal tide
#

Guys. Should i keep continue writing in same c# file in unity or should i create another one? For exampld i made jumping mechanic for my character i gave it 2 jumping limit until it hits ground collision now i will code character WASD movement. Im not sure if i should continue from same c# file or create another

nimble apex
#

do iobjectpool has methods that can return all existing/active objects that it instantiated and not yet disposed(destroyed)?

#

not including released(inactive) objects

polar acorn
formal tide
slender nymph
eternal falconBOT
slender nymph
#

yes, i am aware.

formal tide
#

Is there a limit inside update

#

Im trying to learn thank u for info

#

I will researxh

slender nymph
formal tide
polar acorn
#

Fix... what

slender nymph
#

i don't even know what you are asking, hence the reason i asked for clarification . . .

formal tide
#

Is there any issue on my code so i can fix it

#

Or is it fine

slender nymph
#

i mean, it's currently fine, but if you don't know how to include multiple lines inside the scope of an if statement, perhaps start by learning the basics of c#. there are beginner courses pinned in this channel

polar acorn
formal tide
slender nymph
hallow acorn
#

break goes out of the current "if", "for" etc right? so if i have 2 stacked ifs and i write "break;" in the inner one it would go back to the outer if?

slender nymph
#

yes

formal tide
#

Thanks

slender nymph
#

c# is not python. white space does not matter, just because that last line is at the same indentation as the one before it does not mean it is in the same scope

naive pawn
#

it seems like this is something you've discovered but not understood, given the duplicate condition

formal tide
#

Thank u.

naive pawn
#

you should probably go through some beginner c# resources, there are some pinned in this channel

formal tide
#

Its good to see my mistakes and see what should i study again

#

!code

eternal falconBOT
formal tide
#

I will use one of these next time i post my code

raven yew
#

Hi!
I don't know if this is more beginner code or not but I need help with a code snippet that make's a lot of sense in my head but is not working for some reason.
I'm trying to use the new input system to make my character sprint, but it is isn't sprinting. Help pls
https://paste.mod.gg/bjccxwwhtidw/0

keen dew
#

You don't do anything with m_speedWhileSprinting

raven yew
#

oh wow, embarrassing. ty

vapid mesa
#

hello guys, i try to code a 2d Top down view game and my kinematic character go througt object and d'ont car about it, thank you so much if someone can help me !!

wintry quarry
#

working as expected

vapid mesa
#

how i can do collision to dont allow going througt

wintry quarry
#

make it dynamic

#

and set the velocity instead of using MovePosition

vapid mesa
#

pls

wintry quarry
#

what part are you confused by

vapid mesa
#

i dont understand what i need to change else of kinematic to dynamic

wintry quarry
#

Change your code so it sets the Rigidbody's linearVelocity instead of calling MovePosition

vapid mesa
#

i change this so ?
movement.x = Input.GetAxisRaw("Horizontal"); // -1, 0 ou 1
movement.y = Input.GetAxisRaw("Vertical"); // -1, 0 ou 1
movement.Normalize();

wintry quarry
#

nothing there needs to change

#

You need to change the MovePosition part

vapid mesa
#

okayyy

#

this
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);

wintry quarry
#

rb.linearVelocity = movement * movespeed;

vapid mesa
#

thksss

#

it say as if linearvelocity doesn't exist

rich adder
wintry quarry
vapid mesa
#

most recent version of unity are better ?

#

i'm pretty sure there is something else wrong but since yesterday i can't find it

#

it doesn't work with dynamic

rich adder