#💻┃code-beginner

1 messages · Page 668 of 1

naive pawn
#

is it possible to have multiple Kx100ItemGridItem at once? or any of the others

lean shadow
#

yes

#

thats why I have the IDs on the scripts

#

but I think youre onto something with the prefab

naive pawn
#

so if you modify the template, and then instantiate it, they'll all have the same ID

lean shadow
#

ill try modifying the instantiated gameobject

naive pawn
#

since you did the modification before the instantiation

#

either move the ID generation to after the instantiation, or move the instantiation to before the ID change

#

hell you could have the Instantiate call in AddCorrespondingItem

lean shadow
#

i think thats the problem Ill try it thanks a lot beforehand

#

appreciate it

lean shadow
odd remnant
#

Question about ScriptableObjects. If I understand it right, SOs are used to define like...an overarching class, that other classes inherit common functions and fields from. So I might have a "MountableVehicleSO" script, and a "TrebuchetEmplacement" script that inherits from MountableVehicleSO. Is that right so far?

teal viper
odd remnant
#

Ok I think my question instead then is....when do I use an SO, vs using MonoBehaviour?

teal viper
odd remnant
#

When you say "being able to reference it in the inspector", what is it I need to do to make that data available in the inspector? Derive from that class in the class definition? Or simply instantiate an SO instance inside of another class?

teal viper
odd remnant
#

So I have this code at the top of my SO:

{
    public Player[] playersInVehicle; // This might be an AI instead. What effect would this have?
    [SerializeField] public int numberOfSeats; // Maybe this can be the size of the array above?
    public Transform dropOffPoint;
    [SerializeField] public GameObject vehicleCamera;
    public bool isPlayerOnBoard;
    public bool isAIDriven;
    private bool vehicleCanMove;
    private bool vehicleCameraCanMove;```

Also all Mountable vehicles have some method logic for entering and exiting that they share:

```public void EnterVehicle(Player _player) {
    bool playerHasEntered = false;
    for (int i = 0; i < numberOfSeats && playerHasEntered != true; i++) {
        if (playersInVehicle[i] == null) {
            playersInVehicle[i] = _player;
            playersInVehicle[i].transform.parent = dropOffPoint;
            playersInVehicle[i].transform.localPosition = Vector3.zero;
            vehicleCamera.SetActive(true);
            playersInVehicle[i].GetComponent<GameInput>().OnChangeSelectedInventorySlotByKey += GameInput_OnChangeInventorySlotByKeyAction; // Start listening for key press (This might be changed to a vehicle control in the future)
            isPlayerOnBoard = true;
            playerHasEntered = true;
        }
    }
}```

(This is really early in development so a lot of this might change)  What is it I need to add to make that possible?
#

Ugh, that formatting is horrid.

teal viper
#

Check the ScriptableObject docs page. It has an example and explanation on how to create instances of it. That being said, I'd avoid putting runtime logic in it.

#

There's absolutely no need to for this to be an SO over MonoBehaviour imho.

odd remnant
#

Got it. That's the feeling I'm coming to, too.

teal viper
#

SOs are best used for immutable data. In your case it's only the "number of seats" field.

oak mountain
#

Hello I have a question: Im making guns in unity, but I have an issue on understanding how to approach gun attatchments
my idea is this: have the gun's prefab contain all attatchments possible as children of the gameobject but they are disabled at first, on my gun script I have a float called "gunAttatchment" and the default value is 0 (no attatchments). In this scenario let's say I picked up a flashlight, it will set my gunAttatchment float from 0 to 1, and if its 1, then it'll enable the game object that is my flashlight. Is this a good approach or is there something I am missing?

edit: while rereading this, i have encountered a flaw in my own logic, now it would work if it were single attatchments, but I want to have multiple attatchments at the same time, and since each is a different value, what value would it even yield for it to have both objects enabled?

slender nymph
#

rather than using a float (and why would it even be a float rather than an int) just use a flags enum, assuming you need some way to save which attachments are active. otherwise you just need some method that can enable/disable specific ones

slender nymph
#

of course there are probably dozens of other ways to handle it, i'd recommend just finding a tutorial that suits your needs

oak mountain
#

the reason why im kinda avoiding booleans is because I dont want like 10 lines for different attachments

naive pawn
#

that's what a bitfield solves

#

(what boxfriend was suggesting with "flags enum")

#

a bitfield is an integer that's treated like a bunch of booleans

oak mountain
#

and some attatchments will be overlapping in the same place, so laser sights cannot be active with flashlights

slender nymph
#

and in enum form they have nametags so you aren't just relying on arbitrary indices

oak mountain
#

like this?

naive pawn
#

something like that, yeah, but you'd generally do 1 << 0, 1 << 1, etc so you don't accidentally typo a value

naive pawn
#

kinda like weapon attachment slots in.. idk, pubg, i guess

oak mountain
#

so logically, if my gun only has a flashlight, it returns value 1, if my gun only has a holosight it returns 2, but if it has a flashlight AND a holosight, it'll yield 3?

#

3 or whatever value I set it to

naive pawn
#

yeah

naive pawn
oak mountain
#

so if the flag is set to 3, then the value that it must return is 3, correct?

naive pawn
#

ah i think you don't have the exact terminology down yet

oak mountain
naive pawn
#

a "flag" is each one of the bits in the integer - a flashlight flag, a holosight flag
you can have multiple flags together, but the combined result isn't called a flag
the combined result is a bitfield, which specifies all the flags at once - which are set and which aren't

#

so you would have a flashlight flag, a holosight flag - which would just mean each attachment individually
then you could have a flashlight+holosight bitfield, which specifies that they're both set

#

you could also have bitmasks, which are structurally the same as bitfields - just used in a different way
bitfields are for storing what's set and what's not, bitmasks are for operating on bitfields

#

so you might have a flashlight bitmask (equivalent to the flashlight flag itself), which you can use on some unknown bitfield to set, clear, or check the flashlight flag

oak mountain
naive pawn
#

yeah

#

(assuming the flashlight flag is the first flag, at least)

oak mountain
#

and the flashlight flag and holosight flag together form another bitfield

naive pawn
#

yeah

oak mountain
#

and I define what bitfield comes out of the flags

#

for some reason in my adhd induced thought I thought of having
flashlight flag = 1
holosight flag = 2
flashlight and holosight flag = 12 (😭)

slender nymph
#

if you use the | operator you can combine them so you can do something like this: Options options = Options.Option1 | Options.Option2; and then if you were to cast it to int it would be 3

naive pawn
#

i mean.. if you use strings/chars as flags.. but then it wouldn't be a bitfield lol

#

a bytefield/charfield

oak mountain
slender nymph
naive pawn
slender nymph
#

i was using the previous "Options" enum that was pasted earlier

alpine heron
#

Can I get a Unity Cheat Sheet for application development, I'm new, starting out in Unity, but I'm a intermediate/advanced level C# programmer.
I would like to learn how to create proper scripts for PlayerMovement, GUI, etc.

#

Like in general C# we dont have Monobehavior
So, how do I learn these, the document doesn't teach it.
Also, like SeralizedFields, and other intialization things confuse me, and I want to get started, I've been trying to use and learn C# and Unity for a couple of weeks coming as a Java programmer.

eternal falconBOT
#

:teacher: Unity Learn ↗

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

alpine heron
#

I'll look into it, thank you.

naive pawn
#

yes, that site has plenty of info

alpine heron
#

Which one specifically for my need?

#

It's just unity's version of programming I need.

naive pawn
#

programming essentials and maybe the junior programmer pathway, i guess?
feel free to skim over parts you're already comfortable with

oak mountain
#
public enum gunAttatchments
{
    noAttatchments = 0,

    // scope attatchments
   attatchmentHolosight = 1 << 0,
    attatchmentScope8x = 1 << 1,

    // underbarrel attatchments
    attatchmentFlashlight = 1 << 2,
    attatchmentLaser = 1 << 3,
    attatchmentKnife = 1 << 4,

    // barrel attatchments
    attatchmentSilencer = 1 << 5,
    attatchmentMuzzleBoost = 1 << 6
}```

something like this?
#

where do I define these? im lost

naive pawn
#

you would generally have the enum and its members as PascalCase, and also it would act kinda like a namespace so you wouldn't need attachment in the enum member names - you would have GunAttachments.HoloSight, not GunAttachments.AttachmentHoloSight

oak mountain
#

ohhhhh

naive pawn
naive pawn
oak mountain
#

thats honestly a better ideia ngl

#

you ever played unturned? thats kinda where I got the idea

orchid trout
#

How do I check if a game object exists in the scene on play, without also returning True if it gets instantiated into the scene later?
On Start and OnAwake methods both fail to correctly test if the object existed when I hit play vs. the object later got instantiated in

#

XY problem my REAL problem is I have a room loader and I need to load rooms into the room loader that already exist in the scene that I placed myself, and I need a way to differentiate stuff I put in the scene vs stuff that gets loaded later

#

ideally I want a sollution that removes all possibility for human error - I COULD put a bool on the room that I flag myself manually if it existed at start or not, but that's way too likely to get saved into the prefab and @#%@^ everything up

naive pawn
#

not sure if this is optimal, but i do have an idea -
have some persistent singleton listen for sceneLoaded, and then set a state "first frame of scene" to true (or something like that)
then on Awake/Start of each object, check if that state is set

#

or on sceneLoaded, go through each existing object in the scene to mark them as such

wintry quarry
orchid trout
wintry quarry
dim yew
#

when i set the rotation of my object to a degree value between 180 and -180 it works fine, but when i get the value elsewhere (ie. transform.rotation.x) it turns into a number between 1 and -1. is this a radians thing or am i just stupid?

wintry quarry
#

Never ever try to look at the individual components of it

dim yew
dim yew
#

alr thanks you guys

frigid sequoia
#

Any particular reason the icon of the script shows updated there but not in the folder?

#

Is that a thing that just happens sometimes?

fleet nova
#

hello, guys

#

I have a question

slender nymph
#

!ask

eternal falconBOT
slender nymph
#

pay particular attention to the last two lines

fleet nova
#

okok, thx

wild basalt
slender nymph
#

a massive cheat sheet of just unity specific functions
that's called the documentation

swift elbow
#

!code

eternal falconBOT
untold elk
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GoBack : MonoBehaviour
{

    int sceneIndex;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        sceneIndex = SceneManager.GetActiveScene().buildIndex;
        if (!PlayerPrefs.HasKey(sceneIndex.ToString()))
        {
            PlayerPrefs.SetInt(sceneIndex.ToString(), sceneIndex);
            Debug.Log("worked");
        }
        int ScenetoOpen = PlayerPrefs.GetInt(sceneIndex.ToString());
        Debug.Log("Scene is opened succesfully, hip hip hurray,we're extra dextra crazay.");

    }

    public void Backward()
    {
        SceneManager.LoadScene(sceneIndex - 1);
                            Debug.Log("Hip hip hurray");

    }

}

