#💻┃code-beginner

1 messages · Page 565 of 1

whole cliff
#

now it works

#

i finally have a somewhat working game

obtuse quarry
#

my project isnt broken but

#

is this a problem?

teal viper
obtuse quarry
#

ya

#

everythign still works

#

just wondering if its anything to worry about

teal viper
#

As long as it doesn't appear frequently enough, it should be fine. Probably an editor bug.
Maybe note what you did for it to appear next time you see it.

obtuse quarry
#

okay

#

thanks

echo kite
#

how do i add weapon sway?

#

i did google it

night raptor
echo kite
#

and just copying makes it red lined

night raptor
echo kite
#

and idk where to put

#

top one is video

frail hawk
#

you mean a knockback or

echo kite
pine cedar
#

@echo kite Is this first person weapon sway or something?

echo kite
#

yes

pine cedar
#

You should do something using Mathf.Sin or Mathf.Cos where while moving you have a timer variable which counts up.

#

Something like Weapon.transform.localPosition.x = new Vector3( Mathf.Cos( time ), 0, 0);

#

The idea is you utilize the undulating behavior of the sin/cosine functions to get the back and forth sway you're looking for.

#

In your update function you'd want to count time:

echo kite
#

like this?

pine cedar
#
Update(){
time += Time.delaTime;
}
#

If you have time moving and you pass this into Mathf.Sin() you will get the undulating behavior you're looking for.

#

I can't see anything in that screenshot.

echo kite
#

transform.localPosition += (Vector3)mouseAxis * weaponSwayAmount / 1000;

pine cedar
#

I don't know what weaponSwayAmount will be affected by.

#

Atm that's just going to add a local position offset to the weapon, but if weaponSwayAmount keeps growing you just end up with your weapon moving off in some linear direction.

#

This is a sine wave, it undulates from 1 to -1

#

When you call Mathf.Sin( time ) you can get an undulating value you can use for a swaying motion.

#

You can then do something like:

transform.localPosition = new Vector3( Mathf.Sin( swayTime ), 0, 0 );

#

This moves the weapon object back and forth on the local X axis.

#

You can also have a constant multiplier in there to control the sway distance.

#

You can then do something like:

transform.localPosition = new Vector3( Mathf.Sin( swayTime ) * _myConstantSway, 0, 0 );

#

In the Update() method you can accumulate time into the variable

#
void Update(){
  swayTime += Time.deltaTime;
}
#

Play around with this

#

You should get something of use

echo kite
# pine cedar You should get something of use
      
        characterController.Move(moveDirection * Time.deltaTime);
        if (canMove)
        {
            rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
            rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
            playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
            transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0);
        }
        ApplyWeaponSway();
    }

    private void ApplyWeaponSway()
    {
        swayTime += Time.deltaTime * swayFrequency;
        float swayOffset = Mathf.Sin(swayTime) * swayAmplitude;
        playerCamera.transform.localPosition = initialCameraPosition + new Vector3(swayOffset, swayOffset, 0);
    }
}

i tried this no errors but it doesnt work

pine cedar
#

your swayAmplitude and swayFrequency values are sensible?

#
playerCamera.transform.localPosition = initialCameraPosition + new Vector3(swayOffset, swayOffset, 0);

You're applying swayOffset to X and y equally. That will have the camera moving diagonally.

#

You'd have to have a different mathematical function running for X and Y independant of one another (only dependant on time) to get the effect you're looking for.

#

You'd have to describe what you mean by "doesn't work" more.

echo ruin
#

If I attach two or more CircleCollider2D to an object, how would I differenciate between them in the script?

naive pawn
#

position? size? trigger? etc
use that to differentiate them

echo ruin
naive pawn
#

but if they need to be differentiated you probably should just not have them on the same object

naive pawn
echo ruin
#

Yeah.

naive pawn
#

then you might want to just have them on separate objects, yeah

echo ruin
#

Put then in child objects and then just reference them by object name?

naive pawn
#

or if you're using messages, you could setup layer overrides on each, and then you could differentiate what to do based on which one was hit, but idk if that'd work for your usecase

naive pawn
echo ruin
#

Like an example would be an enemy that has a radius for chasing range, one for checking long range ability range, one for short range ability range

pine cedar
#

This will tell you what collider was involved here.

#

And thus you will know based on that information.

echo ruin
#

I’ll check it out

pine cedar
#

👍

echo ruin
#

I’m thinking it would be possible to add colliders as an array in the script and have them referenced by the index?

#

Might make it slighly less readable though?

pine cedar
#

It very much depends on your usage.

echo ruin
#

True.

pine cedar
#

You'd have to specify what you mean by "differentiating"

naive pawn
pine cedar
#

Is it? I see

#

True

echo ruin
pine cedar
#

So if that script is on the trigger object

#

You will know it is this trigger

#

That was mostly my thinking

#

Chris, do you agree?

echo ruin
#

Yeah, but if I have more than one trigger on the same object..

pine cedar
#

I'd put the script on each trigger

#

Then I would have it talk to the root object

echo ruin
#

So.. using child objects for each trigger?

naive pawn
pine cedar
#

Root
Trigger(script)
Trigger(script)
...

naive pawn
#

i don't think the "communicate back to parent" part is super ideal

pine cedar
naive pawn
#

i guess it would work though

final gazelle
pine cedar
naive pawn
pine cedar
#

I do this sort of thing often enough

pine cedar
echo ruin
#

This would be much easier if Unity just let us rename components? ChaseTrigger and WithinRangeTrigger

pine cedar
#

Was tryign to reply to the other guy

#

mb

naive pawn
final gazelle
naive pawn
#

oh also there's another approach if the enemies just have to track the player, just check what distance the player is from the enemy

pine cedar
#

That's effectively the same as just attaching a trigger listener script as I mentioned.

#

Listening for OnTriggerEnter

echo ruin
naive pawn
pine cedar
#

I would have a script on each trigger which just notifies the parent (a script on the parent. "Unit" script, or whatever) that it's involved in a trigger event

#

The parent ("Unit" or whatever) would do the tracking of add/remove based on listener calls.

#

This gives you the involved trigger, and the necessary trigger enter/trigger exit events.

final gazelle
#

having a manager script is a game changer

pine cedar
#

It's not a manager, but it's the root of the responsibility chain here.

#

The Unit wants to know what trigger events happen.

#

The triggers provide the specifics of each interactions.

#

I've done this exact sort of thing before in various circumstances.

#

It works well enough, soon enough you forget about the underlying implementation 😛

final gazelle
#

i mean in a way it acts as a manager

pine cedar
#

Agreed

willow shoal
#

can some one give me script for a off second script in inspector?

#

one line of code i need

swift elbow
willow shoal
#

i meen script for off/on in scene

#

by script

naive pawn
#

yeah no clue what you actually need

willow shoal
#

second

naive pawn
#

what is "off/on" here?

#

a gameobject being active?

willow shoal
#

yes

naive pawn
#

then just do that

#

SetActive(true) or SetActive(false)

whole cliff
#

how do i fix the errors

#

what is scm

naive pawn
willow shoal
#

lightSource = GetComponent<Light>(); ? what change

naive pawn
#

what change for what?

willow shoal
#

and then i know lightSource.enabled = !lightSource.enabled;

#

but for script

#

not light

#

i found this

#

but i need close in inspector script my second

naive pawn
#

scripts are components, you can enable and disable them as well

willow shoal
#
script = GetComponent("secondscript")();

