#πŸ’»β”ƒcode-beginner

1 messages Β· Page 510 of 1

devout flume
#

Making a += overload without returning anything is technically not standard C(++)

#

This can cause issues depending on who will use your library

burnt vapor
#

+= is fine, it's the multiple inline assignments that makes my skin crawl

#

Never had a use for it anyway

languid spire
#

ok, so how would you set 3 variables to the same value?

devout flume
#

Yeah, it applies to all of them either way

devout flume
languid spire
#

I have no problem with a = b = c = 1; Makes perfect sense to me

burnt vapor
#

To avoid an unneeded discussion, let me just say that the average person would have to spend a significant amount of time figuring out what a line like that would do. That would be enough reason to advice against it tbh

devout flume
burnt vapor
#

And it might have been a mandatory thing in C or C++, but this is a C# server

languid spire
devout flume
#

I'm the kind of person to do

int fd
if ((fd = open(...)) != -1) {}
devout flume
languid spire
burnt vapor
#

Sorry, maybe I'm a bit quick to judge, but it has only been a few days since somebody here suggested the use of a nullable boolean because it's good to have a "maybe" state 😎

devout flume
#

That's standard C yes

burnt vapor
#

If you have to go out of your way to figure out why something like it exists (in this case it would be relevant for both) then it's time to rewrite

devout flume
languid spire
burnt vapor
#

You think the average programmer would care?

languid spire
#

no, but they should

burnt vapor
#

Of course not

#

If you would care so much about this then you would not write with C# to begin with

languid spire
#

wrong, you use the tools which are available to you in the context of which you are working

burnt vapor
#

Let's at least learn the beginners the proper way to manage states then πŸ˜›

languid spire
#

how about we just educate them to think, that would be a damn good start

faint osprey
#

im instantiating in a card in script and then in its awake function im creasing the alpha from 0 to 255 howver once the alpha gets to full the cubes start to blend together (the cards are two small cuboids stuck to the back of eacother

#

with different materials on different sides

burnt vapor
#

And even if it did, you didn't share any

#

Do that, and maybe a video

#

All I can say is that it sounds like z-fighting

ivory bobcat
cosmic hinge
#

Is there a cell count limit for unity's built-in "Grid" component? Like 10 rows and 15 columns or something like this?

polar acorn
#

If I had to guess, probably 2,147,483,647

wintry quarry
#

of course actually havoing data in that many cells will be a memory limitation on your system overall

worn spire
#

Hi, i'm new in C# so sorry if i'm asking something simple, the program tells me the next error:

#

Idk how to fix it, someone can tell me what i have to change on the code?

slender nymph
eternal falconBOT
worn spire
#

aight

tall lodge
slender nymph
#

a configured IDE would show them that too, which is why it is a requirement to ensure it is configured before providing help

worn spire
#

ops🀭 , damn and ihave checked it like 5 times

subtle sedge
#

Does anyone know how to change a sprite in unity?

#

bro "yes" 😭

slender nymph
#

next time try !ask ing a proper question

eternal falconBOT
polar acorn
subtle sedge
subtle sedge
steep rose
hollow slate
#

I can't seem to find a way to get all the scenes in my project that aren't loaded, and from there get their names.
From what I understand, I only have the option of fully loading a scene with a specific index to check what the name of it is.
If this scene doesn't exist, then it just doesn't load.
SceneManager.sceneCountInBuildSettings gets the amount of scenes in the build, which is 3 for me.
I then attempt:

for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++)
        {
            //(doesn't work) Scene s = SceneManager.GetSceneAt(i); 
            //(doesn't work) Scene s = SceneManager.GetSceneByName(name);
            Scene s = SceneManager.GetSceneByBuildIndex(i); //doesn't work

            if (!s.IsValid()) continue;

            if (s.name.Equals(name, StringComparison.OrdinalIgnoreCase))
            {
                return s;
            }
        }

This, however, tells me that I don't have a scene at index 1 because it isn't loaded.
I need some way of "peeking" at a scene, like in a list without having to pop the damn thing.

#

it finds the first scene in the index, because that's the currently loaded scene. The rest are invalid with an index of -1. It's not a valid scene, even though I know there are scenes at index 2 and 3.

wintry quarry
#

The rest of those functions (SceneManager.GetSceneXXX) only work with scenes that are currently loaded.

#

This is the kind of thing that a lot of games end up building some custom tooling around, i.e. with ScriptableObjects and some pre-build scanning editor script.

vernal thorn
#

How can i assign controller 1 too player 1 and controller 2 too player 2? Because righnt now both controllers controll the same player

hollow slate
wintry quarry
#

Not that I'm aware of

#

It feels like a limitation because it is one

#

Unity doesn't have a way to read "metadata" from a scene before loading the scene

hollow slate
wintry quarry
hollow slate
#

@wintry quarry so, what do I do then? I need to load all scenes in the background and store their names based on index...?

#

no metadata available AT ALL?

wintry quarry
near wadi
#

is there a more efficient/common way to see if two Vectors are nearly equal, or is this fine?

    private bool PositionsAreEqual(Vector3 pos1, Vector3 pos2, float tolerance = 0.1f)
    {
        return Vector3.Distance(pos1, pos2) <= tolerance;
    }
wintry quarry
#

(hardcoded at 1e-5)

near wadi
#

well, that was an adventure! With my extended programmer (i hate to say it, but it is ChatGPT 4o and 4o-mini). i now have two scripts that together do the following:
Place a Nav Mesh Obstacle where any Terrain Tree is, since there is a bug in the system that does not add a tree as an Obstacle in the Nav Mesh Surface. https://issuetracker.unity3d.com/issues/navmeshsurface-trees-placed-on-terrain-are-not-taken-into-account-when-baking-navmesh (thanks @steep rose finding that, and stopping me from wasting more time). this allowed NPC/AI/Player to walk through trees, or to get Nav glitched on them if you use Tree Colliders, which i consider absurd. Automatically swap to a Prefab version of the Tree when close, and back to Terrain Tree when you walk away. i use the same Prefab to make the Terrain Brush since it strips everything except basically the Mesh/Mesh Renderer anyways. this allow an auto swap to the correct prefab without having to manually cross reference which Prefab should replace which trees. The common rotation and scale issues are resolved and match perfectly when swapped back and forth between Prefab and Terrain Tree (Thanks @robust schooner for a vital piece of information about that).
The Nav Mesh Obstacle is Destroyed and the Nav Mesh hole/Carve is removed automatically when the Tree is chopped down/Destroyed/is temporarily in Prefab form. i may change it a bit to keep the Obstacle in Prefab form, and remove only if either Terrain Tree, or Prefab is Destroyed.

#

BTW, ChatGPT released a tool called Canvas today (for paid accounts. goes free and teams soon)

whole gyro
#

I made a script called game manger but the icon won't show up, not sure what I'm doing wrong when I'm following a tutorial.

near wadi
#

it does not show up anymore, by Unity design choice/bug fix. it is not a problem @whole gyro

steep rose
whole gyro
near wadi
#

to me, ChatGPT as a learning from scratch tool for coding is a bad idea. however, if you know enough to comprehend the(often) bad code it gives you, and prompt it to fix it, it is just a tool like any other in my arsenal. It writes working code for me faster than i can myself πŸ™‚

near wadi
whole gyro
#

Learning c+ by making pong so stuck on what to place in the script for keeping of point. A nice way to ease myself into c+

eternal needle
pastel dome
#

All programmers use AI to understand code now days

eternal needle
eternal falconBOT
#

:teacher: Unity Learn β†—

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

tawdry quest
hollow slate
pastel dome
#

Catch up to the time before you're left behind AI makes us faster programmers

eternal needle
tawdry quest
#

If you know how to code, then AI is a great assistant to code faster (AI autocompletion), but code generation like as to understand code (chatgpt) is like wrong

#

But you need to know how to code, to catch the AI completion hallucinating

steep rose
tawdry quest
#

Also reminder of the rules, we do not allow AI code as answers here and will not help with AI Garbage Code

near wadi
tawdry quest
pastel dome
#

Where do yall sell scripts

steep rose
near wadi
#

the Asset Store

eternal needle
tawdry quest
whole gyro
#

Didn't use AI to learn sql won't use it to learn c#

tawdry quest
#

Good choice, it cant teach anything

steep rose
#

you can just go on github and probably find something for free even

tawdry quest
fierce geode
#

If you use the reverseFlow method for splines, make sure your splines aren't broken; otherwise (comparison between mirrored and broken splines), otherwise the splines go crazy.

dusty shell
#

I'm having a problem finding where to set the free Look default center to. it keeps on reseting the cam just below the waist and I want to raise that a bit. any idea how?

shell orchid
dapper harness
#