swift elbow
#

and you said that no logs are printing at all?

#

is there an instance of this script in your scene?

untold elk
#

yes its inside a button inside a panel

swift elbow
#

you are getting logs, but you cant see them

untold elk
#

!code

eternal falconBOT
untold elk
#

    public void Backward()
    {
        SceneManager.LoadScene(sceneIndex - 1);
                            Debug.Log("Hip hip hurray");

    }
\
``` does not work its the one that isnt printed
frosty hound
#

Then Backward() isn't being called.

swift elbow
untold elk
#

yeah i got that to work

swift elbow
#

so what is supposed to be calling the Backward function?

untold elk
#

when i click my button named BackWard if that is important at all

frosty hound
#

How do you actually tell that button to run this function?

untold elk
#

feel like there would be a mousebuttononeclick function with the button to indicate it is hit but objectively it hasnt reached me in code on how to fix that or write sum like that,otherwise my buttons in previous scenes use public void and run properly so it confused me

swift elbow
#

so... you arent doing anything to call it at the moment?

untold elk
#

no

#

i rushed figuring that out ig oop

swift elbow
#

then obviously its not gonna run

#

this is very easy to setup, though. a ton of basic tutorials on UI will teach you how to set this up

untold elk
#

ok what do u recommend to search for calling buttons then on unity

#

so i can not suffer incorrect tut

swift elbow
#

yeah just "unity UI buttons tutorial" should work

untold elk
#

ok tysm i will come bac w a manifested success hoping lol

#

tysm!

#

btw am i calling the back() or the sceneIndex

swift elbow
#

sceneIndex is an int. how are you gonna call an int?

untold elk
#

oop tru

brave robin
#

If you're using the UnityEvent on a button, you'll only be able to call functions or properties

untold elk
#

I tried setting a serializefield for both button and a function to define it but it is unsuccesful

#
    [SerializeField] private string theexamplesisaidbefore = "GamePlay";

``` made sense u couldnt put backward but now i am curious
swift elbow
#

your terminology is entirely messed up. you are supposed to be referencing the Backward function on your button

swift elbow
untold elk
# swift elbow what is this supposed to mean?

according to the random tut : ( its supposed to create a string just for enabling the scene w whatever name or level it was but istg ive not seen unity code using serializefield but this was 3yo tutorial so ill give it slack and me braincell growth

swift elbow
#

"create a string"???
how familiar are you with programming and c# in general?

untold elk
#

i literally started w tutorials like 1.5 days ago

swift elbow
#

you should really familiarize yourself with the basics more before continuing. i would recommend spending at least a couple weeks learning the basics and practicing before continuing

untold elk
#

ok assumed i could do a tutorial by tutorial basis definently tells how not easy the csharp is for beginners but i do need this for a school proj so am curious if u would know what id exactly have to add (its not a grade where the code is important alas its a history project)

#

also is code 🐒🙉 monkey a good place to start he has a full course and seems trusted in the unity community

swift elbow
swift elbow
swift elbow
untold elk
#

yeah makes sense lmao

#

is his full course tutorial for beginners from beginner/intermediate made exactly 2 years ago best or would any of the code be broken in unity 6x now

swift elbow
tranquil forge
#

in a multiplayer context, players character using the same material, if i did: skinmesh.sharedmaterial = newmat, will this also change the other players? like how this player see the others ?
also in normal context i know that: var mat = skinmesh.material create a copy, assign to that skinmesh and that var mat so i will have to keep this mat reference at all time to call Destroy(mat) and cant do Destroy(skinmesh.material) right? or will it just auto get gc when no longer referenced (var mat is lost or skinmesh is destroyed)?

undone depot
#

im getting this error on code that i dont think should be having an error
Assets\Ancient Language\PlayerMovement.cs(88,62): error CS1061: 'Rigidbody' does not contain a definition for 'linearVelocity' and no accessible extension method 'linearVelocity' accepting a first argument of type 'Rigidbody' could be found (are you missing a using directive or an assembly reference?)

anyone know what's up here?

sour fulcrum
#

Eg. If it’s four people playing thats not four people playing in the same connected game thats four different games that are ideally identically setup

teal viper
#

!ide

eternal falconBOT
bright arch
#

if a dictionary is null, does that mean it doesnt exist, or that its empty?

sour fulcrum
#

the former

bright arch
#

err okay, so i have a class that stores info about player stats and stores them with a static call of that class, and im trying to add a dictionary to it but:


void SomeFunction()
{
    if (adventures == null)
        {
            print("No adventures?");
        }
    else
        {
            print(adventures);
        }
}

it says its null and i cant add to it from other scripts, it acts like it doesnt even exist

bright arch
rich adder
bright arch
rich adder
#

thats not assignment

bright arch
#

its static so shouldnt matter right ??

rich adder
#

huh?

#

declaring a field isnt assignment

bright arch
#

im able to call other information from GameDataManager.Instance without issue

brave robin
#

Sure, if you're only accessing other static methods and variables from GameDataManager, then those will work, but there's no instance being assigned, so non-statics will fail

#

It looks like you want it to be a singleton, which means you need to assign an instance to that variable at Awake()

rich adder
#

they most likely do it in start without realizing

#

if at all..

bright arch
#

i solved it, it was an issue with my save/load and i had to use ?? srry

#

thanks though

vapid wren
#

Hello, I'm completely new to Unity, I've been following a tutorial and I'm now getting to coding stuff, I generated a script, but when I try double clicking to open Visual Studio, there's nothing there

bright arch
keen cargo
eternal falconBOT
swift elbow
keen cargo
#

I mean I've seen that as a solution here and there, and it doesn't hurt to make sure that it is configured

swift elbow
#

configuring your ide wouldnt magically make it so that text appears in your ide

vapid wren
keen cargo
#

i mean, configuring your ide is essentially making it compatible with unity

if it's not compatible with unity by default, then it's not a stretch to think that it's a possible issue

swift elbow
#

that's not the case at all...

keen cargo
#

feel free to correct me

keen cargo
#

unity has the Project tab where you can open the scripts from directly

swift elbow
#

all IDE's that are compatible with unity at all are compatible with unity by default. configuring your IDE makes it so that respective csproj and sln files are generated so that your IDE can properly talk with Unity. Though, this doesnt necessarily mean that it wont work with unity at all without configuration

vapid wren
ivory bobcat
#

Solution explorer etc

keen cargo
vapid wren
ivory bobcat
keen cargo
vapid wren
#

It opens to visual studio, but no code shows up

keen cargo
#

does the same happen if you open it from file explorer?

#

not dragging, just Open With -> Visual studio

keen cargo
#

i mean, did no code show up when you did it via file explorer?

swift elbow
vapid wren
#

oh my bad, its not the same, the code does show up if I open it using file explorer

keen cargo
#

ok then, in unity, go to

edit > preferences > external tools, and check that Visual Studio is the IDE

vapid wren
keen cargo
#

nice ok, you can try to "Regenerate project files" too, could help here

keen cargo
vapid wren
#

Where do I find the package manager?

keen cargo
#

should be under Window in unity

vapid wren
keen cargo
#

really strange, and did you check what Dalphat suggested? They edited their message, but check View tab in VS and see if everything is there like Solution explorer

teal viper
# vapid wren Yes

Did you go through the manual installation instructions of !ide? It seems like you might be missing some C# workloads.

eternal falconBOT
keen cargo
vapid wren
real bobcat
#

hello everyone i recently started using unity and downloaded some asset from the store ( VFX ) but they got the default pink texture and i don't know how to fix it

teal viper
#

Unless I'm missing something, they never confirmed that they configured it properly

keen cargo
#

i think it is worth it to check that the IDE is configured

#

since you'll be needing that to get any further help here anyway, if you have issues with code for an example

teal viper
vapid wren
real bobcat
keen cargo
teal viper
real bobcat
#

may i ask how to change said pipeline ?

teal viper
#

I mean, how exactly did you expect to use several at the same time? Render the frame several times and then combine the results or something like that?😅

bright arch
#

how do i make it so that a ui element DOESNT move with the camera?

keen cargo
real bobcat
teal viper
keen cargo
bright arch
#

oh also, for something like a scriptableobject, how can i make it so that certain information below it in the inspector only appears when an enumeration value is a certain value?
so that for example i can have items fulfilling different purposes (food needs a value for how much hunger it replenishes, but a furniture or clothing item doesnt need that)

teal viper
vapid wren
bright arch
teal viper
#

Another approach is to use composition

bright arch
#

oh inheritance, i need to read about these things then. thanks for giving me pointers about how to learn this

undone depot
sour adder
undone depot
#

2022

sour adder
#

Yes, that's it then...

little anvil
#

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

public class Collision_Off : MonoBehaviour
{
public GameObject Platform2; // Assign platform_2 in the Inspector

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

}

// Update is called once per frame
void Update()
{

}

void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        BoxCollider box = Platform2.GetComponent<BoxCollider>();
        if (box != null)
        {
            box.enabled = false;
        }
    }
}

}