```like this?
naive pawn
#

no, that's now how you call GetComponent

pine cedar
#

var myScript = GetComponent<SecondScript>()
or
var myScript = GetComponent( typeof( SomeScriptType ) )
or
var myScript = GetComponent( typeof( SomeScriptType ).Name )
or
var myScript = GetComponent( "ValidTypeName" )

willow shoal
#

ok

lilac plinth
#

hi, is this the expected result?

lilac plinth
#

it seems like some components were gone after i save and run the script

#

I'll send the script below

naive pawn
pine cedar
naive pawn
lilac plinth
pine cedar
#

They're valid based on the documentation and some cases they are useful either way.

lilac plinth
pine cedar
#

My preference is the generic implementation

lilac plinth
#

i remember i had 2 components

naive pawn
lilac plinth
#

now it's gone from the sphere

pine cedar
#

GetComponent<TComponentType>() <- my preference

lilac plinth
#

1 is rigid body

pine cedar
#

None of them are fragile other than the string argument version

#

The others are all based off of type arguments

#

I'm not arguing for them, but they aren't fragile.

lilac plinth
#

other is player input component

naive pawn
#

the generic one, is... generic, so it returns the type given
the others are not generic, and return Component
so you need to cast that
and now if you ever need to change what component you get, you won't get warned about type mismatches since there's technically no compiletime mismatch

pine cedar
#

That's fair. Anyway, I was just quoting the documentation.

naive pawn
pine cedar
#

typeof generates the type

naive pawn
#

not really, no

pine cedar
#

It's a argument of type Type.

naive pawn
#

and that isn't a type argument

pine cedar
#

Anyway, off topic from the OP.

#

As Chris said the preferred method is the generic method.

#

But those are your methods for getting a component from the object.

naive pawn
#

the generic one is generally going to be the only useful one
if you ever need to use the others, that's a sign you've gone down the wrong path, and you have pain inbound

pine cedar
#

I think that's a different discussion.

naive pawn
#

there's not much to discuss there, that's just how it is

lilac plinth
#

the player doesn't move

pine cedar
#

I've used those other methods in situations where the type is derived from an attribute and not where the generic method can be used.

#

prefer what you prefer.

naive pawn
lilac plinth
#

and yeah gone from all modes

#

I've remade them quickly

#

but still

#

i still cant control the player

#

is that what the script intended to do?

#

i dont have error log anymore, but it's not the proper result I think

#

since the player is supposed to move

naive pawn
#

have you setup your input actions

lilac plinth
#

apply input data to the player?

#

yes?

#

would like to see the script?

teal viper
eternal falconBOT
frank flare
#

I'm making a car for my game and it seems like w and s work too slow and probably broken. I tried modifying some values but still no result

I'm copying this tutorial: https://www.youtube.com/watch?v=CdPYlj5uZeI

CarController: https://paste.ofcode.org/32Aw6yCVr5P7PCtu6B3DsPu

A detailed look at how we made our custom raycast-based car physics in Unity for our game Very Very Valet - available for Nintendo Switch, PS5, and Steam.
BUY NOW!! https://toyful.games/vvv-buy

~ More from Toyful Games ~

▶ Play video
naive pawn
#

have you set up your player input

#

have you assigned the player actions

frank flare
pine cedar
frank flare
#

well, I copied it from youtube

#

I'm trying to have similar car like in the video
or I don't get what you mean

pine cedar
#

Unless someone dives into that video/code base you're going to have a hard time getting assistance.

frank flare
pine cedar
#

I think you'd have to break it down based on the code involved.

#

And hope someone can see something.

languid spire
#

also !code

eternal falconBOT
frank flare
frank flare
west garnet
#

how can i make a script for when the user press either "a" or "d" to move either left or right? i cant seem to make it work

swift elbow
swift elbow
#

and what exactly isnt working? are you not noticing any changes?

west garnet
swift elbow
#

and how did you debug that it wasnt working

swift elbow
west garnet
swift elbow
west garnet
swift elbow
west garnet
swift elbow
swift elbow
west garnet
weak tusk
#

hey, is it possible to create a 3D game, which will have a phone with a 2D game?

#

something familiar to screenbound

keen dew
#

yes

weak tusk
#

okay, now im wondering which project type should i choose for such game

#

is it a normal universal 3d?

foggy yoke
#

I have this code. It works just fine, except the enemies don't spawn at the position of the enemySpawn object. Why is that?

using System;
using UnityEngine;

public class Enemy : MonoBehaviour
{
    public Transform enemySpawn;
    public Collider2D playerEnemySpawn;
    public GameObject player;
    public Collider2D playerCollider;
    public GameObject enemy;
    public int numberOfMaxEnemyThatSpawns = 3;

    private int spawnedEnemies = 0;
    private bool hasSpawned = false;

    private void Update()
    {
        if (Physics2D.IsTouching(playerCollider, playerEnemySpawn) && !hasSpawned)
        {
            Debug.Log("Spawning enemies...");

            for (int i = 0; i < numberOfMaxEnemyThatSpawns; i++)
            {
                GameObject newEnemy = Instantiate(enemy, enemySpawn.position, enemySpawn.rotation);
                newEnemy.transform.SetParent(enemySpawn);
                spawnedEnemies++;
            }

            hasSpawned = true;
        }
    }
}
wintry quarry
#

Anyway when you do SetParent it will move the object. Why are you doing a separate SetParent call?

foggy yoke
#

I thought it would move it to the position of the object

wintry quarry
#

You can just do Instantiate(enemy, enemySpawn.position, enemySpawn.rotation, enemySpawn);

foggy yoke
wintry quarry
#

You don't need a second call

foggy yoke
#

okay. thanks

wintry quarry
foggy yoke
#

Okay, will do.

keen dew
weak tusk
#

ohh okay thanks

covert flower
#

im struggling to find what i need to do to get this text to show my 2 Ints. i know where to put the code just not what i need

wintry quarry
foggy yoke
# wintry quarry You can just do `Instantiate(enemy, enemySpawn.position, enemySpawn.rotation, en...

Didn't fix it.

using System;
using UnityEngine;

public class EnemySpawner : MonoBehaviour
{
    public Transform enemySpawn;
    public Collider2D playerEnemySpawn;
    public GameObject player;
    public Collider2D playerCollider;
    public GameObject enemy;
    public int numberOfMaxEnemyThatSpawns = 3;

    private int spawnedEnemies = 0;
    private bool hasSpawned = false;

    private void Update()
    {
        if (Physics2D.IsTouching(playerCollider, playerEnemySpawn) && !hasSpawned)
        {
            Debug.Log("Spawning enemies...");

            for (int i = 0; i < numberOfMaxEnemyThatSpawns; i++)
            {
                Instantiate(enemy, enemySpawn.position, enemySpawn.rotation, enemySpawn);
                spawnedEnemies++;
            }

            hasSpawned = true;
        }
    }
}```
frail hawk
#

reset your enemySpawn Transform maybe

#

there might be some offset

foggy yoke
leaden pasture
frail hawk
#

use a standart sprite from unity, i assume there is somethign with your sprite, maybe it is just not centered or has whitespace

foggy yoke
leaden pasture
#

Is the sprite a child of the prefab root or is it the actual root itself?

leaden pasture
#

Is it positioned at the same position as the root in that case? If it's anywhat offset from the prefab root, it will be offset from wherever you move the prefab to after it's spawned in

foggy yoke
#

I fixed it. It was offset. Thank you guys for the help.

frank flare
verbal dome
#

No.

frank flare
#

maybe

rich adder
#

close but why rotation?

frank flare
#

oh I thought it's camera lol like doom
read it wrong

rich adder
#

they said Move not rotate

fluid ferry
#

can somebody help me with importing my player model

#

it broke my game

ivory pollen
#

To clarify: you're saying that you have an empty object in the scene which has references to the models / weapons for the different characters?

ivory pollen
grand snow
#

and wrong chat

fluid ferry
#

i made a player in blender and imported it then i deleted the previous cylinder and i put the camera in its head and no matter how i position it its always looking to the right

#

hes tposing rn and all you can see is his right arm

ivory pollen
#

sounds like you need to rotate the camera?

short hazel
ivory pollen
#

@queen adder kinda tough to understand what you've got and what you're trying to accomplish, sorry. You have 4 objects in the scene with sphere colliders, each one has a reference to a model in the project, and you're trying to figure out how to put the objects in an array or something...?

#

Ah, right

muted pawn
#

Hey everyone :) Can someone help me with my code/unity??

The Dashing doesnt seem to work cuz when I start the game I checked in the inspector the speed and dashingPower variables and they dont seem to change + I get the error that the referenced script on this behavior is missing

https://paste.ofcode.org/GBUfUDHPkTaEJ3JEhdhWH7 the code

ivory pollen
#

So usually what you'd want to do is not to put a copy of every weapon into every character, but instead, create the weapons completely separately from the characters and then parent them to the right place in the skeleton

rich adder
#

show exact error

muted pawn
rich adder
ivory pollen
#

so you have a list of your characters, and a list of your weapon prefabs; once you've chosen a character, you instantiate the weapon prefabs and then set their parent to the appropriate bone in the character's skeleton

muted pawn
grand snow
#

e.g a monobehaviour you deleted but never removed from a game object

muted pawn
ivory pollen
#

Ah you mean like how to identify the hand? The simplest approach is just to say that the attachment point GameObject has to have the same name in each character's skeleton.

#

I would probably make the code which instantiates the character once the player selected it, then also instantiate the weapons afterwards. That way the character itself doesn't need to "know" about the weapons.

grand snow
#

this is painful to read this is not difficult to do 😐
As they say, spawn in the required weapon and set its parent/pos to be placed where you want in the player bones/transforms

ivory pollen
#

like:

void OnSelectedCharacter(int characterIndex)
{
    PlayerCharacter = Instantiate(characterPrefabs[characterIndex]);
    foreach(var weaponPrefab in weaponPrefabs)
    {
        var weapon = Instantiate(weaponPrefab);
        ParentWeaponToCharacter(weapon, PlayerCharacter);
    }
}
grand snow
#

well at runtime you get what weapon the player is using and create that. if they change it, destroy old one and spawn new one?

#

Have a think about what you are unsure about so you can be more detailed

ivory pollen
#

(I was imagining that other weapons would be SetActive(false) rather than destroyed, but sure)

rich adder
#

put them in an array then use a for loop to grab different on based on index or something

ivory pollen
#

What do you mean by "with script inside" ?

grand snow
ivory pollen
#

When character chooses it, it comes with button array.
You mean like an array of "which button selects which weapon" ?

#

So before the game shall i add to the Awake(); array that activates the proper hand to attach weapon on?
It's not clear which script's Awake() method you're talking about. I would generally not recommend putting scripts on the Character or on the Weapon which handle this (in Awake() or otherwise) - it's usually better to have your Controller/Manager component take care of creating and parenting the objects together, instead of distributing the responsibilities between all the individual objects.

#

Right

#

You can share the code into a pastebin and drop a link in here for everyone to be able to help out, if you want.

#

OK I see - so you are not using prefabs for this, you just have all the objects in the scene

#

So you need handTransform to point at the correct transform once the player selects a character

#

Do you have a similar CharacterSelect component?

#

You can make the CharacterSelect component get the WeaponSelect component and set the handTransform field on it.

spring skiff
#

It solved itself again and I have no clue how and why. now it works again, I was just adding a simple:

"[SerializeField] private GameObject _testGameObjectToApear1;" in the beginning of the monobehavior class and 
"_testGameObjectToApear1.SetActive(true);" inside of my OnClick event with my Sound effect, phone vibration and saving system" 

to enable a image in the panel to even know in the android build, that the script was reachable even if the Sound, Vibration and Saving inside of this script was not working.
But the sound, phone vibration and saving also works now but I was only adding this few lines of code to drag a UI Image gameobject inside of it.

How is this even possible?
If it were a mechanical machine, I would have said that something was probably jammed, or if it was a water pump, there were probably a few air bubbles in the pump, which is why it didn't work, but how does that apply to the Android .apk and .abb versions and the Unity Engine?

ivory pollen
#

Good luck 🙂

#

There's a couple of ways I can suggest:

  • Make sure the hand always has the same name in every character, and then use Transform.Find() on the root of the character to find it
  • Put a component on the hand (like WeaponAttachmentPoint) and use GetComponentInChildren to find it
  • Put a component on the root of the character which stores information about the character, and one of the fields it can store is Transform handTransform
copper kettle
#

Will this script make the object I attached it to move 1 tile in the x direction?

eternal falconBOT
rich adder
#

please don't use photos for code

#

especially a photo and not a screenshot

rich adder
eternal falconBOT
languid spire
#

AI Code? Really?

rich adder
#

is it?

rocky canyon
#

wher?! 🧙‍♀️

copper kettle
#

Yes, I tried watching tutorials but everything seems overcomplicated

rich adder
#

I just see blinding light

languid spire
#

3 lines of code, 3 comments, yes, I guess so

rich adder
#

but you can !learn properly

ivory pollen
eternal falconBOT
#

:teacher: Unity Learn ↗

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

rocky canyon
#

the top line kinda makes think that eh..

theSizeOfThisThing = 10; // the size of this thing

rich adder
#

follow the pathways ^

#

you won't learn anything by pasting code from ai especially when you have 0 clue what you're pasting

rocky canyon
#

if ur gonna use AI
im not gonna go on a witch-hunt..
but test what AI gives u.. and if its wrong..
Go BACK to AI and ask it to help u solve it

#

keep it self-contained

grand snow
#

"Help i made ai generate code i dont understand and it no worky whyyy"

rocky canyon
#

🧪 😈

rich adder
#

"AI" is being generous

rocky canyon
#

ya, we def need a new name for it..

#

internet index, gibberish generator

rich adder
#

more like a fancy google search that talks to you, mostly incorrect

copper kettle
grand snow
#

logically it looks fine to me

rocky canyon
rich adder
languid spire
rocky canyon
#

aye! i like that one steve

winged seal
#

hello, im a beginner with coding, and i need help on how to make a popable balloon when it gets shot at with basically anything with hands, guns , axes

rich adder
winged seal
#

im trying to ask for a code because i cant code

rich adder
#

no one is gonna code it for you

winged seal
#

chagpt?

rich adder
#

start with the !learn pathways they will guide you through how to code components in unity

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich adder
#

easy to apply what you learn here

#

you will be using functions you need like, OnCollision or OnTrigger etc..

winged seal
# rich adder easy to apply what you learn here

using UnityEngine;

public class Balloon : MonoBehaviour
{
public GameObject popEffect; // Assign a particle effect for the pop
public AudioClip popSound; // Assign a sound effect for the pop
public float damageThreshold = 0.1f; // Minimum force to pop the balloon

private void OnCollisionEnter(Collision collision)
{
    // Check the collision force
    if (collision.relativeVelocity.magnitude > damageThreshold)
    {
        PopBalloon();
    }
}

private void PopBalloon()
{
    // Play the pop effect
    if (popEffect != null)
    {
        Instantiate(popEffect, transform.position, Quaternion.identity);
    }

    // Play the sound effect
    if (popSound != null)
    {
        AudioSource.PlayClipAtPoint(popSound, transform.position);
    }

    // Destroy the balloon
    Destroy(gameObject);
}

}

rich adder
frail hawk
#

yeah this is ai code.

winged seal
#

defo

frail hawk
#

for lazy people

rich adder
#

learn how to actually do things by using logic

winged seal
#

managed to make vr run so

rich adder
#

or play roblox

winged seal
#

i did use to work on roblox studio i know a little there

#

but i like unity more

#

its more simple

rich adder
#

no shite I can tell

winged seal
#

😳

rich adder
#

lazy kids who don't want to put in the work thinksmart

#

"do homework for me "

winged seal
#

tutorials?thinksmart

rich adder
#

well structured courses

#

i sent you Unity specific ones

winged seal
#

you know that guy?

#

anyways im gonna learn the basic scripting skills then coming back here

rich adder
#

its not about copying what tutorial does, you have to learn the building blocks

#

after you learn the basics, you can watch whatever ttutorials you want

#

this way you don't just blindly follow, you just lookup specific thing and walk away

#

recognize where they do wrong and improve

languid spire
#

everyones in too much of a rush, the concept of spending years learning the craft of dev fills them with horror

rich adder
#

yeah next generation will be the instant download scripts to brain chips

frail hawk
#

i miss the times before 2022 when people used to ask normal unity questions . now you only get questions asked that ai cant solve for them

#

i really noticed this after all

languid spire
languid spire
rich adder
languid spire
#

'me play game, me make game', like bro

rich adder
#

hmm looks like Unity essentials was updated to have a programming section now?
https://learn.unity.com/mission/mission-4-programming-essentials?uv=6&pathwayId=664b6225edbc2a01973f4f19

Unity Learn

In this Mission, you’ll program a simple interactive experience where you control a character in a living room scene and move around to collect objects. You'll be able to choose from a variety of characters and collectible objects. In our example, we'll use a robot vacuum that maneuvers to pick up dirt around the room.

#

and its proper rigidbody code!

#

wow

Note: Don’t worry if your IDE doesn’t look identical to the one shown in the demo videos.
If the script doesn’t open in an IDE, follow these instructions to install Visual Studio, relaunch Unity, and try opening the script again.
👏 wow unity

livid sable
#

Hello, anyone can help me?

verbal dome
#

Not if you don't ask an actual question thinksmart

frail hawk
#

actually he already asked a question

naive pawn
#

actually not an actual question though

rich adder
#

don't ask to ask , just ask

naive pawn
livid sable
#

Sry

#

Found the solution

nocturne kayak
#

So, apparently i'm running into my first ever memory leak

#

I'm gonna try to put this in the most composed way i can:

#

what the fuck??

#

But no seriously what do i do from here? how do i debug this? this doesn't happen after any one action, just as soon as i play in editor

#

the Debug -diag-temp-memory-leak thing- does that mean i have to build the app?

brave compass
#

Did this start happening recently? Did you add any new packages to the project or start using any new features?

hallow bough
#

When I try to define a gameObject, it works, but when I instantiate it, the clone becomes the gameObject the script is using to clone items. As it is a collectible, once it is collected, the variable will then become missing, breaking my game. Can anyone help me? Here is the script

nocturne kayak
#

I realized as soon as i did that that the game was freezing for a good three seconds every time i did that, and then the memory leaks would come in

#

So i erased that line of code

#

but it still keeps happening

wintry quarry
rich adder
brave compass
nocturne kayak
hallow bough
brave compass
rich adder
#

it would make more sense to distinguish
var clockClone = Instantiate(clock ...

hallow bough
#

thank you, I never noticed that somehow

naive pawn
hallow bough
#

prefab

rich adder
#

clockPrefab make things very clear when you name variables

naive pawn
#

what's with the assignment in Start then

rich adder
#

oh ya wtf going on there

hallow bough
#

Honestly, I was trying anything I could think of, and I just had one offscreen

rich adder
#

you don't need that line at all

#

just assign the prefab of clock from the project folder (prefab) into the inspector slot

hallow bough
#

yeah I am realising that now

#

thank you for your help!

brittle maple
#

Can AddForce (Specifically ForceMode.Impulse) cause my player object to go trough walls?

rich adder
#

esp with discrete collision mode

brittle maple
gaunt solstice
#

Hello, I am trying to make a 2d game similar to Sonic the Hedgehog and I want my player to turn into a ball when they jump and when they're in ball mode they can bounce on enemies but if they aren't a ball they will get hurt. I am just having difficulties making the player turn into a ball and then back to normal once they hit the ground

verbal dome
#

Or just show us the inspector of all its components

brittle maple
brittle maple
rich adder
#

sounds like you can use a simple State tracking variable

#

even a simple boolean can track that state tbh. less "clean" but does the deed

brittle maple
#

Wait I posted the wrong thing

verbal dome
brittle maple
rich adder
brittle maple
verbal dome
#

Some context would be nice. All i see is a wall that can move in the Y axis only, and a player that can move in the X axis only

#

When you say "wall" most people expect a static wall, not a moving one

gaunt solstice
rich adder
brittle maple
# verbal dome Some context would be nice. All i see is a wall that can move in the Y axis only...

Alright, so, its a game about an umbrella constantly falling (to do that, everything around umbrella is moving up), its constantly (procedurally) generated and has worked fine, but when I added a tilemap, it stopped working, I removed it, and it still doesnt work. The player can move along the X axis (for now) using Forcemode.Impulse. I might've missed something but pretty much everything is here.

rich adder
#

maybe you can make the wall kinematic and use .MovePosition ? could help simulate impact better?

flat slate
#

Hello, can someone please help me? Im at programming for a year and a half now, but actually i dont know that much about rb and stuff like that. I want to make a Dash-attack for my enemys, but i dont know how to make that really because in my enemy script the whole movement is based on transforms and moveTowards and i dont really know how i can add that attack

#

the goal is just to dash in the direction of the player

rich adder
verbal dome
flat slate
#

okay

verbal dome
#

If you go with transform, you'll need to do your own collision detection

rich adder
verbal dome
#

You could use a simple state machine so that when you are dashing it will ignore your other movement code

brittle maple
brittle maple
rich adder
#

yeah but movePosition will yield better result esp with kinematic

#

otherwise you're forcing the rigidbody to catchup to transform

#

instead of rigidbody driving the transform (proper way)

verbal dome
#

Not using two dynamic rigidbodies

rich adder
brittle maple
flat slate
#

!code

eternal falconBOT
wintry quarry
rich adder
wintry quarry
#

Which works for 2d kinematic objects

rich adder
#

ah yeah also .velocity works for 2d kinematic

#

box2d 😮

flat slate
# verbal dome Using transform was the cause of phasing thru walls

so the thing is i used this tutorial https://youtu.be/tH57EInEb58?si=v-dVZ5NEoOzRtm_F to make this dash. And the only problem i have is with the part with "rb.velocity =..." because i dont know what i have to attach to that to get it that its moving to the players direction

In this video I'll show you a quick and simple way to give your player a nice dashing ability! This tutorial is an extension from my previous 1 minute tutorial, where I show you how to create simple top down movement, you can find it here: https://www.youtube.com/watch?v=tFblCEFQoTs

if there are any tutorials you'd like to see, feel free to lea...

▶ Play video
#

the rest is working i guess

verbal dome
#

You'd use the same direction that you use for moving your character somewhere else in your code

gaunt solstice
verbal dome
rich adder
flat slate
verbal dome
#

Ok what direction do you want to dash in?

flat slate
#

in the direction of the player

verbal dome
#

Maybe just show your !code

eternal falconBOT
gaunt solstice
flat slate
rich adder
#

then you can figure out if you get hurt or not when OnCollision. But simple bool can also work ofc.

verbal dome
# gaunt solstice a box collider

I don't recommend using a box collider for a character especially in 3D. It has hard edges which can feel unpleasant
A capsule collider is the common way to go. Then you can adjust the capsule collider's height to transform it into a sphere when you go into the "ball" mode

flat slate
verbal dome
flat slate
#

in rb.velocity i have to use a vector to adjust it

languid spire
#

did you not look to see what transform.right and .up are?

flat slate
#

i dont know what they are

#

are they vectors?

languid spire
#

that is why google and docs exist

flat slate
#

you are right

gleaming topaz
frail hawk
#

more likely shorthands for vectors i´d say

languid spire
languid spire
#

perhaps learn about sarcasm first

gleaming topaz
#

perhaps womp womp

sharp abyss
wintry quarry
#

Or make the weapon and arms 0 mass

sharp abyss
verbal dome
sharp abyss
sharp abyss
#

is it something you can see n debug mode?

verbal dome
magic panther
#

Thanks guys for being here to help, I really appreciate it

carmine totem
#

Google came through.. I was missing "Entities Graphics" (tutorial says to install, but not for what and why)

north kiln
carmine totem
#

Looks like SRP (=URP) = not supported by what you linked. and SRP is the new default in unity 6. at least the launcher seems to suggest that when creating a new project.

rich adder
#

just run the converter BiRP to URP
the visuals/rendering wouldn't affect how this asset functions.

#

converter is part of URP package

forest harness
#

i use the kinematic controller package as well, it doesn't matter what render pipeline you use, it probably is just relying on one for its example scenes

#

fwiw that package is extremely good i highly recommend it

north kiln
#

If you did actually want to use the Entities character controller then yes, you must use an SRP with Entities Graphics

lilac plinth
#

i cant control the plauer object idk whjy can anyone look through my script?

north kiln
#

!code

eternal falconBOT
lilac plinth
#

here

rich adder
lilac plinth
rich adder
#

also put a speeed/force multiplier, make sure you have enough power pushing this rigidbody and its mass

magic panther
#

I have this function in my class. Problem being that I am comparing other to the two colliders the class has, both for different purposes. This code won't work, as it checks if the collider of the object collided with is one of the variables. I need to check if the collider that caused the collision on the missile's end is one of the variables. Is there a way to do that?

https://hastebin.com/share/obuvayapef.csharp

north kiln
rich adder
#

thats the new Input system Messages mode i believe

north kiln
#

Do messages work on private functions? Maybe they do

rich adder
#

yea

north kiln
#

Either way, do some debugging

lilac plinth
#

step 7. atm

rich adder
#

^ put some logs in OnMove as well

lilac plinth
#

type logs into it?

rich adder
north kiln
rich adder
#

its quick and easy tho lol

lilac plinth
#

like so? void OnMove(InputValue movementValue)Debug.Log

rich adder
#

do you have a Player Input component on your player and this script on that ?

north kiln
lilac plinth
#

idk if the script is on that or not

rich adder
lilac plinth
#

i just follow the guide

north kiln
rich adder
lilac plinth
#

no thjere is a script ill send it here

magic panther
rich adder
#

in this case on the same one as Player Input component

lilac plinth
#

cause the guide say nothing about that

#

besides putting it in a scripts folder

north kiln
#

it's not a probably you don't have to

#

it's a you definitely have to

lilac plinth
#

okay then I dont't have to

#

oh okay can you show me how?

#

the guide the doesnt cover that

north kiln
rich adder
#

MonoBehaviour is a component, in order for a component to do anything in goes on a gameobject

lilac plinth
#

ah

#

now how can i remove the other player input component?

rich adder
lilac plinth
bitter apex
#

I keep getting a "The object you want to instantiate is null" argumentexception.

// in Start()
prefabTile = (GameObject)Resources.Load("initialPrefabTile"); // no idea if this could be the issue or not
// other code and stuff ...
for (int x = 0; x < objectWidth; x++)
    {
        for (int y = 0; y < objectHeight; y++)
        {
            Vector3 position = new Vector3(x * blockSize, y * blockSize, 0);
            GameObject tile = Instantiate(prefabTile, position, quaternion.identity);   
            tile.name = $"tile_{x}_{y}";
        }
    }

I added some checks and prefabTile != null, and it's definitely fine in the inspector whenever i run the program, so i assume I'm doing something wrong with Instantiate? or something else entirely?

rich adder
# lilac plinth

one is for capturing inputs and one is to useing those inputs to do stuff

#

you keep both

lilac plinth
#

ou

north kiln
vocal orchid
#

@rich adder not working, the get same result

rich adder
rich adder
vocal orchid
rich adder
vocal orchid
#

The event is must public, right¿

lilac plinth
rich adder
lilac plinth
#

so that mean i can only keep 1 right?

lilac plinth
#

because i go into playmode

vocal orchid
rich adder
lilac plinth
#

should i screen record it and send it back to you? vertx?

north kiln
#

Sure

vocal orchid
bitter apex
rich adder
vocal orchid
# rich adder please show your current code and explain a bit what you want to do with it. I'm...

Ok

using TMPro;
using UnityEngine;

public class UI_Points : MonoBehaviour
{
    [SerializeField] Enemy_1 enemy_1;

    [SerializeField] TMP_Text pointsUI;

    float pointsCurrent;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        enemy_1.UpdateUIPoints += writeUI;

    }

    void OnDisable()
    {
        enemy_1.UpdateUIPoints -= writeUI;

    }

    void writeUI(float points)
    {
        pointsCurrent += points;
        pointsUI.text = pointsCurrent.ToString();
    }
}

``` The script the gameobject subscribed to event of prefab
north kiln
rich adder
#

you would want it from the instance

lilac plinth
#

ty guys

#

i readd the player controller

#

and go to playmode

#

the comp is not removed

#

and player is controllable now

vocal orchid
rich adder
# vocal orchid How?

if you want this script to listen to ALL enemies event you can also just make the event static and subscribe to the static event rather than a specific enemy

rich adder
vocal orchid
rich adder
#

that way any Enemy class that invokes that event you get notified if subbed

north kiln
#

Note that static events are an extremely easy way to create a leak, so you must unsubscribe from them when you're done

rich adder
#

ah yeah always do the OnEnable sub, and OnDisable cleanups

magic panther
rich adder
carmine stone
#

Anyone able to help with this?

magic panther
gentle bone
# magic panther If someone knows please ping me

i would try to simplify the code first... its not a good code design using a lot of nested "if" statements like... if { .... if {.... if {... if { ... try simplifiy it with the things you wont have first... if not xy... return.. then do the 1-2 it should do..

magic panther
#

It's the only issue right now I don't know how to resolve

magic panther
#

But I bet my life it's possible in afairly simple way

teal viper
magic panther
rich adder
spring skiff
robust condor
#

I have tons of scriptableobjects that hold composable data such as CharacterSO for playable characters. What is the best way to access a list of these characters during runtime? Should I create a Datamanager monobehaviour singleton that can access the SO for this info?

magic panther
wintry quarry
magic panther
#

This is suprisingly difficult to phrase for me

robust condor
#

@wintry quarryRight, and where would you put it? SO needs to be instantiated does it not?

rich adder
wintry quarry
#

You drag and drop them in the inspector

robust condor
#

If I have a SO called HealthSO which is shared across all characters in the game, will they share the same health?

wintry quarry
#

You can make many objects from a class

#

And name them whatever you'd like

#

but I don't see a SO as a good way to track the health of an individual character

#

because then you'd need an instance for each one, and at that point what are you gaining?

#

SOs are best for immutable shared data reused in many places

robust condor
#

Yeah as a reference, because in my CharacterSO I have a "public StatsSO stats" which contains a list of attributes possible for the character. And multiple characters share these attributes. So I mean when I run the game all the characters would need unique instance of these

wintry quarry
#

You might as well use a POCO

magic panther
# rich adder can you explain the mechanic , dont explain what you want from code. What is the...

The missile flies around. It has a collision collider and a field (or explosion) collider. The field collider causes the missile to prime, storing the objects detected in a list. When the missile stops colliding with these objects, they should be removed from the list. This is used to damage the objects if possible when the missile explodes. Speaking of that, the missile has a lifetime, which counts up every frame (speeds up when primed) up to it's maxLifetime. Once that number is reached, or the collision collider collides with another collider, the missile explodes, dealing damage to the objects the field collider was colliding with at that time.

Here's the missile's code, it should be a bit clearer.

https://hastebin.com/share/ogiwebehoc.csharp

wintry quarry
#

If you have a SO for base stats that's a different thing entirely than "current stats"

robust condor
#

Well it is great for the inspector editing

wintry quarry
robust condor
#

Yeah it should be for base stats

wintry quarry
#

e.g.

[Serializable]
public class Stats {
  public float hp;
  public int strength;
}

public class Character: MonoBehaviour {
  public Stats stats
}```
robust condor
#

So I guess I should just instantiate a new character using the SO data

wintry quarry
# robust condor Yeah it should be for base stats

then I would do something like this:

public class Character : MonoBehaviour {
  public BaseStatsSO baseStats;
  public Stats currentStats;

  void Awake() {
    currentStats = new Stats(baseStats); // copy from the base stats
  }
}```
#

and then you would deal with currentStats from then on out

#

leaving baseStats to not be modified

rich adder
robust condor
#

Right

magic panther
#

The problem right now seems to be that the missile won't collide with them

#
    private void OnTriggerEnter2D(Collider2D other) {
        if (other == mainCollider) {
            if (other.gameObject.TryGetComponent(out LayeredCollidable objectLayeredCollidable)) {
                if (objectLayeredCollidable.ship) {
                    lifetime = maxLifetime;
                }
            }
        }

        if (other == explodeAreaCollider) {
            if (!zoneObjects.Contains(other.gameObject)) {
                zoneObjects.Add(other.gameObject);
            }

            if (!primed) {
                primed = true;
            }
        }
    }```
Now it's a bit cleaner. Still does not work. It appears `other` is the object that was collided with. I need the collider that caused the collision on the missile's end
#

Like, know if the explodeAreaCollider did it or the mainCollider

#

Put it this way: I'm not checking if other caused the collision. I'm checking if the missile collided with other

rich adder
#

you can have different zones per cast

magic panther
#

Actually, yeah

#

I'll try that

trim galleon
#

how do i fix this?I havebeen working on this for 30 minutes and its still not working

wintry quarry
#

Vector is not one of them

#

Maybe you wanted Vector3 or Vector2?

#

Or maybe you're using a variable that doesn't exist?

trim galleon
#

i have writed Vector3 but idk whats wrong with it

wintry quarry
#

you'd have to show your code if you want more specific advice than that

#

!code

eternal falconBOT
wintry quarry
#

but you are trying to write code with an IDE that is NOT configured

#

you need to configure it before you do anything else

#

!ide

eternal falconBOT
trim galleon
#

i dont understandUnityChanPanicWork

flint igloo
#

How do I get a unity script to say a variable value in the console?

trim galleon
#

the whole thing

flint igloo
trim galleon
wintry quarry
wintry quarry
#

Or:

Debug.LogFormat("My variable's value is {0}", myVariable);```
or ```cs
Debug.Log("My variable's value is " + myVariable);```
#

any of these work

nocturne kayak
#

hey, i'm using a toggle button and i see there's a "on value changed" option- is there a "on value set false" of something of the sort?

wintry quarry
wintry quarry
#
if (!newValue)...```
flint igloo
wintry quarry
#

You're just printing some random object out

#

you need to print the velocity

#

not a random script or object

#

Show your code if you want more help

austere osprey
#

this damn audio adjustment just won't do anything. like it apparently won't save my audio settings in player prefs as it keeps being stuck at 0% volume when i load the game and it won't even adjust the volume when i play around with the sliders and i just feel so lost i have no clue how to fix this
https://pastebin.com/HnmEUEfc

wintry quarry
#

Start using Debug.Log to see what's going on (sorry misread)

flint igloo
# wintry quarry Show your code if you want more help

I could do that, but it was a pretty big tutorial with a lot of moving parts that I pretty much just copy pasted. The reason why I want to find out the values of these variables is because I'm new to coding (just in C#) and I don't really understand what values the variables actually are and how adding them together creates the player movement that I'm seeing, so I'm trying to see what the variables are actually doing.

wintry quarry
#

the point of tutorials is to learn how things work

#

not to just get a thing working

flint igloo
#

Okay tutorial isn't the right word

wintry quarry
#

I recommend doing the tutorial again and taking it slow and making sure you understand each part

flint igloo
#

I just copied this movement script for a character, and I'm trying to kind of learn it myself

#

through finding out what the variables actually are

wintry quarry
#

You won't learn by blindly copying. Anyway it's not clear what your actual question is then

#

If you won't share your code we can't help you figure out how to get the velocity

flint igloo
#

hold up one sec

#

`if (_requestedJump)
{
_requestedJump = false;

        motor.ForceUnground(time: 0f);

        //Add Jumpforce
        var currentVerticalSpeed = Vector3.Dot(currentVelocity, motor.CharacterUp);
        var targetVerticalSpeed = Mathf.Max(currentVerticalSpeed, jumpSpeed);
        //Add the diffrence in current and target vertical speed to the character's velocity
        currentVelocity += motor.CharacterUp * (targetVerticalSpeed - currentVerticalSpeed);
    }`
#

It uses a KinematicCharacterMotor addon type of thing

wintry quarry
#

This is not a script

#

this is a random several lines of code

#

doesn't tell us much

#

Anyway if you want to print the curreent velocity you'll need a variable that holds it

#

if there is no such variable, you'd have to create and update one

#

there's something here called currentVelocity which sounds promising, but based on this code snippet it's possibly only holding vertical velocity

flint igloo
#

Is there a way for me to paste over the entire script without flooding the chat?

wintry quarry
#

you could try that though

#

!code

eternal falconBOT
flint igloo
#

lmk if that works

wintry quarry
#

this is using the KCC asset from the asset store

flint igloo
#

https://www.youtube.com/watch?v=NsSk58un8E0
Here is the original video btw

This one is a bit different than the last couple devlogs. I thought it would be fun to share a longer video where I actually make a thing. Might be super boring? Idk!

Links:
https://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
https://youtu.be/7daTGyVZ60I
https://youtu.be/tYc1yUt0IeA
https://github.com/TheAllenChou...

▶ Play video
wintry quarry
#

Not necessary

flint igloo
#

Lets just say that I want to get the currentVelocity pasted in the console whenever the (_requestedJump) thing is called, how would I go about that?

austere osprey
#

so like the volume adjustments should be made by setting up the volume sliders in my pause menu with some functions in the pause menu's script, and then when the value of said sliders change they should change the volume. idk i suspect there might be something up with that because i put in debug logs into my code and they said the value that got saved in playerprefs was just 0. problem is, not really sure what to put in the onvaluechange thing's parameter for the sliders here (for reference, below is the function that this particular slider in the image refers to)

public void SetSFXVolume(float volume) { sfxMix.SetFloat("SFXVolume", Mathf.Log10(volume) * 20); PlayerPrefs.SetFloat(sfxVolumeKey, volume); PlayerPrefs.Save(); Debug.Log("Volume settings saved: " + PlayerPrefs.GetFloat(sfxVolumeKey)); }

wintry quarry
flint igloo
#

if I put that in like this Debug.Log(motor.GetState().BaseVelocity); it still just returns (object)

wintry quarry
#

nah not possible

#

you didn't save your code or something

#

or you have an error

flint igloo
#

Oh wait

wintry quarry
#

or you are looking at the wrong log

flint igloo
#

lmao I am an idiot it is at the top lol

#

Thanks bro

#

appreciate it

#

hold up

#

I was looking where it said UnityEngine.Debug:Log (object)

#

not directly above it

#

thats why

#

say I wanted it to just spit out the first, second or third value or a combination of them, how would I do that?

rich adder
#
  • or use $
wintry quarry
#

just... type what you want to print

#

it will print it

#

this is just a Vector3

#

you can do with it what you want

flint igloo
#

Yeah man I'm really new lol sorry

#

I'm probably messing with coding scripts that are way out of my realm of understanding

wintry quarry
#

Well KCC is a little complex for a bare beginner yes

#

but just simple manipulation of vectors and Debug.Log are very simple

flint igloo
#

If I want to show two variables in one Debug.Log, how do I separate them? I've tried commas and I've tried adding a + sign, but that just actually adds them together.

wintry quarry
sage peak
#

Hey guys! Idk what happened, but my collider isnt working at all. I tried connecting 2 scripts to 2 new objects, none of them work. Its not the scripts, its something with the collider because even a sound doesnt play on collisions, I tested it with a simple script

queen adder
#

does Input.GetKeyDown(KeyCode.Letters) work on Bluestacks (any other android emulator) on android builds?

wintry quarry
queen adder
#

dunno

#

just a popup

wintry quarry
wintry quarry
sage peak
wintry quarry
#

you must have messed something up

#

Show us:

  • The inspectors of the two objects
  • the code (and explain which object it's on)
sage peak
#

I set up an object

#

I turn off mesh renderer

rich adder
sage peak
#

I add component to this cube and I add this script

flint igloo
sage peak
#

public class TestScript : MonoBehaviour
{
    public AudioClip collisionSound;

    private void OnCollisionEnter(Collision collision)
    {
        AudioSource.PlayClipAtPoint(collisionSound, transform.position);
    }
}
#

I use gpt plz dont hunt me down

#

Okay then I asign the sound

#

And nothing works

#

🤷

rich adder
sage peak
#

My bad, here

rich adder
#

what about other object

sage peak
#

Lets just test this one, I meant I tried it on 2 objects

rich adder
#

where is the other one

sage peak
#

Ohhhh The capsule!

rich adder
#

show inspector

#

and how you move it towards "collider thing"

sage peak
rich adder
#

OnCollision does not work with CC (Character Controller)

sage peak
#

I have other colliders that it worked perfectly with

#

But I just realised for some reason the capsule is not colliding with the cube

rich adder
#

the collision works fine, its the event that doesnt get called

#

OnCollisionEnter wants Rigidbody

#

thats why OnControllerColliderHit for CC

#

its the next closest thing

sage peak
#

So I shoudl add a RigidBody to the player?

rich adder
#

use the other method, which goes on CC gameobject itself then call the method you want based on tag / component check of what you hit

sage peak
#

Okay let me check, Thank you!

rich adder
#
   void OnControllerColliderHit(ControllerColliderHit hit)
   {
       //e component
       if(hit.collider.TryGetComponent(out SomeComponent c))
       {
           c.DoSomething();
       }
       //e tag
       if (hit.collider.CompareTag("SomeTag"))
       {
           DoSomethingElse();
       }
   }```
weary tartan
#
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class Animations : MonoBehaviour
{
    private Animator animator;
    private Rigidbody rb;
    private Vector2 moveInput; // Stores movement input

    public void Start()
    {
        animator = GetComponent<Animator>();
        rb = GetComponent<Rigidbody>();
    }

    // Input System callback for movement
    public void OnMove(InputAction.CallbackContext context)
    {
        moveInput = context.ReadValue<Vector2>();
        Debug.Log("OnMove called with input: " + moveInput); // Debug for testing
    }

    public void Update()
    {
        // Convert moveInput to a Vector3 for 3D movement
        Vector3 movement = new Vector3(moveInput.x, 0, moveInput.y);

        // Set "isWalking" based on movement magnitude
        animator.SetBool("isWalking", movement.magnitude > 0);
        Debug.Log("Update Move Input: " + moveInput + ", isWalking: " + (movement.magnitude > 0));
    }
}```

Does anyone know how to fix the bug for Unity never finding the OnMove function?
rich adder
wintry quarry
#

in what way should it "find" it?

#

If you're using PlayerInput in "Send Messages" mode, you don't have the correct method signature there

weary tartan
wintry quarry
#

What mode is your PlayerInput set to?

rich adder
#

ah yeah if its messages mode you need InputValue

wintry quarry
#

If it's on Send Messages you need an InputValue param not CallbackContext

#

if it's on Unity Events you have to manually assign the function

#

If you don't have a PlayerInput component, you need more than this to handle the input.

weary tartan
wintry quarry
#

I mean the PlayerInput component

#

Do you have one on the same GameObject as this script or not

#

You said:

all the scripts and input schemes are on the same object
But it's not clear what an "input scheme" is

rich adder
#

screenshot us the gameobject with PlayerInput component 😅

weary tartan
wintry quarry
#

Is this a complete sentence?

#

it's a simple question

#

do you have a PlayerInput component on the object or not?

#

If not, then it's not going to magically work without one (properly configured) or without other code to hook your function up to the input asset

wintry quarry
#

which won't work with your code

rich adder
#

yeah you got wrong signature there

weary tartan
weary tartan
#

Just to check

wintry quarry
#

THe method signature is the return type and the list of parameters

rich adder
weary tartan
#

Oh OK. Thanks

quartz lantern
#

Running across a bizzare bug that makes my event system stop working. I have a single eventSystem on dont destroy on load and after reloading a certain scene the event system just stops working. Buttons dont detect mouse presses etc. The only way to fix it is to disable the Event system and re-enable it on the heirarchy (or in code). Has anyone come across this before?

wintry quarry
quartz lantern
wintry quarry
wintry quarry
#

Is there a good reason you need a custom one for the input module?

#

Most of the time I've found that the default asset works just fine for it.

quartz lantern
quartz lantern
#

thanks dude

quartz lantern
sand dagger
#

How do I hide a panel/menu? I'm trying to make a main menu with a menu that loads on start, a difficulty selector that loads when you hit Play, and an audio button that lets you adjust the volume, but I don't know how to hide panels with button presses

sand dagger
#

Thank you

nimble apex
#

its weird to use awake/start inside interface right?

cosmic dagger
teal viper
#

But, yeah, I wouldn't do it.

#

These methods are supposed to be optional by design.

cosmic dagger
#

you may as well make interfaces for all the UnityEvents: IAwake, IStart, IUpdate, IFixedUpdate, ILateUpdate, etc . . .

#

I think I actually did this for something . . .

wintry quarry
teal viper
untold shore
#

Hey, what does this mean?

teal viper
untold shore
teal viper
robust condor
robust condor
#

I tried searching the registry but nothing came up

teal viper
#

But I'd check thoroughly in the package manager. Check the different categories.

robust condor
#

I installed it by name "com.unity.nuget.newtonsoft-json"

quick epoch
#

hello guys im having a problem with my enemy animation.. done everything correctly in the animation/animator windows but now my code doesnt seem to work... please could you give me ahand?

teal viper
eternal falconBOT
quick epoch
# teal viper Share the !code correctly and explain the issue in details.

so the challengerController is there i shared it, so what happens is the enemy is roaming, and the direction is going is picking the sprite for the respective direction but its only the IDLE one... so when is moving is facing the right diorection but not animating... ive done all the 4 animations in the blend tree plus the transitions and all but i think my code is what seems to be wrong .... what do you mean by share the code correctly?

teal viper
quick epoch
#

oh sorry fellas

#

sorry its over 2000 characters

robust condor
#

I have the weirdest bug. I can't update my label text, despite it doesn't complain about being null:

var characterNameLabel = characterInfoContainer.Q<Label>("character-name");
Debug.Log($"characterNameLabel is null: {characterNameLabel == null}"); // False
Debug.Log($"Character name: {character.Name}"); // Has value
characterNameLabel.text = character.Name; // Doesn't work

This is called inside a function I run on buttonpress.

teal viper
quick epoch
#

but im guessing thats the bit of code that handles the animation

private IEnumerator MoveToTarget()
{
    if (!isMoving)
    {
        isMoving = true;
        Vector2 moveDirection = targetPosition - (Vector2)transform.position;           

        // If moving, update direction
        if (moveDirection != Vector2.zero)
        {
            animator.SetFloat("moveX", moveDirection.x);
            animator.SetFloat("moveY", moveDirection.y);                
        }

        animator.SetBool("isMoving", isMoving);
        

        while ((Vector2)transform.position != targetPosition)
        {
            transform.position = Vector2.MoveTowards(transform.position, targetPosition, moveSpeed * Time.deltaTime);
            yield return null;
        }
    }

    isMoving = false;
    // Stop movement but KEEP last direction
    animator.SetBool("isMoving", false);
}```
teal viper
teal viper
quick epoch
#

ive done... its showng the proper directions right i removed them ... when its picking a direction is either 0,-1 or 1,0 etc..

teal viper
quick epoch
#

oh ok let me add some

#

sorry

teal viper
#

Nvm. Managed to view it in different mode.

teal viper
# quick epoch oh ok let me add some

You should add logs when setting the animator parameters. You can also open the animator tab at runtime with the animated object selected to see it's parameters in real time. As well as what state it's in.

quick epoch
#

i added some comments there hopefully it helps

robust condor
#

@teal viperThere isn't much more. I think I am running into some kind of redraw problem. That the UI doesn't update.

private void ShowCharacterInfo(Character character)
        {
            var characterInfo = _characterInfoTemplate.Instantiate();
            var characterInfoContainer = characterInfo.Q<VisualElement>("character-info-container");
            Debug.Log($"characterNameLabel is null: {characterNameLabel == null}"); // False
            Debug.Log($"Character object: {character.Name}, {character.Biography}");
            Debug.Log($"labeltext: {characterNameLabel.text}");
            characterNameLabel.text = character.Name;
...
#

When update the label in the inspector it works

#

Ah wait I fixed it. I think I know what happened kinda. It instantiated a new uxml (which was invisible in the debugger for some reason) instead of using the one that was already there

teal viper
quick epoch
#

so i was able to make it move .. i open the animator as you told me .. and during the game on i tweaked true and false the transitions and it started working but it was the same before O>o? but now the challenger starts the game already animating

#

now i added another check when i get component for animator to set the isMoving to false at the start and it worked O.o? really this is messed up haha

teal viper
#

Basically, pay attention to your states and transitions and make sure they are working as you expect.

quick epoch
#

now it is but feels like the program didnt update the animator after i made changes

amber swallow
#

I was wonder if anyone knew what i am doing wrong as i am trying to connect a script to a game object but it says that the game object i (think ) i connected it too doesnt exist ive checked in unity and it looks good as it is under the game object but im not quite sure what im doing wrong here

#

The tutorial im following if it helps at all

teal viper
eternal falconBOT
teal viper
echo ruin
burnt vapor
shell orchid
astral falcon
echo ruin
#

Do you have an audio listener component?

quick epoch
#

guys whats the best approach for collision in this situation? i got a 2d top down game snap grid walk, and now im introducing roaming for my enemy .. but as i come near to the enemy with player the enemy doest not collide with player during roaming.... i got rigid body and colliders in both player and enemy... what would be the best approach here?

shell orchid
#

i have two audio sorces

#

one for a sound effect and one for the music (bad one)

echo ruin
echo ruin
echo ruin
#

Also your coroutine wont start unless you actually put it somewhere

shell orchid
#

oh shoot

#

alright then

echo ruin
#

Looks better

shell orchid
#

let me do a different way rq

echo ruin
shell orchid
#

i now put it in start

#

i figured a way

#

i got it

echo ruin
hexed terrace
arctic shore
hexed terrace
#

It's mostly animation, because you need to setup that properly to be able to run multiple animations on different parts - you don't do that with code, delete from here and ask in #🏃┃animation

queen adder
#

is there a callback that gets called everytime after you move a gameobject? I have a StickToNearestColliderMethod snap I'd like to automate

visual linden
copper kettle
#

Does anyone know a tutorial that shows how to create invisible buttons on touchscreen?

queen adder
#

id probably just create editor hotkeys

queen adder
#

unless you mean something else

burnt vapor
#

However, maybe you should not automate this if you end up checking for gameobjects to move each frame. That's one of the reasons why this doesn't exist as-is

#

It's better to rely on the build on collission to trigger and handle it from there

queen adder
#

public static class GlobalStickToWalls
{
    [UnityEditor.MenuItem("Hotkey/Stick Selected GameObject To Wall #s")]
    private static void SnapToStickToWalls()
    {
        foreach(var item in UnityEditor.Selection.gameObjects)
        {
            var c = item.AddComponent<StickToWalls>();
            c.MoveToTouchWalls();
            Object.DestroyImmediate(c);
        }
    }
}```Just did this anyways
hexed terrace
queen adder
#

ye, just a hotkey thing to make map designing quicker

#

the class is still accessible in builds, if everything is fine

hexed terrace
#

UnityEditor namespace can't be included in builds

copper kettle
#

How to make an object increase x position by 1 when a button is pressed?

grand snow
obsidian plaza
#

or
transform.position = new Vector3(transform.position.x+1, transform.position.y, transform.position.z);
cause it only takes one line

hexed terrace
#

less readable

grand snow
#

i presume the 3 property access are optimised but tbh i dont trust mono 🤷‍♂️

burnt vapor
#

The difference is negligible performance wise, if there even is any

obsidian plaza
#

yea i figured

#

i just always do it like that

grand snow
#

transform.position goes from managed to native code so its not the same
but on non mobile platforms its probably never worth worrying about

obsidian plaza
#

wait guys

#

transform.position += new Vector3(1, 0, 0);

#

no?

#

o wait no

#

need to make it a variable

#

smh c# kinda ass

#

or does it just work

#

am confuse

copper kettle
#

Can I pm someone to help me

obsidian plaza
obsidian plaza
#

have never thought of that

copper kettle
#

I need help making a button and moving player when pressed, all the tutorials ar confusing

obsidian plaza
#

ur modifying the entire property