My visual studio I dont think is synced with my unity project cause it says "Miscellaneous files" I checked and visual studio editor is installed in the package manager and the external tools script editor is set to visual studio, anyone know why this is? Mb if this is the wrong channel btw

north kiln
dapper harness
north kiln
#

And you've tried the

If you are experiencing issues
Section's steps?

dapper harness
#

ye

teal viper
# dapper harness ye

Assuming you did everything correctly and it still doesn't work, try regenerating project files.

frosty hound
#

!collab

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

arctic ridge
#

Kind of a simple question, but how can i get the parent object of a child object, specifically so i can destroy the parent? The only thing i can figure out how to do is to get the transform, which cannot be destroyed

eternal needle
arctic ridge
#

Thanks!

tame valley
#

Hmm i have a question, if i want a panel in canvas to fit the text , but also have panel size limit, how should i do it properly?

slate badge
#

My character is currently standing on a rotating wheel but the problem is that its not dragging my character with it when my character stands on it

#

any solution?

stoic juniper
#

hi so I need help with something I am trying to export anim files to fbx but everytime it's imported in blender the animation doesn't play and is wrong and is not attached on the model am I doing something wrong?

eternal needle
stoic juniper
eternal needle
# slate badge how do i do that

the first thing id start with is detecting when objects are on the moving platform, then applying the same movement that the platform does to those objects. many tutorials will show you just parenting the object under the platform, which is really not ideal in a ton of cases

tawny notch
#

Which ide is best for unity, im using vs code right now

scenic maple
#

whatever you like best

cyan token
burnt vapor
#