can someone help me debug. if u want images of my project i have those.

frail hawk
#

is this a 2d game and what is the problem

#

if 2d you need to use OnCollisionEnter2D

eternal falconBOT
little anvil
frail hawk
#

what exactly is the problem?

little anvil
#

for some reason when i touch the particle thingy the box collider for platform_2 is still enabled. want pics or perhaps a vid?

frail hawk
#

or try to explain

#

may i ask why you are not using sprites because i am guessing you got this wrong

little anvil
#

Theres basically a couple platforms, the player controller works and the goal is to reach the particle thingy, which will disable the platforms and give you the wall jump ability. Currently i'm working on disabling the platforms.

#

The code is meant to do that but it doesn't work.

little anvil
frail hawk
#

just use debug.log inside the oncollisionenter and see if the collision is even taking place

#

narrow down the issue

little anvil
#

how do i do that?

#

i'm new sorry

frail hawk
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

little anvil
#

aight thanks

undone depot
#

what is the equivalent of rigidbody.linearDamping for unity 2022

terse saffron
#

You mean Variable ?

terse saffron
undone depot
#

ty

terse saffron
#

oh

#

i thought he was asking what value it takes 😅. not what it means

undone depot
#

lol thanks anyway

terse saffron
#

if the gameObject is inactive in the scene to which the above Script is applied. and i am running this Function in another script with different gameObject which is active. Will the function still work ?

little anvil
#

Sup. I have a question. Why does
'''cs
Material material2 = Platform2.GetComponent<Renderer>().material;
if (material2 != null)
{
material2.color = Color.clear;
}
'''
make the block 'platform2' look black?

#

... why didn't the code tag work?

terse saffron
#

You want to make it Transparent ? Color.clear makes it a black transparent color . RGB(0,0,0)

little anvil
#

oh... well i want transparent yes

#

how do i do that

bright arch
#

you can probably set the alpha of the color to 0

terse saffron
#

maybe set the color to white and alpha to 0

little anvil
#

how do i do that?

bright arch
#

Color.color.a = 0

#

so material2.color.a = 0 probably

little anvil
#

aight i'll try it out

bright arch
little anvil
#

ok thanks

#

it doesn't work

sour fulcrum
#

what does it say

little anvil
#

CS1612: Cannot modify the return value of 'Material.Color' because it is not a variable

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

public class Collision_Off : MonoBehaviour
{
    public GameObject Platform1; // Assign platform_1 in the Inspector
    public GameObject Platform2; // Assign platform_2 in the Inspector
    public GameObject Player; // Assign the player in the Inspector

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

    // Update is called once per frame
    void Update()
    {
        
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject == Player)
        {
            BoxCollider box2 = Platform2.GetComponent<BoxCollider>();
            if (box2 != null)
            {
                box2.enabled = false;
            }
            Material material2 = Platform2.GetComponent<Renderer>().material;
            if (material2 != null)
            {
                material2.color.a = 0; // Set alpha to 0 for transparency
            }

            BoxCollider box1 = Platform1.GetComponent<BoxCollider>();
            if (box1 != null)
            {
                box1.enabled = false;
            }
        }
    }
}
sour fulcrum
terse saffron
#

Or either make another gameObject with surface type set to transparent and instantiate it in its place after destroying previous one.

real bobcat
#

hi again, i have this cool shader pack but it works only in the default render pipeline how do i change that simply ?

sour fulcrum
#

you don't

#

it's not a simple process

real bobcat
#

yeepee

#

i mean what should do , rewrite it from 0 i guess ?

verbal dome
real bobcat
#

is there any other web site that can provide shader and stuff for unity ?

frosty hound
#

The asset store

real bobcat
#

other than the asset store

pulsar helm
# little anvil ```cs using System.Collections; using System.Collections.Generic; using UnityEng...

Otherwise, material.color is a field and not a variable thus the error. Its declaration in the Material class is : public Color color { get; set; }
That means that you can get it however you like but you can only set it by assigning it a new value.
In short: You can't modify a field with a value type without replacing it entirely.

Usually you just do this :

Color tempColor = material.color; // Extract current color (optional, you can just create one yourself)
tempColor.a = 0; // Transparency to 0 or whatever you'd like to do
material.color = tempColor; // Reassign back

But as Osmal said, it might be more efficient and/or more suitable to disable the renderer completely if you're only interested in a toggle mechanism for show/hide. Since the draw call won't ever happen when disabled, this can greatly increase performance, especially if you got a lot of objects that implements this mechanic.

keen cargo
terse saffron
#

!code

eternal falconBOT
sour fulcrum
kindred halo
#

How do I increase two different values at the same time?

sour fulcrum
#

increase one

#

then increase the other

kindred halo
sour fulcrum
#

nope

#

your doing two things

#

it will never be one thing

kindred halo
#

there should be a way
I've seen games doing that

sour fulcrum
#

no

#

you have never seen any computer do that, explain why you need that

wintry quarry
frosty hound
#

Unity is single threaded, nothing happens at the same time. The fact you think you find this necessary is a beginner red flag.

kindred halo
wintry quarry
kindred halo
wintry quarry
#

Make a function that changes both of them by the same amount