Visual Studio works best but just for Windows (or Mac, but I believe it's discontinued)

#

Rider also works best, is cross platform, but requires payment

#

There's the EAP for Rider which means you could get it for free, assuming you read the license

#

VSCode also work but it has always had bas support. However, I believe it is better nowadays so it might also be a good option now (haven't checked)

#

Also next time, use the proper channel pls

tawny notch
burnt vapor
# tawny notch Which one

On second thought, this channel is probably also fine. People usually post code questions about actual code, not working with code

wooden lance
#

I have been trying to get my save and load game to work for an inventory system script I wrote but nothing seems to save the items in my hotbar or inventory. I've tried everything. If anyone got a spare sec I would really appreciate a second opinion hahahah

languid spire
eternal falconBOT
burnt vapor
wooden lance
clever oar
#

Hello. I have little problem with unity. When I write for example System.IO, I don't see options in visual studio. Where can be problem? 😬 Same with other classes etc

burnt vapor
eternal falconBOT
clever oar
burnt vapor
wooden lance
#

All u need is the inventory system and load system I think

#

Basically I load my SampleScene from my Main scene and I save the game in the SampleScene. When I try to load my samplescene from my mainscene with my loaded data everything is setup nicely except for my inventory 😦 It just doesnt save

burnt vapor
#

What you should do is retrace the steps up until the saving, and see where it goes wrong

#

See if the data is passed into the part that saves, see if the savng happends, then see if the data is saved

#

When that's done, do the same but in reverse for the loading

#

Retrace your steps until you find out where it breaks

wooden lance
#

Ye I know my guy, I've been doing that for a couple of days. The debug log shows that the item is saved, in the right index, etc. So I am kind of at a loss

burnt vapor
burnt vapor
#

Set a breakpoint, follow the steps the code does

#

See if data comes in, see if it's valid, see if it gets passed down to the relevant dependencies that need it

#

The debugger allows you to view the contents of variables

#

With all due respect, the time it takes to do this will be shorter than what it takes for anybody here to read the hundreds of lines you shared

#

Once you know what specifically goes wrong, you can share that part of the code in here in case you don't know the reason

wooden lance
#

No I totally get it man I am just new to this I am already very gratefull for you taking the time for this πŸ‘

burnt vapor
#

NP

slate badge
#

can anyone help me? I have a rotating obstacle in my game but the player doesnt get affected when it stands on it

languid spire
copper crest
#

hey i need help

languid spire
#

!ask

eternal falconBOT
fading vigil
#
        {
            var slash = Instantiate(slashPrefab, bulletSpawnPoint.position,Quaternion.Euler(-90f, 0f, 0f));
            slash.transform.Rotate(-90f,0f,bulletSpawnPoint.transform.rotation.z,0f);
            slash.GetComponent<Rigidbody>();
            cooldownAttack = cooldownNormal;
        }```
#

can anyone figure out why my rotations are messed up

#

the z axis just won't work

slender nymph
#

bulletSpawnPoint.transform.rotation.z
transform.rotation is a Quaternion which is notably not in degrees. also what overload of Transform.Rotate takes 4 floats?

copper crest
#

!ask

eternal falconBOT
slender nymph
copper crest
#

lol sorry

copper crest
# slender nymph you're meant to *read the bot message* not parrot the command

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

public class PipeSpawnerScript : MonoBehaviour
{
public GameObject Pipe;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
    Instantiate(Pipe, transform.position, transform.rotation);
}

}

#

just help me ;-;

slender nymph
#

!code

eternal falconBOT
slender nymph
#

and also you haven't actually asked a question yet

burnt vapor
copper crest
grand badger
copper crest
#

howw

#

idk

#

its my first time coding something

slender nymph
copper crest
#

😭

#

the prefab is already assigned tho

languid spire
eternal falconBOT
#

:teacher: Unity Learn β†—

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

slender nymph
burnt vapor
grand badger
copper crest
#

help pls i need flarby brid gam

grand badger
#

no that's not the correct place to assign

copper crest
#

so where i assign

#

pls tell

burnt vapor
grand badger
#

also, can't tell if you're trolling

copper crest
#

IM NOT ONG

burnt vapor
#

My guess is that it logs twice, and then you will find the wrong one

#

And stop sending spam, just do it

grand badger
#

you need to select the object that has the PipeSpawnerScript Component, then assign the Pipe field there

grand badger
copper crest
#

OH GOT IT

#

THANKS

#

😭 πŸ™

fading vigil
#

So context: I changed the z internally with a script code yet the object won't move rotations at all when spawning

#

This is the code that changes the rotation internally

north kiln
scenic maple
#

also crediting a pinterest account for being the artist of your pfp is crazy

charred spoke
#

Not a code question and also wtf just cut it out yourself

copper crest
#

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

public class PipeSpawnerScript : MonoBehaviour
{
public GameObject pipe;
public float spawnRate = 2;
private float timer = 0;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
    if (timer < spawnRate)
    {
        timer = timer + Time.deltaTime;
    } else
    {
        Instantiate(pipe, transform.position, transform.rotation);
    }
    

}

}

the piller keeps spawning although i added a timer. why is this happening?

languid spire
#

read the code, what would you expect to happen once it's Instantiated once?

copper crest
#

idk spawn another pillar ig (lol im dumb)

languid spire
#

also POST CODE CORRECTLY, you have been told before

silk night
#

Oh boy, executing that code looks like fun, creating a pipe once per frame πŸ˜„

#

you need to reset the timer πŸ˜„

burnt vapor
#

Because your question doesn't even belong here. It's below beginner level

odd epoch
#

im trying to make a script that enables fog when my vr player walks into it, it doesnt work. why?

using UnityEngine;

public class FogTrigger : MonoBehaviour
{
    public bool enableFog = true;
    public Color fogColor = Color.black; 
    public float fogDensity = 1f;

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            RenderSettings.fog = enableFog; // Enable fog
            RenderSettings.fogColor = fogColor; // Set fog color
            RenderSettings.fogDensity = fogDensity; // Set fog density
        }
    }
}
atomic holly
#

Hello,
I want to create a system for attack with a bow and change the value of the power of the bow compared to the time the player stay click on the mouse. But, with I have done, my game crashed so I think I have an infinite loop.
The code :

    public void ClickHitWeapon(InputAction.CallbackContext context)
    {
        isRightClickHeld = context.ReadValueAsButton();
        Debug.Log("Click hit weapon");

        if (isCooldown) return;

        if (isRightClickHeld)
        {
            ArrowTimer();

            isCooldown = true;
            StartCoroutine(AttackDelay());
        }
        
    }

    private IEnumerator AttackDelay()
    {
        yield return new WaitForSeconds(currentWeapon.attackDelay);
        isCooldown = false;
    }


    #region Arrow System

    public void ArrowTimer()
    {
        while(isRightClickHeld)
        {
            timeRightClickHeld += Time.deltaTime;
        }
        ThrowArrow();
        timeRightClickHeld = 0;
    }

    public void ThrowArrow()
    {
#if UNITY_EDITOR
        Debug.Log("Throw Arrow");
#endif
        Vector3 position = SingletonManager.instance.playerTransform.position;
        position.x += offsetX * playerMovement.orientation;

        //If orientaion = 1, do nothing, else rotate the arrow of 180Β°
        Quaternion arrowRotation = playerMovement.orientation == 1 ? Quaternion.identity : Quaternion.Euler(0, 180, 0);

        GameObject arrowGameObject = Instantiate(arrowPrefab, position, arrowRotation);
        arrowGameObject.GetComponent<ArrowCollider>().movementSpeedX = movementSpeedArrow;
    }
    #endregion
#

I precise that my input system that call ClickHitWeapon() is in pass through button

languid spire
#

yep, infinite loop right here

while(isRightClickHeld)
        {
            timeRightClickHeld += Time.deltaTime;
        }
atomic holly
burnt vapor
burnt vapor
#

It doesn't end

#

You need to ensure it checks each frame

#

Add yield return null; inside the while loop

languid spire
night valve
#

Right why don't you use coroutine like you did in cooldown

burnt vapor
#

C# / Unity uses threads and you are hogging the main thread with a while loop that runs infinitely on a single frame

#

So either you add that yield line and check once per frame, or you run it in a background thread (which is a bad solution here!)

#

Actually, this is wrong

#

Your method is not even a Coroutine

atomic holly
atomic holly
burnt vapor
#

There's a lot wrong with this code

#

Make the method a Coroutine, add the yield

#

Then you want to call StartCoroutine for the method in ClickHitWeapon

languid spire
#

or read the button INSIDE the while loop

burnt vapor
#

Lastly, assuming you want to trigger the cooldown after, add isCooldown = true; and StartCoroutine(AttackDelay()); at the end of the method, or have another coroutine call ArrowTimer and wait until it is finished, and then call those

#

Regardless, your current code is not going to do what you want at all

atomic holly
night valve
#

You don't have to always yield WaitForSeconds, you can return null until button gets released

wheat coral
#

why do we write List<ClassName>() waypoint = new List<ClassName>(); in unity
While I wrote the code like this: List<ClassName>() waypoint; and it still works fine for me.
When I use the data in it and also it is [SerializeField]

eternal needle
#

Also you dont need to type the Type again,
= new(); will be fine there

cosmic dagger
eternal needle
cosmic dagger
wheat coral
wheat coral
rich adder
cosmic dagger
#

think of every field as an object that stores data based on its type, and that data is located at a specific address in memory . . .

wheat coral
night valve
#

If you add field of type List, I guess you need a list, not only the declaration of field that can "hold" that list

eternal needle
cosmic dagger
wheat coral
#

By the way where I can get the list of reference types and value in unity

rich adder
cosmic dagger
rich adder
#

πŸ”½

eternal falconBOT
cosmic dagger
#

damn, thought i added the ! . . . πŸ˜”

night valve
#

Yeah, you should decide to [SerializeField] when you actually need that field to be serialized. If you don't, but need initialized list, use new()

rich adder
wheat coral
#

Ok thank you guys that helps a lot

#

Btw from where should I learn DOT

rich adder
cosmic dagger
#

oh, you mean DOTS?

rich adder
#

I should hope not, so early for dots lol

tulip nimbus
#

Why cant i invoke my Event here? Im using UnityEngine.Events and it works fine like this on other scripts

rich adder
wheat coral
cosmic dagger
#

also, posting the error message would help . . .

rich adder
#

no definition defined invoke bla blah

wheat coral
rich adder
# wheat coral Dots yes

data oriented stack is pretty diffcult if you're new, but any resources can be found on the unity docs/manual and learn site

cosmic dagger
eternal falconBOT
#

:teacher: Unity Learn β†—

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

tulip nimbus
rich adder
#

turbo makes games also has good tutorials on DOTS

wheat coral
rich adder
#

why do you want to write DOTS so badly lol

cosmic dagger
rich adder
#

are you having performance issues?

night valve
#

Imho dots are good start instead of monobehaviors, BUT you NEED to know a C# better

night valve
#

If you prefer to learn unity along with c#, start with normal OOP

wheat coral
#

Ok

rich adder
#

I mean you can use it, I just wouldn't recommend it until you learn more coding

#

there is a lot of different concepts that are not regular to oop

night valve
rich adder
#

yes its very good for performance, but writing the code is very boilerplate in the beginning and annoying. Not the best for beginner

night valve
#

Was thinking more about not getting narrowed mindset by mono:p

#

I struggle with this a bit now

rich adder
#

imo, at the end of the day you're making a game so yes performance is important but if it hampers progress then its not worth the time unless you really having performance issues that traditional means do not solve

night valve
#

That's right. But if it is only about learning unity, eventually you end up using mb anyways, but can start learning in different order

rich adder
#

true, i just see it as you gotta learn the "wrong way" first to see the major benefits in the "correct way"

dark laurel
#

I wouldn't even worry about DOTS until you know why you need it imho

#

I have games with "thousands" of instances of items for mobile and they work just fine.. migrating or doing it in DOTS wouldn't improve performance since we're already fine at 60fps and would greatly increase complexity

#

"greatly" if you're a Unity beginner, that is

wintry quarry
#

To play devil's advocate - even after reaching your framerate targets, improving performance still:

  • Reduces energy usage (reduced battery drain) of your application (which user's might not notice at first but will eventually)
  • makes it accessible to even more devices
#

but noit worth entertaining those goals without concrete targets either

rich adder
#

Btw I was mainly referring to ECS when speaking dots, cause dots and mb work together just fine so its not like we choose one or the other luckily unity can use both and we can mix GOs with ECS or just use things like JOBS which are very useful MB or not

night valve
#

Agreed, can't think of advantages of doing "pure dots" for a game. But making a system to handle specific area of that game just to offload CPU, even if not necessary, isn't bad idea imo

final kestrel
#

I had to make an init scene and put my singletons for data persistence and scene management in it so the data in them would be ready for fetching beforehand. When I start the game from init scene, I load the playable scene additively and set it active. I log the active scene and yes it successfully makes the newly loaded scene active. My problem is that I cannot interact with anything when I'm loading from init scene. And the lighting settings are all messed up. Why is that?

rich adder
final kestrel
#

Yes they are DDOL.

#

This is the init scene objects

rich adder
#

and also which do you mean when saying

cannot interact with anything

#

what are you trying to interact with ? what's supposed to happen

final kestrel
#

I set up interactables in my playable scene that I can interact with. When I start playing from my playable scene it all works fine. I can interact with the objects and such.

#

Like a fridge. I can open and close its door.

rich adder
#

did you check the console for errors?

final kestrel
#

These are the only errors I'm having

rich adder
#

hmm seems like some objects are not being carried over in DDOL unless their parent is already ddol

final kestrel
#

I also check the layers of my interactables to see if they change or anything but no everything looks fine

rich adder
#

unless you specifically coded to do so

final kestrel
#

Nope i did not code anything of sorts.

#

Maybe changing scene messes something up

#

thats why I checked

rich adder
#

clear

#

but the "why" is why you debug lol

rich adder
final kestrel
#

The ones that carry over to my playable scene. They are not child to any other object

rich adder
#

ok and no camera?

final kestrel
#

Camera does not carry over. I have my camera set up in the playable scene

#

I mean i did not anything about it. Does it usually get carried over?

rich adder
#

nah just wondering if you had that on DDOL

#

see if the interactions script is running and put debugs see whats happening inside when new scene switched

final kestrel
#

Like when I delete the camera from the init scene. My playable scene camera changes angles and stuff

rich adder
#

I'm not sure how one would affect the other

final kestrel
#

I do not know either

rich adder
#

are you saving values n stuff?

final kestrel
#

Just simple booleans about the game checkpoint.

rich adder
final kestrel
#

Wait why the hell is my camera coming with me

#

There is one camera in init scene.

#

And there is another in my playable scene?

rich adder
#

ah well there you go, you might be raycasting from the wrong camera..

rich adder
final kestrel
#

Yeah when I disable the first camera. The interactions and all works now. The question is

rich adder
#

I did ask about if it was being brought with DDOL. Check all the ddols you're making

final kestrel
#

I start my game by playing a timeline in the playable scene. Why does disabling init scene camera changes the angle?

final kestrel
#

Like I only have 2 3 ddols in scene and there is nothing related with camera being carried over

rich adder
final kestrel
#

These three come with me from init scene

rich adder
#

are those the only DontDestroyOnLoad you have in script?

rich adder
#

you just made new one active, possibly

final kestrel
#

Well I cannot unload the init scene. I have to have the game data ready all times. Its like, I start a new scene, new scene checks the data if necessary and loads the game accordingly

#

If i try loading the data and make my scene act on it, the data does not get loaded immediately leaving with exceptions.

rich adder
#

what is even the point of DDOL then..

final kestrel
#

I mean it may be wrong but thats what I could come up with.

#

So you're saying they are already in the init scene why carry them over with you. They will already be available

rich adder
#

if you dont unload the scene objects don't even get unloaded there is no point in DDOL

final kestrel
#

Yeah never thought about it damn

rich adder
#

DDOL is a scene that just never unloads (between scene changes)

final kestrel
#

So like they will be loaded at start in init scene and stay there for me to read and write. Makes sense

rich adder
#

once they are in DDOL(code) they should be put automatically in DDOL(scene)

#

so its kind of seamless

final kestrel
#

Hm okay. So what should I search for about the lighting issue?

rich adder
final kestrel
#

All right. I am also new to the lighting things. I must research. Thanks a lot for your help. You're the best.

olive galleon
#

if I want enemies and players to have health should I make an interface that they can both inherit? Or is there a better way to approach making a generalized health system without using interfaces?

rich adder
#

just use a Health component?

languid spire
olive galleon
#

Ty!

rich adder
sage abyss
#

Can I get the length of ReadOnlyArray<>?

rich adder
#

wouldnt it just give you .Count ext method, cause it implements IEnumerable ?

sage abyss
stone pilot
#

I've a problem, why at the start of the game I can adjust the volume but when I start the game and return to the main menu I can't adjust it anymore?

#

(if the code is needed please tell me)

rich adder
#

well yeah, we can only guess without seeing code/setup

#

presumably some null reference

stone pilot
#

Alright, so the adjusting volume is just a scroll bar, and when you return to the main menu this is the code

{
    if(Input.GetKeyDown(KeyCode.Escape))
    {
        PlayerPrefs.SetInt("LoadSaved", 1);
        PlayerPrefs.SetInt("SavedScene", SceneManager.GetActiveScene().buildIndex);
        SceneManager.LoadScene(0);
    }
}```
languid spire
#

and what does any of that code have to do with the volume?

rich adder
stone pilot
rich adder
#

we need to see the code that gets Input from the slider and outputs to the audio volume

#

guessing some reference in scene switch breaks

stone pilot
#

Well there's no code ig.. I added the music prefab and set the volume in the slider

#

Is there a better way to do it or smh else?

rich adder
#

ideally a persistend audio ddol object + audio manager

rich adder
#

unless it cant find Music anymore somehow

#

if you mean its not saving the same value then see above

stone pilot
#

That's the problem, I think the problem is with the switching scene code

stone pilot
#

If I try adding volume saving will that works?

#

I found a script on reddit I'll try making that

rich adder
stone pilot
#

You can see the video I've sent up

rich adder
#

did you check if you have any errors in console when you switch scene back?

stone pilot
#

Not really, there's no errors at all

rich adder
#

can you show the Music object inspector, when you switch back to that scene

stone pilot
#

Alright, I'll record a video

flint crow
#

!bug

eternal falconBOT
#

πŸͺ² To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.

πŸ“ If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click β€˜Report a problem on this page’!

πŸ’‘If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.

For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting

flint crow
#

!help

rich adder
#

why do you want

flint crow
#

bro i installed unity for the first time and i want to try ot learn it but when i click create project

#

it says

#

unable to create project

rich adder
flint crow
#

ok thx

stone pilot
rich adder
#

Ah its in a DDOL

#

pretty sure the slider is now referencing the first one instead

#

the slider in the scene has no idea you want the audiosarce thats already playing

stone pilot
#

Oh yeah I get it now but to be honest idk how to fix lol
this is the audio script if it's needed

{
    private static Audio audioinstance;

    void Awake()
    {
        if(audioinstance != null)
        {
            Destroy(gameObject);
        }
        else
        {
            DontDestroyOnLoad(transform.gameObject);
            audioinstance = this;
        }
    }
}```
vast sparrow
#

Hi I'm new to coding and I have some questions first what ways are the best to learn coding second are there easy way to learn it and lastly are is there any beginner friendly project that I can try

rich adder
stone pilot
#

I can't really get it, I've never made a audio script and this kind of thing before, could you explain more please?

rich adder
#

wdym you never made an audio script, why did you write Audio in the class and use a singleton

eternal falconBOT
#

:teacher: Unity Learn β†—

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

torpid hamlet
#

Hello, quick question: I found this character controller on the internet: https://pastebin.com/RXZ1dXgw. I was wondering, is there any way I can get this code explained to me? Since I don't just want to copy and paste code, I want to partly understand what I'm doing.

cosmic quail
torpid hamlet
#

Most that I found only gave you the code in 30 seconds and flipped you off, but I'm sure there are some that explain?

#

Tried asking chatgpt aswell, it didn't give out bad answers surprisingly

languid spire
steep rose
#

most things can be explained via docs

torpid hamlet
languid spire
#

!docs

eternal falconBOT
fringe kite
#

just why

languid spire
#

just why what?

fringe kite
languid spire
#

and how did you install it?

fringe kite
languid spire
#

right so you didn't bother to read the docs that specifically tell you not to do that

short hazel
#

Unity does not support NuGet, because it has the control over your C# project file. When you include a NuGet package, VS writes it to the project file, Unity detects the changes and rebuilds the project file entirely before recompiling. You lose the changes VS made

fringe kite
#

sorry

#

i watched yt tutorial and fixed it

fickle reef
#

Hey guys I was wondering if you’d know how to sort this error? I haven’t seen this type of error before

polar acorn
fickle reef
#

Where abouts is it? In inspector?

#

Yeah but which component? I can’t see it

polar acorn
#

Read the error

#

It tells you exactly which variable and component

fickle reef
#

Where is ground check variable? This is what I can see atm

polar acorn
shell orchid
#

how can i make my capsule not slow down when i walk up slopes and not go extremely fast going down slopes?

#

my script aint working

#

rigidbody

#

ok

#

theres no gravity in my script

#

i have drag

#

ok

#

where would i add that script

#

im just tryna add hills

#

oh

#

ok

molten dock
#

Could I be recommended a good save and load system tutorial

molten dock
#

I think this recommendation may be biased lol

#

Ty though I’ll watch

rich adder
#

thanks!

upper forge
#

I was wanting to update my project to Unity 6, but im afraid its going to mess it up as Ive never done this before? if i just open the project with unity 6 will it mess it up even though thats not the orginial version its on?

deft grail
rich adder
upper forge
#

Yeah i have it on GIT so ill just do last commit and try it out then Thanks!

#

What you mean unity flash screen?
Im still on 2022.38f1 lmao

rocky canyon
#

haha, did i hear somene say Unity6 is the most stable and performant version of Unity?

#

in what bubble?

torpid jetty
torpid jetty
#

My own (admittedly small) projects converted without any issues.

rocky canyon
#

Marketting Hype

rich adder
rocky canyon
#

id def recommend 2022 for stable

#

but not having a splash screen is a +

#

that said.. i am in the process of porting over some of my projects to 6.. but i dont expect it to go 100% smoothly ofc

torpid jetty
#

That wasn't a "yes this will work" broad statement, but sure. Of course YMMV.

rocky canyon
#

ya, thats teh best route u can take tho.. duplicate ur project open it in Unity6 and see for urself

rocky canyon
#

i just wanna get rid of the early releases i have

torpid jetty
#

Ah, gotcha

rocky canyon
#

no need for them anymore

rich adder
#

i meant to @queen adder

unity 6 is the most stable and performant version of unity and you can set unity flash screen as optional

torpid jetty
#

Thanks for clarifying, I was a bit confused XD

#

I haven't been able to verify this for myself, but my understanding is that U6 should improve overall performance in some respects, especially with the lighting system?

#

At least that's the impression I've been given, mostly based on just a few YouTube videos that have talked about it.

rocky canyon
torpid jetty
#

I didn't have many issues during the preview period, so it's what I'm using for my own stuff at the moment. (again, small projects, so that probably doesn't say much)

#

I have high hopes for whenever they get around to updating the engine from mono to .net core, though... but it'll be a while, unfortunately.

upper forge
upper forge
#

With the UI BUttons by holding it down and on release you stop

teal viper
upper forge
#

RB Character controller

teal viper
keen owl
#

Don’t you need subscription to disable it?

slender nymph
keen owl
#

How do you switch to unity 6?

slender nymph
#

by downloading the unity 6 editor and opening your project with that

keen owl
#

You can always switch back right?

rich adder
keen owl
#

Figured it out as soon as I left discord lol

#

Thought it was an update in the actual editor

steep rose
#

you might want to save your project first before you go to unity 6, it could introduce a lot of bugs

keen owl
#

What kind of bugs? Issues with editor or actual project/mechanics?

cosmic dagger
vague gust
#

I have a 'public Text' variable in my code to display ammo and it works just not with TMP

#

would anyone know why

vague gust
#

that would make sense

#

thank you

glad comet
#

How do I put maxvectorangle into the random.range parentheses correctly?

rich adder
#

like awake / start

keen owl
glad comet
#

Random.Range(0, 2); will return 0 or 1 right?

zenith cypress
#

Yes

bitter sage
#

Hi, I have a Steam Integration cs script in my project that seems to throw up a compiler error only for Android / Webgl when trying to export them. I'm assuming because it's not compatible with those platforms.

Is there a way to have those platforms ignore that script, instead of me having to literally delete the script off my project each time?

languid spire
queen adder
#

help my tank top is sideways from a follow mouse script

night valve
#

!ask

eternal falconBOT
night valve
#

There is a lot of things that could be wrong, we can't determine what based on a single image with no code provided

#

First of all

frank zodiac
#

Its been ages and they still havent updated the Junior Programmer pathway. Is it outdated or still applicable with Unity 6 today?

eternal falconBOT
#

:teacher: Unity Learn β†—

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

silk night
#

Specific class names may have changed here and there but Unity 6 is mostly the same to a junior dev

#

the deeper you go the more likely it is to find differences πŸ˜„

frank zodiac
frank zodiac
#

Last time I used Unity was when 2021 LTS was released so Im kinda trying to refresh my skills lol

silk night
#

If you want to be sure they have time to update, stay on 2022.3.x for now

#

its by no means outdated

#

and knowledge transfers pretty easy

frank zodiac
#

Except the input system

silk night
#

You still have both available

#

even in unity 6 you have legacy, you can also choose to install the new one in 2022

#

only the default has changed πŸ˜„

#

But i would say it even makes sense to take a small sidequest and learn the new input system

hexed terrace
#

When following a tutorial, you're usually best off using the same version of Unity that the tutorial uses - otherwise you will end up wasting your time trying to find the same menu option/ tick box/ bool/ field/ etc

frank zodiac
#

Unity Learn is too buggy as a website

frank zodiac
silk night
frank zodiac
#

When I wanted to paste in my WebGL game for example, it gave me a "project_unsupported_url" error

#

I couldnt complete the pathway

#

And its very very slow as well

silk night
#

Oh i never touched the webgl stuff

#

but also not slow for me

frank zodiac
#

You must be lucky then

hexed terrace
eternal falconBOT
#

:teacher: Unity Learn β†—

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

fickle wagon
#

@frank zodiac The same issue loading stops at "Linking build.js(wasm)" for 20 to 25 minutes every-time

fickle wagon
#

I have tried to change to a "smaller build" and "disk size" in the project setting but I still same problem.

sturdy wharf
#

hey i need some help... i have a stickman image, and i have sliced the arms and legs and stuff all separately, and now i want to rig it, but i can only select one slice at a time (in the attched image, i have the torso selected) and when i try to rig it i can make the bones go across to the other slices. ive searched everywhere and idk if im just dumb. ive tried shift and cntrl slecting multiple but i just cant. if you could help that would be great!

sturdy wharf
#

pls

floral wren
sturdy wharf
#

but i need them to be connected so i can animate the stickman ?

#

like i need the rig bones to connect to one another

quiet ginkgo
#

I am trying to make the character jump
But when I press spacebar it plays the jumping animation multiple times
Can anyone help?

copper crest
#

which app should i use for learning c#?

fickle wagon
#

@quiet ginkgo Use trigger for jumping instead boolean

cosmic dagger
copper crest
night valve
cosmic dagger
cosmic dagger
calm adder
steep rose
echo sand
#
public CharacterController CC;
private Vector3 Gravity = new Vector3 (0,-9.82f,0);
private Vector3 Velocity = Vector3.zero;

void UpdateGravity()
 {
     Velocity += Gravity * Time.deltaTime;
     Debug.Log("Is Grounded: " + CC.isGrounded);
     if (CC.isGrounded)
     {
         Velocity =  Vector3.zero;
     }
     else
     {
         CC.Move(Velocity * Time.deltaTime);
     }
 }
``` did i do this correctly
#

tho "is grounded" is switching between false and true. even tho it works

hollow field
#

Is there an easy way to build things like walls and buildings without having to keep duplicating objects and aligning them manually?

steep rose
#

Probuilder and using the built in snap in unity, alternatively you can use blender as well

main karma
#

guys I have a very specific issue and I can only describe it with images... HOW DO I FIX THIS

#

as you can see

#

these 2 give me different characters than they should

steep rose
#

not in a code channel

main karma
steep rose
#

have patience

#

also there are more relavent channels other than code channels as well πŸ€”

main karma
#

thankfully I fixed it just now so yeah nevermind

steep rose
#

ask the question and see if it gets answered, but if you already did fix it you don't need to.

rocky axle
#

Hi, in the beginning of the junior programmer lessons they mention how microsoft visual studio can auto fill suggestions for C#, and show alternatives. I can't figure out how to set this up. Can anyone point me in the right direction?

eternal falconBOT
rocky axle
snow apex
#

when working with events, is it common practice to unsubscribe from the event i subscribed to once its no longer used?
lets say i have a falling object called disc, which upon finishing its fall it fires an event "stoppedfalling". everytime i create the disc i should subscribe to the event, and then wait for the event to fire, where i start it by unsubscribing the object from the event since i assume itll never be falling again once its in place

#

specfically unsubscribing from within the same event

cosmic dagger
snow apex
#

    private void SpawnedDisc_StoppedFalling()
    {

        // Detach Event
        spawnedDisc.StoppedFalling -= SpawnedDisc_StoppedFalling;

        // Code
        //
        //
    }
#

im a complete beginner, whats on enable and on disable?

#

is it scopes like start and update?

cosmic dagger
#

they are Unity methods. you place the subscribe code inside one method, and the ubsubscribe code in the other method . . .

snow apex
#

of the object definition

cosmic dagger
#

OnEnable is automatically called when the GameObject is enabled. the same applies to OnDisable (but obviously the opposite) . . .

snow apex
#

gotcha, its sorta like the enter and exit dunders of python classes

cosmic dagger
snow apex
#

ok, another question, what if i cant access or modify the object that im trying to subscribe & unsubscribe?

cosmic dagger
#

you mean the falling object?

cosmic dagger
snow apex
cosmic dagger
#

what code do you have for subscribing right now?

cosmic dagger
snow apex
#

i have 2 objects i cant access..
an igrid and a idisk

the igrid is spawning the idisk. after its spawned i keep it in a variable and immediately subscribe it. but then when i spawn the next one for some reason the event that is subscribed is fired twice for the one i just subscribed to, and once for the old one i subscribed before. i found the solution by unsubscribing from the inside of the subscribed method after its fired, but i was wondering if it was a good practice

echo sand
#
public CharacterController CC;
private Vector3 Gravity = new Vector3 (0,-9.82f,0);
private Vector3 Velocity = Vector3.zero;

void UpdateGravity()
 {
     Velocity += Gravity * Time.deltaTime;
     Debug.Log("Is Grounded: " + CC.isGrounded);
     if (CC.isGrounded)
     {
         Velocity =  Vector3.zero;
     }
     else
     {
         CC.Move(Velocity * Time.deltaTime);
     }
 }
```any idea why output is switching between true and false
snow apex
# cosmic dagger oh, then you are fine . . .

subscription

...
...
                // Spawn Disk & Assign Post-Spawn Logic
                spawnedDisc = grid.Spawn(userDisc, col, row);
                spawnedDisc.StoppedFalling += SpawnedDisc_StoppedFalling;
...
...

unsubscription

...
...
    private void SpawnedDisc_StoppedFalling()
    {

        // Detach Event
        spawnedDisc.StoppedFalling -= SpawnedDisc_StoppedFalling;
        
        // Code
        //
        //

    }
...
...
#

like that

cosmic dagger
silver cobalt
#

!code

eternal falconBOT
cosmic dagger
snow apex
#

its active and static

#

it doesnt move until its destroyed when the game is restarted

#

that part isnt implemented yet

silver cobalt
#

Hello everyone :-),
Im wondering why my player isn't properly rotating towards the mousePosition.
when i attach this script to the player object it creates a weird rotation effect. Its responding to the mouse Movement but it doesnt properly rotate towards the mouse Position. Please Help.

using UnityEngine;

public class PlayerRotation : MonoBehaviour
{
    [SerializeField] private float rotationSpeed = 5f;
    [SerializeField] private LayerMask groundLayer;
    private Camera mainCamera;

    private void Awake() {
        mainCamera = Camera.main;
    }

    private void Update() {
        RotatePlayer();
    }

    private void RotatePlayer() {
        if(TryGetMousePosition(out Vector3 mousePos)) {
            var dir = mousePos - transform.position;
            dir.y = 0;
            transform.forward = dir;
        }
    }

    private bool TryGetMousePosition(out Vector3 position) {
        var ray = mainCamera.ScreenPointToRay(Input.mousePosition);

        bool success = Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, groundLayer);
        position = hit.point;
        return success;
    }
}

snow apex
#

another question, does it matter where i define my variables? i find it most comfortable to define class wide variables for my script. is that bad?

cosmic dagger
timber tide
echo sand
silver cobalt
timber tide
#

If that doesn't solve it, you may want to add on the player position + direction to localize the direction. I forget

cosmic dagger
# echo sand this happens when its grounded

your code only logs the value of CC.isGrounded. we can't determine anything from this. you need to check/show us the code that determines how the player is grounded . . .

echo sand
#

it has its own "isGrounded" variable

silver cobalt
#

and thank you agaain for the help

finite dove
#

and specially how you tell / invoke it to another code

snow apex
finite dove
cosmic dagger
# echo sand its Charactercontroller

it can be a collider issue. make sure it's properly setup. are you on a slope? if so, slopeLimit could be the problem as well. is your character just on a flat surface?

timber tide
cosmic dagger
snow apex
#

gotcha

#

thanks for the help!

cosmic dagger
silver cobalt
#

and also how the beaviour of the mouse influences the rotation of the pllayer with the current code setup?

timber tide
#

I'd make sure the position is correct from the raycast, and print out the transform position and direction and make sure those values are correct

#

sometimes when I'm not sure if the values are lining up I'll stick what I'm working on at the origin such that I know that (0, 0, 1) is forward in both the local and world direction

finite dove
timber tide
cosmic dagger
snow apex
#

again total beginner πŸ˜„

cosmic quail
snow apex
#

im subscribing on the instanced object

#

i tried instancing on the spawnDisc before i assign to it an instance but that didnt work

#

prolly did something wrong?

snow apex
#

well maybe not a total beginner, just a total beginner with unity

#

and c# lol

cosmic quail
# snow apex why not?

its kinda difficult for a beginner, theres a reason beginner tutorials on youtube never use them

snow apex
#

well im familiar with the idea of events, just not how to implement them in unity

#

i think its the right solution for the use case im trying to implement

#

but anyway this is for a job interview, its a home assignment so i want to do it with industry standard approach

#

so its worth putting my time into figuring it out right now

silver cobalt
#

i figured it out. the problem lied in the fact that i was using a render texture on my cam to achieve a pixelated effect but the mousePos wasnt accounting for that

finite dove
#

i mean subscription just like Radio, you send the radio then if someone like it it will continue hear the radio talking until it finish.

cosmic dagger
# snow apex what do you mean?

no, i read the code wrong. it's hard to see when all broken up.

  • the instance created is spawnedDisc
  • then you access the StoppedFalling event from spawnedDisc
  • SpawnedDisc_StoppedFalling from this script is subscribed to the StoppedFalling on spawnedDisc
    i thought SpawnedDisc_StoppedFalling was a method from the spawnedDisc instance . . .
snow apex
#

ah no, its another event of the disc that has been spawned inside the subscribed method of ColumnClicked

#

so basically i gather the information i need for spawning a disc, reach a scenario that requires a spawned disc, then i spawn disc based on an event that is subscribed to the game board which broadcasts the fact and location of what column is clicked.
that results in a spawned object that will communicate when it arrived at its slot

hollow forum
#

sorry if stupid question, why is the capsule in the ground, what should my center be because i thought it should be half of the height

slender nymph
#

for starters, the CharacterController is already a capsule collider. this is also not a code question

rich adder
hollow forum
#

thanks

queen adder
#

its rectangular on 2d if that matters

rich adder
queen adder
#

second, firing up unity

#

this is the code

#

and the thing is instead of maintaining a pace and spinning around infinitley it slows down and stops at abt 90 degrees

#

now i dont really understand quanternions so and explanation would be great

rich adder
#

yes because Slerp is going from a start rotation to a target rotation

#

if you want to rotation just do
transform.Rotate(0,0, horizontalInput * rotateSpeed * Time.deltaTime)

#

also configure your IDE

queen adder
rich adder
#

btw Quaternions are just representation of rotation in 3D space

queen adder
#

yeah just out of curiosity since i didnt set it

rich adder
#

just know you need to work with Euler angles -180 to 180

#

using quaternion for rotations prevent issues with gimbal lock

Two of the rotation axes become parallel to each other, meaning a rotation around one axis effectively affects the other, causing a loss of independent control over one degree of freedom.
https://en.wikipedia.org/wiki/Gimbal_lock
(common issue with eulers)

queen adder
#

alright ill remember that thx alot!

queen adder
torpid hamlet
#

How can I make another object be actie (appear), after player collides with some object? I have a plane and sone text behind the player and I want them both to just appear (be active) after the player collides with some cube on the ground

#

I know it's something with OnTriggerEnter

coral flame
slender nymph
eternal falconBOT
zealous junco
#
using System.Collections.Generic;
using UnityEngine;

public class Controller : MonoBehaviour
{
    public float speed;
    public float maxSpeed;
    public Rigidbody rb;

    void FixedUpdate()
    {
        float vertical = Input.GetAxis("Vertical");
        float horizontal = Input.GetAxis("Horizontal");

        var movement = transform.forward * vertical * speed;

        rb.AddForce(movement, ForceMode.Acceleration);

        if (rb.velocity.magnitude > maxSpeed)
        {
            rb.velocity = rb.velocity.normalized * maxSpeed;
        }
    }
}

I made this script for a rigidbody FPS controller, but when I test the position values change but the actual object appears to not move.

deft grail
#

especially if you have a 100x100 for example floor thats full white

#

its hard to tell if your actually moving

zealous junco
#

The ground is changed to a dark grey and the I havent messed with the camera

deft grail
zealous junco
#

Still nothing

#

could it be that Im using an older version?

deft grail
#

is your position frozen maybe on your rigidbody?

zealous junco
#

No I had the rotations froze

deft grail
zealous junco
toxic cloak
#

i have recently updated to unity 6 and i cant seem to find rigidbody2d.velocity() did i miss something they changed?

deft grail
#

linearVelocity

toxic cloak
deft grail
cosmic dagger
toxic cloak
steep rose
#

you could also use google

toxic cloak
steep rose
#

LinearVelocity?

#

Im looking at it right now

toxic cloak
naive flare
#

Anyway, if you use Rigidbody.velocity your code editor should tell you to use linearVelocity instead, something like "'Rigidbody2D.velocity' is obsolete: 'Please use Rigidbody2D.linearVelocity instead. (UnityUpgradable) -> linearVelocity'"

toxic cloak
cosmic dagger
cosmic dagger
steep rose
#

!docs

eternal falconBOT
obsidian granite
#

wdym "velocity()"?

rich adder
obsidian granite
#

ah

gleaming plaza
#

and then I have a moving version of pretty much the same thing and it like half works, but the particles don't change when the button is hit

obsidian granite
gleaming plaza
#

...the first video

obsidian granite
#

which particles? the ones around the triangles, or the ones on the floor?

#

what button is being hit?

gleaming plaza
#

the ones that appear when the greenish triangles disappear

obsidian granite
#

ah okay i gotchu, the triangles are the buttons, i thought u meant like a key on ur keyboard

#

make sure your variables are referring to the right thing

#

too often i've seen beginners have fields referring to prefabs under the assets folder instead of the actual instantiated object that they should be referring to

gleaming plaza
obsidian granite
#

yeah it be like that

#

all good

gleaming plaza
#

can't believe it took me forever to figure that out

hasty dragon
#

how do you put a scene as a variable

#

it says public Scene is deprecated

thorny basalt
#

Change it back to camel / pascal >:(

gleaming plaza
#

you mean...starting with a capital letter and using underscores? is that what that is?

cosmic dagger
#

probably came from C++ . . .

gleaming plaza
#

or just the underscores

cosmic dagger
slender nymph
# hasty dragon how do you put a scene as a variable

for runtime stuff you don't. you can use a string or an int. there are third party assets like NaughtyAttributes and OdinInspector which add stuff that allow you to pick a scene from a dropdown though, but it's still either a string or int

thorny basalt
#

This is a good place to start

#

Some teams use different conventions but that is what I personally follow

gleaming plaza
#

seems everyone uses camel case and suggests it. I use snake case because I haven't really seen anything in the language that uses underscores so they kind of stand out

#

...although sometimes it's inconsistent πŸ’€

teal viper
cosmic dagger
#

though, actually, if you have public fields, they should be PascalCase, similar to properties . . .

past herald
#

hey guy, I'm new in Unity. Could someone provide me some tutorial to start? Thank you so much UnityChanThumbsUp

ivory bobcat
plucky copper
#

Odd question, I'm quite new and am sure this is probaly really easy.

I need to swap a corpse's model to a Loot Bag on death (so this involves swapping the Mesh).

How do I go about this / where is this located in the official docs? Version 2022 if it matters.

#

If its not an appropriate question, I can ask in another channel.

cosmic dagger
plucky copper
#

So there is no swap mesh in place. Got it, thanks!

normal turret
#

Hey guys, what's up...?

#

I'm kind of new to Blendspaces in Unity, and Unity in general to be honest

#

The animations were working before but I changed up my code a bit and it stopped working somehow

#

Someone said that my code is stuck in the "Vertical Velocity" Blendspace (it has Jump, Double Jump and Fall in it)...I'm not sure why

#

This is my snippet of code for my animation logic

        //Animation Logic - Horizontal Movement
        if(horizontalMovement == 0) {
            sidAnimations.SetFloat("Horizontal Velocity", 0.0f); //Idle Logic
            } if(horizontalMovement != 0) {
                sidAnimations.SetFloat("Horizontal Velocity", 1.0f); //Walking Logic
                if(runningAction) {
                    sidAnimations.SetFloat("Horizontal Velocity", 2.0f); //Running Logic
                }
            }

        //Animation Logic - Vertical Movement
        if(verticalMovement > 0) {
            sidAnimations.SetFloat("Vertical Velocity", 0.0f); //Single Jump Logic
            if(jumpsLeft == 0) {
                sidAnimations.SetFloat("Vertical Velocity", 1.0f); //Double Jump Logic
            } else if(verticalMovement < 0) {
                sidAnimations.SetFloat("Vertical Velocity", -1.0f); //Falling Logic
                }
            }```
#

This is the value of horizontalMovement, basically just the X-values (after watching the tutorials on the new Input System)

#

I set the parameters Horizontal Velocity and Vertical Velocity (one for each blendspace), based on my player's axis movement

#

I'm not sure why the animation is basically locked in my Jumping blendspace...

fickle wagon
#

@frank zodiac I solved slower build time in Unity 2022.3.47f1 by applying these settings

spring skiff
#

Is there a way, how I can check those Inputs without creating 6 if statements?

If you know Minecraft, there is a Hotbar down for the inventory with 9 Slots you can target with your mouse wheel. But you also can just press the Number Keys to get directly to the Inventory Slot.

My inventory is similar to this, but instead of 9 Slots, I only need 6.

        bool _DirectSlotButton1Pressed = _controls.Player.Inventory_Hotbar_DirectSlot1Button.WasPressedThisFrame();
        bool _DirectSlotButton2Pressed = _controls.Player.Inventory_Hotbar_DirectSlot1Button.WasPressedThisFrame();
        bool _DirectSlotButton3Pressed = _controls.Player.Inventory_Hotbar_DirectSlot1Button.WasPressedThisFrame();
        bool _DirectSlotButton4Pressed = _controls.Player.Inventory_Hotbar_DirectSlot1Button.WasPressedThisFrame();
        bool _DirectSlotButton5Pressed = _controls.Player.Inventory_Hotbar_DirectSlot1Button.WasPressedThisFrame();
        bool _DirectSlotButton6Pressed = _controls.Player.Inventory_Hotbar_DirectSlot1Button.WasPressedThisFrame();

        if (_DirectSlotButton1Pressed)
        {
            _AktullerHotbarSlot = 5f;
            _Slider_Hotbar.value = _AktullerHotbarSlot;
        }
        if (_DirectSlotButton2Pressed)
        {
            _AktullerHotbarSlot = 4f;
            _Slider_Hotbar.value = _AktullerHotbarSlot;
        }
        if (_DirectSlotButton3Pressed)
        {
            _AktullerHotbarSlot = 3f;
            _Slider_Hotbar.value = _AktullerHotbarSlot;
        }
        if (_DirectSlotButton4Pressed)
        {
            _AktullerHotbarSlot = 2f;
            _Slider_Hotbar.value = _AktullerHotbarSlot;
        }
        if (_DirectSlotButton5Pressed)
        {
            _AktullerHotbarSlot = 1f;
            _Slider_Hotbar.value = _AktullerHotbarSlot;
        }
        if (_DirectSlotButton6Pressed)
        {
            _AktullerHotbarSlot = 0f;
            _Slider_Hotbar.value = _AktullerHotbarSlot;
        }
ivory bobcat
#

Poor copy and paste btw Inventory_Hotbar_DirectSlot1Button

spring skiff
#

Is there also a solution for the Input action Map to keep this also clean?
Instead of using 6 extra actions just for an alternative keybind for the Hotbar?

ivory bobcat
#

I'm not too aware of the new input system but you should be able to poll input as well if you're not liking the other two methods of acquiring input (event subscription and something other that I do not remember)

cosmic dagger
#

C# events (code), unity events (inspector), polling in Update (code) . . .

ivory bobcat
#

Not sure if manually loading would be considered creating... UnityChanThink

#

I'm assuming they would have to create the actions in Unity, export as json and reimport. Unless.. they simply write it in json...

zenith cypress
#

If you already have premade bindings I'd just put them in an array like Dalphat suggested with something like:

// rough example since it is very late for me lol
struct Foo {
  public InputActionReference action; // w/e the type is
  public int slotIndex;
  // constructor
}

private Foo[] _slotActions = new Foo[6];

void Init() {
  var playerMap = _controls.Player;
  _slotActions[0] = new Foo(playerMap.Inventory_Hotbar_DirectSlot1Button, 5);
  // etc
}

void Run() {
  foreach (var slot in _slotActions) {
    if (slot.action.WasPressedThisFrame()) {
      _AktullerHotbarSlot = slot.slotIndex;
      // do thing
      break;
    }
  }
}

Could simplify the premade actions into generated ones, but not sure how those work with things like the PlayerInput handler, would also have to manually enable/disable/dispose them

// actual binding name is probably wrong here
// can generate them in a loop
_slotActions[0] = new Foo(new InputAction("slot_0", binding: "<Keyboard>/1"), 5);
// etc

Food for thought anyhow πŸ˜„

spring skiff
cosmic dagger
spring skiff
spring skiff
#

I mean I have a Slider but this Slider is not for clicking on it, only staring.

spring skiff
# ivory bobcat Direct answer: An array and loop

The part with the array and loop...
Are you sure this will it not overcomplicate the script and make it even harder to read than 6 if statements, in case you will visit the script again in 4 years later or something?...

#

But I also run in an issue here with:

_DirectSlotButton1Pressed = _controls.Player.Inventory_Hotbar_DirectSlot1Button.WasPressedThisFrame();

Because I cant make an array in the new input system action map and how can I replace the "1" with a 2,3,4,5,6 in this loop of the "Inventory_Hotbar_DirectSlot1Button", if I can't make an array in the New Input System Action map?

        bool[] _DirectSlotButtonPressed_ARRAY;
        for (int i = 0; i < 6; i++)
        {
            _DirectSlotButtonPressed_ARRAY = _controls.Player.Inventory_Hotbar_DirectSlot1Button.WasPressedThisFrame();
        }```
scenic maple
#

You add the array of buttons as a field in your class and iterate over that

#
for (int i = 0; i < _buttons.Length; i++)
{
  if (_buttons[i].WasPressedThisFrame())
  {
    _sliderHotbar.Value = _buttons.Length - i;
  }
}
spring skiff
#

are we still talking about Keyboard Buttons or UI Buttons?

scenic maple
#

Whatever "Inventory_Hotbar_DirectSlot1Button" is

spring skiff
scenic maple
#

Just guessing based off the message. It's an array containing whatever type Inventory_Hotbar_DirectSlot1Button is

scenic maple
#

Just... Check in the code. Hover over the reference. It'll tell you what type it is. It's really not that complicated.

spring skiff
#

I mean its not a UI Button, it is more like a location-description of this here and I think I must have the option to make arrays in there first, before I am able to make arrays in the code realated to this.

#

Its like the New Input system was never made for putting it in arrays.

scenic maple
#

You can put anything into arrays

#

You have the buttons (or actions, whichever it may be) in code, clearly

#

Just use them there

#

I don't really get the confusion

#
class YourFunnyClass
{
  private WhateverType[] _buttons;

  private void Start()
  {
    _buttons = new[]
    {
      _controls.Player.Inventory_Hotbar_DirectSlot1Button,
      ...
    };
  }

  private void Run()
  {
    // loop
  }
}
spring skiff
#

The input itself is a bool in my case.
But putting it in a bool array would also need that I would be able to put the "Inventory_Hotbar_DirectSlot1Button" into an array, what seems to not be possible because this is part of the New Input System Map. Its more like a location than a variable. Its different to how you would threat a simple Unity UI Button.

scenic maple
#

Once more, you are supposed to put the button/action into the array

#

Not any kind of bool

#

Wherever you may be getting that from

scenic maple
spring skiff
scenic maple
#

It's 3 lines of code, how is it overengineered?

#

You could just as well use a bool array with the approach I suggested. But that'll waste more resources

spring skiff
torpid hamlet
#

What should I put in the OnCollisionEnter ()? Anything I put in gives me an error...

eternal needle
torpid hamlet
eternal needle
#

That's pretty unrelated to anything that was said above

torpid hamlet
#

Player walks over a so called "trap" (the trigger), and a plane then blocks their path backwards nd a text saying try again appears

#

Pretty simple, but this is actually my first ever script I wrote all by myself, so everything looks the same to me (everything is chinese)

teal viper
#

Then it wouldn't look like Chinese to you.

verbal dome
#

Or something close to that

torpid hamlet
#

Everything else is completely logical

teal viper
#

Unity doesn't change the programming language in any way. The only thing unique to unity is the API.

eternal needle
torpid hamlet
#

Might be a little misleading from my side here

scenic maple
#

collision : UnityEngine.Collision is invalid C# syntax. That's what caused the error.

teal viper
torpid hamlet
#

And that was probably right? I just didn't unchildren the text and wall from the trigger for it to work

warm garden
torpid hamlet
#

Now it works after all, got my shit togheter and realised what I was writing didn't make any sense.

teal viper
torpid hamlet
#

Went back on the docs, researched it a bit more and realised I had to use OnTriggerEnter (Collider other) (which actually makes sense?)

verbal dome
#

Unity used to support javascript, you were reading a really old post

torpid hamlet
teal viper
torpid hamlet
#

This time I want trigger since it's a trigger trap basically

#

And it works pretty good actually right now

burnt vapor
#

Your ide is supposed to auto complete known Unity methods for you

#

If you are trying to do this manually then I suspect your !ide is not configured. Configure it.

eternal falconBOT
burnt vapor
#

It is very easy to make mistakes with these methods since they don't have a lot of checks, but if it's not the same as what Unity suspects then it simply won't call it.

eager spindle
#

Is there any way I can get on-screen buttons to affect Input.GetAxis?

#

For example I want to use Input GetAxis horizontal for A and D keys, and for mobile users to press the left/right buttons

vast pelican
#

Hello, what is the best way to share project with other person?

devout flume
#

It will be useful for all of your projects

#

There are two main websites to host repositories : github & gitlab

#

Both have their pros & cons

vast pelican
frosty hound
#

Yes. All solutions do.

slender nymph
# vast pelican Is there are storage limit?

storage limits are dependent on the remote host you use. github for example has a soft storage limit of about 5 gb for a repository. if you have the resources though, you can always spin up your own git server so you can use as much storage as you need

frank zodiac
#

Why do people sometimes name their variables with an uppercase letter like this? Doesn’t this go against the naming conventions?

#

Why not just name it β€œhealth”

#

Is there a convention for this I didn’t hear of

slender nymph
#

according to the standard c# naming conventions public members should be PascalCase. also that isn't a variable, that is a property

frank zodiac
slender nymph
#

it's not a variable if it has a getter/setter, it is a property. a property is used like a variable but in actuality is a group of getter and setter methods

#

this is why you run into issues with modify the members of a value type you get from a property. such as something like this: transform.position.x = 1; This is not valid because position is a property which means it is a getter method returning a copy of the position

frank zodiac
#

Ohh I see

#

Thanks

devout flume
#

And you do whatever you want with the naming of your variable, even though standards exist, you do you at the end of the day

frank zodiac
devout flume
#

Makes sense

frank zodiac
#

In case I end up working with a team later

#

I should get used to it

burnt vapor
echo sand
#

how do i connect my lever class to the class i want to interact with ```cs
public class Lever : MonoBehaviour, Interactable
{
public Animation LeverAnimation;
public bool CanInteract = true;
public string HoverText => "Use Lever";

private float InteractTime = 0;

public void interact()
{
    if (CanInteract)
    {
        CanInteract = false;
        LeverAnimation.Play("lever");
    }

}
void UpdateInteractiontTimer()
{
    if (!CanInteract)
    {
        AnimationClip Clip = LeverAnimation.clip;

        InteractTime += Time.deltaTime / Clip.length;
        if (InteractTime >= 1)
        {
            InteractTime = 0;
            CanInteract = true;
        }
    }
}

void Update()
{
   UpdateInteractiontTimer();
}

}

slender nymph
#

presumably your interaction system is raycasting and checking for an Interactable component, so that's all you need to do. that should then call the interact method

echo sand
slender nymph
#

give it a UnityEvent then you just hook it up in the inspector

#

and just invoke the event at the appropriate time during your interaction

echo sand
#

ah i see, thought i had to make an abstract class or something

slender nymph
#

nah, that's not necessary. using the unityevent will allow you to be more modular here since you can then use this to interact with pretty much anything you want

#

and if the unityevent is public you can even subscribe to it from other objects in code instead of just the inspector. that would allow you to subscribe non-public methods to the event so that the event can be the only thing that calls those specific methods

scenic maple
burnt vapor
#

Of course you can, you just have to accept that Unity hasn't done it with their exposed variables

#

You can still do it fine with your own code

scenic maple
slender nymph
#

fields are variables. they are class level variables

burnt vapor
#

A variable is a general term. In C# they are more specifically called a field (when part of a class scope)

scenic maple
#

I might accept "instance variables"

burnt vapor
#

It literally means "a value that can change"

slender nymph
#

a field is literally just a variable that is declared directly in the object. it is a variable. calling it a variable is not wrong. my point before was that properties are not technically variables, they are a set of methods that are used like variables

scenic maple
#

The nuance and naming is difficult around this

slender nymph
#

it's really not. a field is literally defined as "a variable of any type that is declared directly in a class or struct"

burnt vapor
#

To be specific on variables; in C# we call them a field when it's on the class scope and a local variable when it's in the method scope.

scenic maple
#

Mhm

#

Like if you say "declare a variable on the class", I wouldn't be entirely sure if you mean a field or a property

#

They're both "variable"

#

An auto-property, you could argue, is a "variable"

burnt vapor
#

A property is not a variable, it doesn't hold a value

#

While it might look like it does, it will use a backing field most of the time. This means the backing field is the variable in this case.

scenic maple
#

It effectively does through the backing field

slender nymph
# scenic maple An auto-property, you could argue, *is* a "variable"

it's still got a separate field that is assigned by the getter and setter, it's just implicitly created by the compiler instead of explicitly created by the coder.
if you want to be pedantic about what is and is not a variable, then you should not be referring to properties as variables

burnt vapor
#

And yes, this is often reason for confusion

burnt vapor
scenic maple
#

It's a bit petty to make that distinction

burnt vapor
#

How is it petty? There's a clear difference, you're just confused by what syntactic sugar allows here

scenic maple
#

Heh, I'm not confused, I know C# inside and out

burnt vapor
#

If that didn't exist, you'd have to explciitly declare a backing field each time.

#

Then surely you'd understand why a property is not an actual variable being mutated each time

scenic maple
#

Just imo

#

Especially because I don't think fields should be public. If I'm meant to add a "public variable", I'm adding a property

#

Which is where I come back to unity not being able to conform to these standards, you can't use properties in the inspector, right?

languid spire
#

so you have a self imposed 'standard' and you wonder why others do not conform to you

slender nymph
#

you can serialize a property's backing field, either by targeting it with the attribute target for an auto property, or just serializing the explicit backing field

languid spire
#

yes it is 'I don't think fields should be public' is self imposed

slender nymph
copper crest
#
using System.Collections.Generic;
using UnityEngine;

public class PipeSpawnerScript : MonoBehaviour
{
    public GameObject Pipe;
    public float spawnRate = 2;
    private float timer = 0;
    public float heightOffset = 10;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (timer < spawnRate)
        {
            timer = timer + Time.deltaTime;
        }
        else
        {
            spawnPipe();
            timer = 0;

        }

        void spawnPipe()
        {
            float lowestPoint = transform.position.y - heightOffset;
            float highestPoint = transform.position.y + heightOffset;

            Instantiate(Pipe, new Vector3(transform.position.x, Random.Range(lowestPoint, highestPoint)0, transform.rotation);


        }
    }
}
#

what is wrong here i dont understand>

charred spoke
#

Neither do we

slender nymph
#

make sure your !IDE is configured so you get your errors underlined, once you see it you'll kick yourself lol

eternal falconBOT
charred spoke
#

Care to elaborate a bit on what is actually going wrong

languid spire
#

you have nested the spawnPipe method

slender nymph
#

they're only calling it from the method it is nested inside of so that isn't an issue. they have a compile error on the last line of actual code

#

two actually

languid spire
#

yep, nonsense Vector3 initializer

charred spoke
#

Local methods, although an abomination, are legal.