#

It's that simple

kindred halo
#

I cant bcuz the image fill amount is restricted between 0-1

wintry quarry
#

I don't see why that means you can't

sour fulcrum
#

how would setting both at the same time solve that

frosty hound
#

That has nothing to do with you wanting to do both?

wintry quarry
#

The entire world of mathematics is available to you

#

Use it

kindred halo
#

Ig I'll dig more

delicate laurel
#

I follow UI toolkit guide for making labels upon objects. I don't get why do my label in screen corner instead of being upon object

frosty hound
#

If you're trying to fill a bar based on progress, then you divide the current value by the max value. Use that in your fillAmount

kindred halo
frosty hound
#

Right. This doesn't seem at all like the issue you were describing before about things happening at the same time.
In the future, just explain your goal rather than what you think you need to do.

wintry quarry
#

The increasing of the values part is totally unrelated to the drawing it in the filled image part

kindred halo
#

yeah I figured it out

real bobcat
keen cargo
sweet iris
#

Hello I have a question about the roll a ball tutorial (https://learn.unity.com/course/roll-a-ball/tutorial/moving-the-player?version=6#66f2d394edbc2a011dded4a3) OnMove gives us a Vector2, which we are using to make a Vector3, however, we're using the y coordinates to use a z coordinates and I don't understand why, I never used playerInput component before and I'm confused 🙏

Unity Learn

Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.

frosty hound
#

Input is naturally a Vector2 because your keyboard arrows, or analogue stick on a gamepad is on 2 dimensions.

X axis is left and right, and Y axis is up and down.

#

In a 3D controller, you want the up and down (y axis) of the input to move the character on the z-axis which is forward and back.

#

So that's why you use the Y axis from the input as the value for the Z axis of the character.

sweet iris
#

oh that makes sense! thank you

jolly stag
#

I was wondering if I could have some help, I'm trying to set up a button that destroys the previous instantiated object and then instantiates a new one. The issue is I can't destroy something that doesn't yet exist the first time the script is running I think?

using UnityEngine.UI;
using Unity.VisualScripting;
using TMPro;

public class Random : MonoBehaviour
{
    private Button button;
    public float number = 0f;
    public TextMeshProUGUI buttonText;
    public GameObject[] balls;
    private GameObject presentBall = null;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
       button = GetComponent<Button>();
       button.onClick.AddListener(RandomBall);
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void RandomNumber()
    {
        Debug.Log("Button Has been Clicked");
        number = UnityEngine.Random.Range(1, 20);
        buttonText.text = "" + number;
    }


    private void RandomBall()
    {
        Destroy(presentBall, 2);
        int colourBall = UnityEngine.Random.Range(1, balls.Length);
        Vector3 location = new Vector3(10, 0, 0);
        GameObject presentBall = (GameObject)Instantiate(balls[colourBall], location, Quaternion.Euler(0, 0, 0)); // New Gameobject Called presentBall which = the instantiate summon
        
    }
}```
teal viper
#

Check if the object is null

jolly stag
#

If I don't destroy it then I'd have a button that generates infinite coloured balls which all over lap, I tried to declare the ball as null when the script starts but it's still throwing a hissy fit about it not being declared before use.

teal viper
#

I mean "don't destroy it if it doesn't exist"

keen dew
#

The "infinite balls" is a different problem. The last line makes a new variable, it doesn't change the presentBall field. Remove the GameObject part from there

teal viper
jolly stag
jolly stag
teal viper
real bobcat
#

ok how do i "install" an asset bundle that i got from somewhere else than the asset store ?

teal viper
real bobcat
keen cargo
kindred iron
#

Guys i made this code but i really have feeling that its messy and i could do better. Im trying to make it better but i cant. Can yall help me to make it better?

private void Update()
{
    CardController();
    UpdateUI();

    slimeRequirement = baseSlimeReq;
    IncreaseSlimeReq();
}

public void IncreaseSlimeReq()
{
    foreach (Transform child in GameObject.Find("Upgrades").transform)
    {
        if (child.gameObject.GetComponent<UpgradeBase>().GetType() == GetType())
        {
            slimeRequirement += slimeRequirement / 3;
            slimeRequirement -= slimeRequirement % 5;
        }
    }
}
rugged beacon
#

same, try apply a design pattern
if you have completed the feature, try go back to it whole and refactor it all to a pattern

rugged beacon
#

yea

kindred iron
#

what is a design pattern

#

i didnt understand it at all ;(

rugged beacon
#

thats a long story, try searching it fr

#

im not expert also, trying to refactor my garbage code atm also

kindred iron
naive pawn
fickle plume
naive pawn
kindred iron
naive pawn
#

the list of upgrades is going to change?

fickle plume
#

If that's the case you should keep track of the list of upgrades somewhere and access that.

kindred iron
naive pawn
#

yeah you shouldn't treat the hierarchy as storing data, really

#

store stuff yourself and then sync that to the hierarchy

#

that way you have direct access and it makes it easier to access stuff

#

if that big change isn't viable, at least use a serialized reference for the Upgrades game object, so you can avoid that magic string

kindred iron
naive pawn
#

you kinda already are - the upgrade gameobject's children

kindred iron
#

if that big change isn't viable, at least use a serialized reference for the Upgrades game object, so you can avoid that magic string
what did u mean, i didnt get it

naive pawn
#

which part exactly, or the whole thing?

kindred iron
#

wdym serialized reference

kindred iron
naive pawn
#

a serialized reference is basically a reference you set in the inspector

kindred iron
naive pawn
#

...so the whole thing

kindred iron
#

not here "yeah you shouldn't treat the hierarchy as storing data, really
store stuff yourself and then sync that to the hierarchy
that way you have direct access and it makes it easier to access stuff"

naive pawn
#

yeah that's still a big chunk you're asking me to rephrase lol

#

you gotta be more specific

kindred iron
#

can u give me a example pls?

naive pawn
#
public Transform upgrades;
#

you likely already have plenty of these

#

it's one of the first things you learn to do in unity scripting

kindred iron
#

wdym so you can avoid that magic string

naive pawn
#

ok so.. dude do you know what "avoid" means

kindred iron
#

magic string

#

wdym

naive pawn
#

yeah, that makes my job a whole lot easier

kindred iron
#

in this case i need to control the childs every time

#

so i cant make a variable for the children

#

cuz then i cant get the children which added new

naive pawn
#

a magic string (or magic number, etc) is a specific hard-coded string that you use as a data point - like the "Upgrades" string here
they're generally not a good idea since they can easily be typo-ed, they don't have a clear link to anything else, and they can easily get out of sync if you decide to rename one

naive pawn
kindred iron
kindred iron
naive pawn
kindred iron
#

ohh ok i got it

#

🙂

#

but because its a upgradeBASE idk if i can add upgrades gameobject even tho this script isnt in hierarchy

naive pawn
#

that has nothing to do with it

kindred iron
#

or i have to add upgrades gameobject every single time when i make a new upgrade card

naive pawn
#

what?

#

i have no idea what an "upgrade card" is here

#

im not sitting in your project

kindred iron
#

UpgradeBase = upgradecardbase

naive pawn
#

that tells me nothing

kindred iron
#

wait

#

1min

#

if i add here the upgrades game object do i need to add the upgrades gameobject for every single inheritances from upgradeBase's (upgradebases classes i mean)

kindred iron
#

yes

naive pawn
kindred iron
#

i cant put it cuz upgradebase is in project

naive pawn
#

yeah you aren't supposed to

#

that's a default reference

#

set it on an instance of the script, not the script itself

kindred iron
#

then i need to set it every time when i make a new child which inheritances from UpgradeBase right?

naive pawn
#

what do you mean by "set"?

kindred iron
#

wouldnt it be better by taking the gameobject by just using GameObjectFind

kindred iron
naive pawn
#

you wouldn't set the variable when you create a subclass

#

you'd set the variable when you instantiate it

naive pawn
kindred iron
naive pawn
#

(but generally, as i mentioned before - direct references are better than Find)

kindred iron
#

but i wanted so say

naive pawn
kindred iron
#

that the tactic how i coded looks messy here like at the start of the update func i have to set the "slimeRequirement = baseSlimeReq;"

#

it looks like shit

#

i think thats a bad way to do this

naive pawn
#

ok... and why do you need to do that every frame?

kindred iron
#
private void Update()
{
    CardController();
    UpdateUI();

    slimeRequirement = baseSlimeReq;
    IncreaseSlimeReq();
}

public void IncreaseSlimeReq()
{
    foreach (Transform child in GameObject.Find("Upgrades").transform)
    {
        if (child.gameObject.GetComponent<UpgradeBase>().GetType() == GetType())
        {
            slimeRequirement += slimeRequirement / 3;
            slimeRequirement -= slimeRequirement % 5;
        }
    }
}
kindred iron
#

if i buy the same card i increase the slimeReq

naive pawn
#

yeah you shouldn't do the same calculation every frame

#

just keep that same variable and only update it when something changes - when you buy one of those cards

#

i think you should step back from your code and take a bit to think about how everything links together first

#

that way you can figure out what kind of relationships and calculations make sense, and then implement that

kindred iron
#

yeah im trying it rn

#

ty for the help

#

if i write it so then it increases the card which i bought not the classes variable

 public void IncreaseSlimeReq()
 {
     slimeRequirement += slimeRequirement / 3;
     slimeRequirement -= slimeRequirement % 5;
 }

 public void BuyCard()
 {
     if (GameManager.instance.slime >= slimeRequirement && GameManager.instance.level >= levelRequirement)
     {
         GameManager.instance.AddSlime(-slimeRequirement);
         IncreaseSlimeReq();
         isBought = true;
         drawCount += 1;
     }
 }
#

how can i do it that the classes slimereq increases?

naive pawn
#

...like that?

kindred iron
naive pawn
#

is slimeRequirement static or something? if not, there is no "class' slimereq", it belongs to each instance of the class

kindred iron
#

so i cant make it static too

#

cuz its abstract

#

if i would able to do it static the problem would gone

naive pawn
#

you could trigger some event or loop to call some method to call IncreaseSlimeReq on each instance

kindred iron
#

could u give me a example?

naive pawn
#

there are tons of ways to achieve this

#

i don't know your project architecture

kindred iron
#

i cant learn it if i cant see it

#

its too complicated to search that cuz my games arch is different like u said

naive pawn
#

i didn't say it's "different"

#

i said i don't know it

#

you do

neon hill
#

Hello, I'm on windows using unity 6.1
I created a prefab folder and dragged a sphere into that folder. It's showing as a prefab now, when I drag the prefab from the folder into the hierarchy the new one is showing up wherever the camera is looking instead of where the original one is. Is there anyway to change that to make it appear at the original location?

brave robin
#

Sounds like you parented it to the camera by mistake, show us a screenshot of the hierarchy

neon hill
brave robin
#

So in-game when you look around, the sphere is always dead center?

slender nymph
#

i think they mean when they place it manually in the scene it ends up where the scene camera is looking which is expected behavior and not really a code issue

naive pawn
naive pawn
#

you could reset the transform to get it to be at 0,0,0 but that also sets rotation and scale (and might not be what you're going for)

slender nymph
#

there is an option to set its position to the origin instead of where the camera is looking, i just don't quite remember where that setting is

#

looks like it should be in Preferences > Scene View

neon hill
#

Thats what I mean. I was running through a course on udemy and he said it should have the same coordinates as when you first created the prefab. If its not broken then that's fine, but now I'm more so just curious on how to get it to go to that original location when I drag it into the hierarchy

ember tangle
#
trajectoryBodies[i].gameObject.layer = ignoreLayer;
Collider[] collider = Physics.OverlapSphere(trajectoryBodies[i].rigidbody.position, trajectoryBodies[i].radius, simluationLayer, QueryTriggerInteraction.UseGlobal);
trajectoryBodies[i].gameObject.layer = simluationLayer;

any ideas why its telling me my object has two layers after this layer switch?

#

both ignoreLayer and simulationLayer are set in the editor.

#

fwiw this also doesnt work:

Collider[] collider = Physics.OverlapSphere(trajectoryBodies[i].rigidbody.position, trajectoryBodies[i].radius, simluationLayer, QueryTriggerInteraction.UseGlobal);
trajectoryBodies[i].gameObject.layer = 1 << 10;```
naive pawn
grand snow
bright arch
#

hey guys im breaking my brain with this, plz help

int[] buttons = new int[] {1};

for (int i = 0; 0 < buttons.Length; i++) // this runs twice... for some reason
{
    print(i);
    // a bunch more code
}

for (int r = 0; 0 < buttons.Length-1; r++) // but this runs zero times!
{
    print(r);
    // a bunch more code
}

(i condensed the code a bunch so sorry if some of it doesnt seem to make sense)
i just want the loop to run through once, just like how theres only one value in buttons

naive pawn
naive pawn
#

you sure that first one runs 2 times and not forever?

bright arch
#

it adds to i at the end of the loop right? i mean i get an error because of my other code so it could very well run forever if that isnt the case

naive pawn
#

it adds to i at the end of the loop right?
what about it? you aren't using it in the condition

#

read your condition again

#

also - do you use i as a number anywhere? if not, you could use a foreach instead to avoid this kind of mistake

bright arch
ember tangle
naive pawn
#

ok it's not actually telling you that it's in multiple layers

ember tangle
#

yes, and i get the same error with bitwise operation to set the integer

naive pawn
#

did you actually read what i sent

#

you aren't supposed to use the bitwise operation

ember tangle
#

Im using layermasks [SerializeField] private LayerMask simluationLayer; [SerializeField] private LayerMask ignoreLayer;

#

set correctly in the editor

naive pawn
#
- trajectoryBodies[i].gameObject.layer = 1 << 2;
+ trajectoryBodies[i].gameObject.layer = 2;
  Collider[] collider = Physics.OverlapSphere(trajectoryBodies[i].rigidbody.position, trajectoryBodies[i].radius, simluationLayer, QueryTriggerInteraction.UseGlobal);
- trajectoryBodies[i].gameObject.layer = 1 << 10;
+ trajectoryBodies[i].gameObject.layer = 10;
```this would work - but of course you wouldn't want that for DX
naive pawn
ember tangle
#

what is DX

naive pawn
#

developer experience - you'd want to be able to set it in the inspector with names, like you would a layermask, yeah?

#

the problem being you can't use a layermask here

ember tangle
#

I understand now

naive pawn
#

since GameObject.layer is just an int and not some wrapper, i don't think there's a utility to get a single flag out of a layermask in this way
so i guess you'd just have to loop to find the first flag set if you want the input to be a layermask

ember tangle
#

LayerMask.value doesnt work either which is annoying

naive pawn
#

yeah because LayerMask.value is the int value of the mask, not an id of one of its flags

#

online solutions also point to either looping or log2

ember tangle
#

okay I dont understand. Layer is an int, LayerMask.value is the int of the layer, but layer = layermask.value does not work?

wintry quarry
#

just because two things are int doesn't mean they represent the same thing

#

just like Vector3 can represent a color, a position, a rotation, euler rotations. Just because they're the same data type doesn't mean they're interchangeable

ember tangle
#

so layer 10 = 10, layermask 1 << 10 does not equal ten right?

wintry quarry
#

1 << 10 is 2 to the 10th power

#

which is not 10

naive pawn
#

a layermask of layer 10 is 1024

wintry quarry
#

the important things with masks is to look at it in binary

ember tangle
#

okay so its like the bits of int eg 0000000001[etc]

wintry quarry
#

1 << 10 is
10000000000

#

so it's the 10th bit set

#

yes

naive pawn
wintry quarry
#

whatever man 😛

ember tangle
#

I thought layer one was 1000 etc, layer 2 was 0100 etc

slender nymph
#

nah, that's right. the bits are 0 indexed

#

1 << 0 is 0b0001

wintry quarry
naive pawn
naive pawn
wintry quarry
#

yes sorry

#

the first layer, with ordinal 0

ember tangle
#

alright I think I get it

supple flume
#

why cant i multiply byte by time.delta time

#

invs = 1 * Time.deltaTime;

grand snow
#

what type is invs

supple flume
#

byte

wintry quarry
grand snow
#

then cast to byte

wintry quarry
#

Depends what you're trying to do

grand snow
#

you probably want to go to int first then byte cus float to byte wont end well

wintry quarry
#

It really depends what you're trying to do here

#

Time.deltaTime cast to an int is always going to be zero

#

I can't imagine that's what you want

supple flume
#

so like this

wintry quarry
#

Wait and you're just multiplying deltaTime by 1

#

What's the point of that

#

That does nothing

supple flume
#

i want to animate a fading off and on effect

wintry quarry
#

You can't store a float in a byte

supple flume
wintry quarry
#

Are you trying to get a 0-255 value?

supple flume
wintry quarry
supple flume
rich adder
#

color is floats (0-1), color32 is byte (0-255)

wintry quarry
#

it's normally a very small number like 0.015

#

because frames are fast

supple flume
wintry quarry
rich adder
#

wdym the "visibility" like alpha?

wintry quarry
#

a float

supple flume
wintry quarry
#

like this:

float alpha = 1;

void Update() {
  alpha -= Time.deltaTime;
  myColor = new Color(1, 1, 1, alpha);
}```
#

something along those lines

#

Color uses 0-1

rich adder
wintry quarry
#

not 0-255

#

so stop using byte

supple flume
wintry quarry
#

your alpha value needs to be a float

supple flume
#

there isnt such thing as new Color32

wintry quarry
grand snow
#

🍿

supple flume
wintry quarry
#
float alpha = 1;

void Update() {
  alpha -= Time.deltaTime;
  myColor = new Color32(255, 255, 255, (int)(alpha * 255));
}```
wintry quarry
supple flume
#

oh so you want me to change it to color

wintry quarry
#

yes

supple flume
#

ok is there a way to change

wintry quarry
#

with your keyboard

supple flume
#

those values into the color format

wintry quarry
#

public Color myColor;

#

myColor = new Color(209f/255f, 112f/255f, 108f/255f);

#

or better yet

#

set it up in the inspector

grand snow
#

some very simple maths lets us go from 0-255 to 0-1

wintry quarry
#

literally just do public Color myColor; and set it up in the inspector

grand snow
#

Yea, setup the colour that way then animate it in code as you desire

supple flume
#

should i use time.delta time right

rich adder
#

if you need the value to change consistently over a series of frames, yes

supple flume
#

i want it to change smoothly

#

going from 255 to 100 then going back

rich adder
lilac cape
#

This is so weird, I'm trying to instantiate a fence but for some reason my spawnmanager is instantiating the wrong obstacle.

  • My SpawnManager gameobject is assigned the right prefab in the SpawnManager Script (Obstacle_White_Fence)
  • When I start the scene, a fence named Prop_Barrier03 is spawned? Anyone know why the right prefab fence isn't spawning?
rich adder
#

not a video of it

lilac cape
#

code is in video but script is:

using UnityEngine;

public class SpawnManager : MonoBehaviour
{
  [SerializeField] private GameObject[] obstaclePrefabs;
  private Vector3 spawnPosition = new Vector3(25, 0, 0);
  float startDelay = 2.0f;
  float repeatRate = 2.0f;
  private PlayerController playerControllerScript;
  // Start is called once before the first execution of Update after the MonoBehaviour is created
  void Start()
  {
    InvokeRepeating("SpawnObstacle", startDelay, repeatRate);
    playerControllerScript = GameObject.Find("Player").GetComponent<PlayerController>();
  }

  // Update is called once per frame
  void Update()
  {

  }

  void SpawnObstacle()
  {
    if (playerControllerScript.gameOver == false)
    {
      int obstacleIndex = Random.Range(0, obstaclePrefabs.Length);
      Instantiate(obstaclePrefabs[obstacleIndex], spawnPosition, obstaclePrefabs[obstacleIndex].transform.rotation);
    }
  }
}

rich adder
lilac cape
#

It looks like it's spawning at the right location, but what might be causing the issues is the prop_Barrier03 doesn't ahve rigidbody/ box collider. When I click on the instantiated obstacle, Prop_Barrier03 pops up

rich adder
lilac cape
#

maybe i should put the rigidbody and boxcollider on the prop...

#

but shouldn't that stuff be on the parent?

rich adder
lilac cape
#

getting clone now

rich adder
# lilac cape

is there something you're misunderstanding because everything looks correctly

#

the original prefab had the components on the parent , no Prop_Barrier03

#

Prop_Barrier03 is just a mesh, and rightfully so doesnt need anything else on it since its just visuals

#

basically what I'm asking is, what exactly you expect to happen that isn't happening because it all seems to be doing what you set it up to do

lilac cape
#

I see what you're saying. I think I was expecting to see my prefab's name when I selected it in playmode and not the mesh. My original issue is that the fence does not fall over when I run into it with my player. My player has the following components.

 void OnCollisionEnter(Collision collision)
  {
    if (collision.gameObject.CompareTag("Ground"))
    {
      isGrounded = true;
    }
    else if (collision.gameObject.CompareTag("Obstacle"))
    {
      gameOver = true;
      playerAnim.SetBool("Death_b", true);
      playerAnim.SetInteger("DeathType_int", 1);
      Debug.Log("Game Over!");
    }

rich adder
lilac cape
#

yes

rich adder
#

is it only the prop not tipping over ? where is the code that supposed to make it fall over?

#

okay so the Event is working, thats one thing you can X off the list

lilac cape
#

Only the prop not tipping over. Prop Mass is 20kg and player is 90.7kg. Do I need code to make it fall over if the object is supposed to have rigidbody and a collider?

rich adder
#

worse case scenario and Imo a better thing to do is add a slight artificial push with some code
like AddForce

wintry quarry
lilac cape
#

I'm not freezing any xyz on the fence but I am freezing the player's x and z position/reotation

rich adder
#

oh yeah also friction plays big part here lol

wintry quarry
#

wait you're freezing the player's position?

#

That means the player isn't actually moving via physics

#

so it's definitely not going to cause any impact on the fence

lilac cape
#

it kept falling over after a few jumps so did that lol

rich adder
#

thats from rotation

wintry quarry
#

it means the way you're moving your player is completely outside the physics engine

#

if it can still move after having its position constrined on the rb

lilac cape
#

I just took off the constraints and still same result where the fence doesn't move

wintry quarry
#

it doesn't matter

#

because you're still moving the player in whatever same way you were before

#

which is outside the physics engine

lilac cape
#

I think I see what you're saying. My player's transform isn't moving at all which is correct so technically there isn't an impact happening right?

wintry quarry
#

Maybe you should explain how your player is moving

#

so we don't have to play a guessing game

lilac cape
#

the tutorial just make a moveleft script that's put on objects to make them come at the player

using UnityEngine;

public class moveLeft : MonoBehaviour
{
  [SerializeField] float moveLeftSpeed = 30f;
  private PlayerController playerControllerScript;
  private float leftBound = -15f;

  // Start is called once before the first execution of Update after the MonoBehaviour is created
  void Start()
  {
    playerControllerScript = GameObject.Find("Player").GetComponent<PlayerController>();

  }

  // Update is called once per frame
  void Update()
  {
    if (playerControllerScript.gameOver == false)
    {
      transform.Translate(Vector3.left * Time.deltaTime * moveLeftSpeed);

    }

    if (transform.position.x < leftBound && gameObject.CompareTag("Obstacle"))
    {
      Destroy(gameObject);
    }

  }
}

rich adder
#

in an ideal situation the transform gets moved by the rigidbody first since thats what simulates the physics rather than other way around

wintry quarry
#

you need to move your player via its Rigidbody

rich adder
#

transform.Translate same as teleporting , ignoring physics (sometimes it catches up creating an illusion that is working but its not working correctly)

wintry quarry
#

either by setting the velocity directly or by adding forces

lilac cape
#

Gotcha I think I'm understanding now. If I wanted to fix this I should move the player by it's rigidbody and then always have the obstacles spawn +30 units away on the X or something

strong shoal
#

one question

#

im making an retro styled game

#

is using iEnumators to make animations with meshes

#

and a foreach loop insted of animating

rich adder
strong shoal
rich adder
strong shoal
#

idk i heard that its better for performance

#

and i dont want it to be smooth

wintry quarry
#

you heard that what's better for performance?

lilac cape
#

Thank you all again. I learned a valuable lesson on physics today 🧠🤯

strong shoal
#

insted of animating it with the animation window im doing it with IEnumators and meshes bc i want to get that retro style and i dont want the animation to be smooth i want it to be like these stop animations

strong shoal
#

is it bad for performance???

strong shoal
wintry quarry
#

there's nothing stopping you from having a retro style with the animator

#

or having a non-smooth animation with the animator

strong shoal
#

no thats not what i mean

wintry quarry
#

that's what you said

strong shoal
#

i dont want it to rotate from this position to this i want it to be like not smooth at all

wintry quarry
#

bc i want to get that retro style and i dont want the animation to be smooth i want it to be like these stop animations

naive pawn
#

the causative link between "wanting a retro style" and "using a coroutine" doesn't make sense

strong shoal
#

i think it would be better that way

wintry quarry
#

What I'm trying to figure out is how you decided that's not possible with the animator

naive pawn
#

you can have discrete animation with an animationclip just fine

rich adder
#

its not like animator has some magic "smoothing frames" going on by default

strong shoal
#

ig im stupid lol

#

idk

rich adder
#

plenty of people made retro games in unity using animator not sure where you got that assumption lol

strong shoal
#

ill try it with the animator

naive pawn
#

check the dopesheet in the animation window. you can set the animation curves there, you can make animations discrete there by making a tangent constant

rich adder
#

looping through a series of frames is what animator is doing anyway and switching sprite on SpriteRenderer

subtle sedge
#

off topic but does anyone here actually like unity courses

#

im trying to learn unity but half of them are just "BUILD A PLATFORMER" or something really boring

rich adder
strong shoal
#

no

#

im trying to bake the animations

rich adder
strong shoal
#

by doing that

subtle sedge
#

but everytime i do i go to far lol

rich adder
subtle sedge
rich adder
#

"original ideas" are barely a thing, every idea has been recycled at some point or another, the execution of the idea is what makes something stand out though

subtle sedge
#

true

strong shoal
#

is it gonna bake animations by doing that

rich adder
rich adder
#

still don't know what you mean there

naive pawn
strong shoal
#

ik what it is

naive pawn
#

animations aren't automatically baked, otherwise there wouldn't be a whole thing about baking animations

supple flume
#

yall, why does it now show a dark body only

wintry quarry
#

so you have 0,0,0,0

strong shoal
#

and that is animation baking

#

in the script

wintry quarry
supple flume
#

i have to specify f in the 255?

wintry quarry
#

you just need it on one or the other

#

the point is to get it to do floating point division

#

or - again

#

the best and easiest way here is to define your colors in the inspector

rocky gale
wintry quarry
#

Make sure the input is being received correctly for example

ivory bobcat
rocky gale
#

ok did it movedir.y is changing but move.y isnt

wintry quarry
#

It's the z axis you're setting

rocky gale
#

oh yea

#

oh that just helped me ty i realized move is a vector2 so i made it vector3 and it worked

#

appreciate it

wintry quarry
#

That'll do it

rocky gale
#

yea lol

snow ruin
#

Hey all! I'm a bit of a beginner at Unity and I'm trying to detect collisions between the player and the door. Once the player collides with the door, I want it to rotate 90 degrees in the correct direction depending on where the collision is coming from. then after the collision is exited, it should close on its own. However, my script isn't detecting any collisions from what it looks like, since when my player collides with the door, it doesn't move at all. Yet, I can tell it's colliding somehow because the player is not clipping through it. Is this because I'm using the VRChat sdk? Please help :') https://pastebin.com/d9pHfnJF

high summit
#

Howdy! I'm getting to the part in my game where my voice actor is going to start recording. My noob brain originally was going to make an audio source for each line so I can just .play them when I need them but I'm realising that is stupid.

I basically want to have one audiosource object and then the clips of all the voice actor lines attached to it. But how do I then fire that off and tell it which clip to play from another script?

rocky canyon
high summit
#

But I would have to then put the audioclip attached to the script im working on?

rocky canyon
#

or aSource.Stop();
aSource.clip = newClip;
aSource.Play();

rocky canyon
#

it doesnt necessarily need to be on the gameobject

grand snow
#

Can use Resources to load it or Addressables

high summit
#

How can I load all the 'audioclips/voicelines' into this so I can then fire them off from another script?

rocky canyon
#

and swap em out

#

a Collection of some sort

high summit
#

I'd need a script on the audiosource object to do that right?

rocky canyon
#

ever heard of a singleton?

grand snow
#

If i were to design such a system i would have a list of clip addresses where i configure stuff for an NPC and either randomly pick a clip or via some id (if via an id, id instead configure a list of ids to some audio config entry)

rocky canyon
#

its a static class... u and since theres only "one" you can call it from any script as long as its in the scene

high summit
rocky canyon
#

myAudioManager.Instance.PlayClip(whateverClip);`

#

simpel as that

high summit
#

But then I have to put the clips on each script that sets it off

#

If that makes sense

rocky canyon
#
        public void Play(int index)
        {
            if (index < 0 || index >= clips.Length || clips[index] == null)
                return;

            source.PlayOneShot(clips[index]);
        }```
#

AudioManager.Instance.Play(0)

#

u can keep all the audioclips On the manager if u want

high summit
#

The manager?

grand snow
#

Perhaps understand this first before paying someone to do voice work...

rocky canyon
#

it'd be smarter than spreading them around w/ ur scripts in my opinion

rocky canyon
#
 public class AudioManager : MonoBehaviour
    {
        public static AudioManager Instance;

        public AudioClip[] clips;
        private AudioSource source;

        void Awake()```
grand snow
#

Still. its not a hard concept to have 1 component that references the assets and does playing

rocky canyon
#

yea.. either or

#

if its something small or a SO object. (has its own audio clip for ever object)

#

u can pass the clip thru the function

#

or have em on the manager.. really doesnt matter too much

grand snow
#

Is this meant to be the "player" saying things as certain major events happen?

high summit
#

Okay sweet we making progress

rocky canyon
#

with debug logs.. getting information from the collider

#

then go from there.. (make sure its stable first) then move along to directions and stuff

high summit
#

So now from my other script

#

I need to somehow fire off 'element 0'

#

I assume I need to make this a singleton like you said?

snow ruin
rocky canyon
#

for the door u can use Tweening libraries or animations.. i prefer my scripting.. (i can change values and have it open this way or that way)

#

u (or I could atleast) just have a trigger volume on either side of the door to tell which direction it should open

rocky canyon
#

thats the simple method...

high summit
#

Would it be better to put the play function inside the audio manager itself?

rocky canyon
#

and onec the door opens u can disable certain colliders

high summit
#

I guess it would

rocky canyon
#

so ur not triggering things when ur not supposed to

grand snow
#

@high summit I dont think this design will help you as you will have calls to play a clip with an index which isnt reliable. If these clips are for when the player collects something or interacts with something, why not have the clip referenced on that and get it from there to then play? (e.g. pick up fuse, get clip from fuse and play)

rocky canyon
#

it does all the logic stuff.. u just tell it what clip.. and maybe volume and pitch

#

if u wanna be fancy

high summit
#

So i need to put a play function event in here that can be called from another script

rocky canyon
#

stop.. and look up singletons and how they work first

grand snow
#

you have just confused them 😆

rocky canyon
#

u need logic in the Awake() to control and make sure theres only that 1 singleton

high summit
#

The awake on me errored, one sec

rocky canyon
#

Joshie ^

#

holy heck.. arent u in luck

#

it even has audiomanager as an example

snow ruin
rocky canyon
#

ya, im trying to ignore the fact ur using VR skds

#

i dont work with it.. so no clue if it matters or impacts whats happening here

snow ruin
#

ye fair

high summit
snow ruin
#

this is my first time too haha

high summit
#

Okay I think im getting somewhere

rocky canyon
high summit
#

Yeah I got that, 2 test ones

rocky canyon
#

then since its a static u can call it from anywhere

#

just make sure its on a gameobject or something

high summit
#

It is yeah

#

Now how do I make it play 'element 0'

#

from another script?

rocky canyon
#

u call this function

#

Singleton.Instance.PlaySound(soundEffect);

grand snow
high summit
#

But i need to tell it which clip?

rocky canyon
#

since its named instance u just:
cs AudioManager.Instance.PlaySound(yourClip);

rocky canyon
high summit
#

No but my clip is in the array

rocky canyon
#

u can code it do play certain clips..

high summit
#

Like I need it to play element 0

#

But I have to tell it that from the other script

rocky canyon
#

audioManager.Instance.PlayAPow();
audioManager.Instance.PlayDogBark();
``audioManager.Instance.PlayOOooyeaaa();`

#

then have functions that already know which clip to play..

#

but thats extra work. when u want things to be modular

grand snow
#

its not modular if you need an index to get a clip

high summit
#

Whats the difference between using the file name or the index really

rocky canyon
#

i use two methods

high summit
#

Urgh I'm a little lost here

#

Gonna be honest lol

#

Bit out of my depth

#

This is why I almost made an audiosource for each voice line notlikethis

grand snow
#

Then think, how were you going to reference them all?

high summit
#

By putting the audiosource on every object that had the original trigger event on

grand snow
#

Then do that with audio clips instead and 1 audio source and bam done

#

Oh hangon, explain with some detail how you intend these audio clips to be played?

high summit
#

Originally?

grand snow
#

is it player enters a physics trigger and a clip is played?

high summit
#

I had it working my way but I realised id have to add a bazillion audiosources for ewach clip

#

One sec ill show

#

an audiosource for every voice line

rocky canyon
#

thats stupid

#

dont do that

high summit
#

^ I agree

#

That's why I'm here lol

grand snow
#

This doesnt mean much to me, how is a fuse collected?

high summit
#

This is on an interaction script

#

but that doesnt matter anyway

grand snow
#

okay and how does the interaction work or get triggered?

high summit
#

with a raycast

#

I dont think that has anything to do with what i'm trying to achieve

grand snow
#

great. So why not have the audio clip on the object the raycast hits?

high summit
#

That's kinda what I was doing

#

Just with an audiosource too

grand snow
#

Then we instead get the clip and play it on an audio source your interaction system has a ref to

high summit
#

I just think it makes more sense to have all the voice actors lines/clips attached to it's own audiosource?

#

vs sending them 'from' objects

grand snow
#

no, please read what i said again

rocky canyon
# high summit

easy..

if(fuse2Collected){audiomanager.Instance.PlayClip(fuse2Sound);}

if(fuse1Collected)
{audiomanager.Instance.PlayClip(fuseSound);}``` and so on
grand snow
#

🙏 im trying to explain this as simply as i can
objects that can be interacted with can have an audio clip on them and this can be retrieved during the interaction process and played

high summit
#

But what i'm saying is id rather have all the voice lines ready waiting on the audiosource

#

like this

grand snow
#

I see no good reason too

high summit
#

It's just easier to manage I guess

#

Than having each voice line/clip on every object that triggers one

grand snow
#

Its not, how do you know what index the clips have?

high summit
#

I assumed I can just select 'element 0'

grand snow
#

If the answer is "i hard code an index" then you just make your life harder later

#

What if you need to insert a clip elsewhere? remove one? oh shit my indexes are all wrong now!

high summit
#

okay I see what you're saying

grand snow
#

BUT if my "fuse 1" gameobject in the scene just has the clip referenced on it already that is easy to update and is intuitive to manage

#

I am presuming they all share some script or some base class here (which would make this easier)

#

otherwise you can have a new component you use:

if(hitObject.TryGetComponent(out InteractableAudio comp))
{
   audioSource.PlayOneShot(comp.GetAudioClip());
}
#

thats all ill say for now im tired

high summit
#

okay this isn't firing/I can hear anything

#

But doesn't seem to show an error

#

clip is loaded too

#

Yeah so this doesnt load any clips

rocky canyon
#

dont assume its not firing

high summit
rocky canyon
#

i seen that

#

put a log in there next to it

#

"audio fired"

#

"audio supposed to fire"

high summit
#

kk

rocky canyon
#

thats the first thing i do.. (make sure hte audio source is close enough to the listener.. and the clips in there and the volumes high enough to here)

#

then i go back to the code/logic

high summit
#

Okay so

#
        if (fuse1collected && fusepickup2.fuse2collected && fusepickup3.fuse3collected)
        {
            AudioManager.Instance.PlaySound(allfusescollected);
            Debug.Log("audio suppose to fire");
#

I get the audio suppose to fire log message

#

and I can't try play on awake because I'm sending the audioclip to the audiosource in code lol

#

But it's not making it to the audiosource, as the clip slot stays empty

#

Also no error when it's suppose to happen

rocky canyon
#

check the clip

high summit
#

if I force the clip into it and press play on awake

#

I hear it

rocky canyon
#

why does it not look like the others?

#

may be a clue

#

ur naming is actually hella confusing

high summit
#

Yeah I'm terrible for that

#

Sorted all that out and still the same

rocky canyon
#

nah.. they still look different lol

high summit
#

What ya mean?

rocky canyon
#

why does 1 have a speaker and the other has a music note?

#

put a log in the singleton as well

high summit
#

Oh the pickup sound is just playing on an audiosource

#

Where as all the fuses is a clip

#

Pickup sound works fine

#

Just the clip is being sent to the 'main audiosource'

#
    public void PlaySound(AudioClip clip)
    {
        source.Play();
        Debug.Log("Singleton Fired");
    }

#

i'll try this

#

Yep I'm getting singleton fired

#

Okay so..

#

The singleton is firing only on the one without a valid clip

#

I didnt give it 'collectedfuse3audio' yet and that one fires the singleton

#

All fuses collected doesnt

rocky canyon
#

wait whats ur play method look like?

high summit
#

Disregard that

#

One second

rocky canyon
#

make sure its not spamming play...

high summit
rocky canyon
#

u could PlayOneShot(clip)

#

if u do Play().. u should do Stop() before it

#

so it doesn't try to play clips on top of clips

high summit
#

The clip isnt even attempting to load itself

#

The clip slot stays empty

rocky canyon
#

yea..

#

ur logic doesn do anything with it

#

lol.. 😛

#

might want to assign the clip to the audiosource if u want to play it...

#

might be helpful

high summit
#

OH wait

rocky canyon
#

ya..

high summit
#

source.clip = clip;

#

right xD

rocky canyon
#

all ur code does is Play an empty audiosource

high summit
#

Phew

#

That's got it

#

Small oversight lol, thanks dude

rocky canyon
#

np..

#

takes a second set of eyes... or extra searching sometimes

rocky canyon
#

now you've solved ur problem, created an audiomanager.. and learned and utilized a singleton

#

good run 👍

#

now u can build onto it

high summit
#

Beats having about 70 audiosources for all the voicelines lol

rocky canyon
#

ya, thats ridiculous.. lmao

high summit
#

I knew it was, I was so tempted to just do it but I was like Nah I'll do it properly

rocky canyon
#

and if ur audio is 3D u can even move around the audio source as u play it.. 😉

#

works great 👍 say i open a door.. i can play a creaking sound and use the doors transform to get spatial 3D audio

high summit
#

It's the character speaking in this instance so 2d is perfect

rocky canyon
#

cool cool

rocky canyon
#

its just really really bad idea lol
programming persuades u to make things reuseable and scaleable.. == work smarter not harder

high summit
#

Yeah honestly, I jumped into too big of a project for my first game and first time touching c# but I'm about 75% done in about 3 weeks with this little game, And I'm pretty proud of where I'm at so far, Learnt alot about cinemachine, The basic stuff, bit of 3d modeling/blender, Sound design, Optimization, Render culling for performance, Cutscenes/Interactions/Raycasting.

https://streamable.com/aj5yi6

Watch "Desktop 2025.06.01 - 00.58.52.03" on Streamable.

▶ Play video
#

The placeholder voicelines are hillarious in this lol.

snow ruin
rocky gale
#

https://www.ghostbin.cloud/soo55 hi this is my first time with multiplayer. i was wondering why the player cant see the bullet come out of the gun? but the host can still see the bullets after the client clicks, the bullets just dont show for the client. any help appreciated, thank you!

teal viper
rocky gale
#

o ok

umbral bough
#

Hi, I am working on an asset.
It works fine when located in the Assets directory, however, if I add it as a package from git url, it can't find the Easings namespace.
What am I doing wrong?
Here's the asset, there's only 2 scripts:
https://github.com/nnra6864/SmoothSceneCamera
Please @ me and thanks in advance!

teal viper
#

You'll nee to check what assembly is the erroring script part of as well as the Easings script, and whether it's in your project/packages at all.

slender nymph
#

seems like the Easings class is in the same package. what's likely the issue is that when it is in the Assets folder, the Easings class is being added to the Assembly-CSharp assembly. however that won't happen for packages, you are required to use asmdefs for packages
https://docs.unity3d.com/Manual/cus-asmdef.html

bright arch
#

using textmeshpro, is there a way to have it so that each line of text is underlined from one border of the thing all the way to the other border? so like not constrained by the text, rather the underline goes all the way across

median hatch
#

this is a coding channel

shut swallow
#

mb