#💻┃code-beginner

1 messages · Page 105 of 1

sullen zealot
#

ty

eternal falconBOT
fossil tree
#

oh i see so i need to put the loop in the coroutine?

slender nymph
#

your sprite object has a navmesh agent on it. that means it is moving (mostly) independently of the parent object

nimble tartan
slender nymph
#

why do you have both a navmeshagent and a rigidbody?

#

but also yes, it should be attached to the object that you want to actually move

nimble tartan
slender nymph
#

the tutorial told you to put a rigidbody on the parent object and a navmeshagent on the child object? 🤔

dusk minnow
#

Hey, how can i play a sound that continues playing after i disable the gameobj with the Audiosource

slender nymph
#

don't make the AudioSource a child of the object you are disabling

polar acorn
dusk minnow
#

alr thanks

nimble tartan
slender nymph
#

unless your rigidbody is kinematic you shouldn't even have both a navmeshagent and a rigidbody on the same object

nimble tartan
nimble tartan
#

@slender nymph great, talking about good patterns, to create enemies, is better to put everything inside the same object like I did with player or separated? if I put separated, which is a best pattern for that (talking about components inisde?)

slender nymph
#

it really depends on how you want to organize everything. whatever moves it should be on the upper most object that needs to move

sullen zealot
#

public void OnBrake()
{
braking = true;
}
i have this code that makes the car brake when pressing the bindings for this action. how can i make it so that braking turns false once the player stops clicking the binding?

#

or is there a way to check if is braking?

#

something like if(inputAction.brake) ?

slender nymph
#

you're not really providing enough context for that OnBrake method. but if you are unsure how to use the input system then read the docs pinned in #🖱️┃input-system

sullen zealot
#

it has only a binding space[keyboard]

#

it uses send message behavior

slender nymph
#

lovely. then OnBrake is likely being called each time you press the key as well as each time you release it. of course since you're using SendMessages you don't really get any of the useful info about the input action to determine the current state of the input

merry spade
#

Why is the sphere teleporting down the cliff and not slowly falling like in the beginning?

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


public class Movement : MonoBehaviour
{
    [SerializeField] float Speed = 6.0f;
    [SerializeField] float gravity = -30f;

    float velocityY;

    CharacterController controller;

    void Start()
    {
        controller = GetComponent<CharacterController>();

    }

    void Update()
    {
        UpdateMove();
    }

    void UpdateMove()
    {


        Vector2 targetDir = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
        targetDir.Normalize();

        velocityY += gravity * 0.5f * Time.deltaTime;

        Vector3 velocity = (transform.forward * targetDir.y + transform.right * targetDir.x) * Speed + Vector3.up * velocityY;

        controller.Move(velocity * Time.deltaTime);


    }
}
sullen zealot
#

so i should just use braking ^= true; ?

slender nymph
sullen zealot
rich ember
#

Anyone know any good 3d player controller tutorials

rich adder
rich ember
#

I looked on youtube but most of them use input x and y axis which doesn't allow changing keybinds

rich adder
rich ember
#

I have a controller that i programmed but it feels weird. I feel like I am having to set speeds way higher than I should just to get the character to move at all and it also is inconsisten and jumps in speed occasionally

rich adder
#

you're still using a vector2

sage mirage
#

Hey, guys! Is there a way to DontDestroyOnPause a game object rather than on load?

sage mirage
#

I mean if I want to pause my game and I want music to be stopped and after that when I click continue button to play it again not to be repeated

rich ember
slender nymph
rich adder
# rich ember

probably should not be mixing Time.deltaTime with rigidbody movements

slender nymph
#

that actually looks fine since they appear to be increasing the values over time

rich ember
#

oh really? I thought you were supposed to use time in player movement

slender nymph
#

you don't use deltaTime when applying physics. you also don't multiply your velocity by deltaTime. with the exception of increasing velocity manually over time, but you only multiply the increase by deltaTime before adding it to the velocity, never multiply the velocity itself by deltaTime

rich adder
#

oh true You're right thats only going on speed increase

rich ember
#

or leave it since it is on an increase instead of directly on velocity?

slender nymph
#

i don't have the full context so i don't know. what i see seems to be fine to leave the deltaTime multiplication in. however those extra 100 multiplications seem pretty sus and make it seem like you're not actually increasing it over time, but rather just adding to a zero vector and resetting the vector each frame

sage mirage
slender nymph
#

have you looked at the !docs for AudioSource?

eternal falconBOT
sage mirage
#

API or manual?

#

Yes I am looking things here i know that documentation

slender nymph
#

great! if you've looked at the docs, the surely you've found the Pause method

sage mirage
#

By the way, I have audio mixer in order to manage my sounds in game. Is it the same for audio mixers, I mean pausing and unpausing?

slender nymph
#

the audio mixer is irrelevant here if you just want to pause an audio source

sage mirage
#

ok!

rich adder
sage mirage
#

Oh, how handy and cool it is there is a method actually for pausing and unpausing audio source!

sweet plover
#

guys, how would i use the rb.addforce on a character controller??

rare basin
#

You don't mix character controller with rigidbody

sweet plover
#

ik but what would be the way to replicate it

rare basin
#

But these are 2 different things

summer stump
#

Learn physics and implement it yourself 🤷‍♂️

rare basin
#

Or just use rigid body 🤷

sweet plover
#

i mean i could do the player movement with rigid body

rare basin
#

No i just said you don't mix it

summer stump
#

You cannot do that.

sweet plover
#

alr ill remake the player movement with rigid body

summer stump
#

They mean INSTEAD of a CharacterController

sweet plover
rare basin
#

Your approach is not very good so

summer stump
rare basin
#

You asked he answered 🤷

tranquil glacier
#

I am having a lot of difficulty with this code, I am trying to make a script that plays an animation only one time, and after time gives control back to the player. My mind is beyond this code, it just looks like spaghetti

eternal falconBOT
rare basin
#

Looks like good case for animation event

tranquil glacier
rare basin
#

Where at the end you restore the things you want

tranquil glacier
#

its either I have it where it can play but you can play it a second time (not what I want)

or it never plays in the first place (def not what I want)

eternal needle
# sweet plover guys, how would i use the rb.addforce on a character controller??

the built in CC isnt really too good, you should do as suggested above to use rigidbody instead.
But to answer your question, if you had to move a CC in this way then I would have another vector on your movement script which handles external forces. Every time you move, you would move by (regular move) + (external forces). Then you can handle reducing the external force however you want every frame, since this is already apart of the update loop. Instead of the rb.addForce, you would call some method which adds to your external force

small gull
#

would this work for hiding a mouth when talking?

#

void update()
{
if (voice.IsSpeaking)
{
mouthopen.SetActive(true)
}else
{
mouthopen.SetActive(false)
}

if (voice.IsSpeaking)
{
mouthclosed.SetActive(false)
}else
{
mouthclosed.SetActive(true)
}
}

slender nymph
#

!code

eternal falconBOT
small gull
short hazel
#
mouthopen.SetActive(voice.IsSpeaking)
mouthclosed.SetActive(!voice.IsSpeaking)

Short form

small gull
#

its to hide the closed mouth when talking and to show open mouth

small gull
#

cs
void update()
{
if (voice.IsSpeaking)
{
mouthopen.SetActive(true)
mouthclosed.SetActive(false)
}else
{
mouthclosed.SetActive(false)
mouthopen.SetActive(false)
}
}

sullen zealot
#

Yes

small gull
slender nymph
#

even better would be an event or something and immediately reacting to the voice beginning and ending to speak rather than constantly checking in update

summer stump
small gull
#

ive been here for 5 mins

short hazel
#

To read!

autumn tusk
#

why is my script refusing to take my animator

summer stump
slender nymph
autumn tusk
small gull
#

im just comfused

summer stump
autumn tusk
#

player_controller

summer stump
slender nymph
autumn tusk
slender nymph
#

why would you need to?

#

your animator controller goes into an animator component which is what your code will interface with

small gull
autumn tusk
#

im confused then

summer stump
short hazel
# autumn tusk im confused then
  1. Add an Animator component on your player
  2. Drag-drop the Animator Controller (the asset in your project files) into the Animator component you just created.
  3. Reference the Animator component into your script
autumn tusk
slender nymph
#

where

autumn tusk
#

in my main player control script

slender nymph
#

wdym in the script? Animator is a component

short hazel
#

That's a variable to fill in

#

You haven't put anything in it

#

Hence the "(None) Animator" that is displayed

autumn tusk
#

this is what my animator looks like now

slender nymph
#

show the animator component

short hazel
#

Animator is just like your script, or a Collider, or a Rigidbody. It's attached to the object
What you're showing here is the asset, not the component

autumn tusk
#

im using 1d movement which gets flipped accordingly based on cursor direction

summer stump
slender nymph
autumn tusk
#

ok now i see it

waxen wyvern
#

hey can some help I have a small game I need to add a gun to the camera in first person 😄

slender nymph
waxen wyvern
#

-.-"

autumn tusk
#

ok now that i dragged in the animator

#

how do i activate a trigger

slender nymph
#

have you looked at the !docs for the Animator class?

eternal falconBOT
boreal tangle
#

does someone know how I can work a project from2 diffrent computers using Github. I made a github account and a repos on the first computer using Github destop. I then cloned it on the second computer. everything I do on both get sent to Github but the changes don't get put on the computers.

slender nymph
#

you have to pull the changes

static cedar
#

Push and pull. UnityChanThink

boreal tangle
#

i pulled but I dont see any changes in the history

polar acorn
#

Push from the computer that changed stuff, pull on the ones that need stuff

slender nymph
boreal tangle
#

I am working in a cloned one

polar acorn
#

Are you certain you pushed and not just committed

boreal tangle
#

i pressed push in the menu

#

i meant pull

slender nymph
#

process for syncing changes:
Make Change > Commit Change > Push Change > Pull Change on other device

boreal tangle
#

oh it worked. I just had to push again on the first computer. thank you!

whole isle
#

can somone recommend a tutorial for building a wave genrator for enemies in a 2d top down game

whole isle
#

that a 2d tower defence game

#

but yh i did that

#

im watching this vid currently

frosty hound
#

Why does it being a tower defense game matter? It's a wave spawning tutorial

whole isle
#

fair point

hoary karma
#

can i ask question about animation here?

slender nymph
waxen wyvern
#

-.-" how do I attach an object to the camera in unity like a gun

polar acorn
waxen wyvern
#

but it is attached

polar acorn
waxen wyvern
#

let me check

#

now it works 😄

autumn tusk
#

uh

how the hell does this happen

slender nymph
#
  1. this is a code channel
  2. is appears your animation is very short
autumn tusk
#

i dont know how but for some reason this exit time transcends time itself

slender nymph
#

yeah it's so incredibly small that it is effectively 0

static cedar
#

That's 3×10^-9.

#

That's about 0.000000003.

vast matrix
#

How do I get my character to jump only once?
here is my code:

            Rigdy.AddForce(0, upwardForce * Time.deltaTime, 0, ForceMode.VelocityChange);
        } ```
verbal dome
#

GetKeyDown for single key press

#

GetKey is continuous

slender nymph
#

start by using GetKeyDown instead of GetKey. then you probably also want to do some sort of ground check

vast matrix
verbal dome
#

You probably want to remove deltaTime from the equation too

vast matrix
#

but If I were to want him to be able to double jump how would that work?

verbal dome
#

And when you try to jump, you check if any jumps are left

verbal dome
#

If yes, subtract from the counter

vast matrix
#

Just playtested
when using Input.getkeydown if I spam click the player still flies any way to prevent this
Thanks

soft canyon
#

Whats a good way to learn? Can anyone recommend any specific courses or anything?

vast matrix
vast matrix
#

can I have an if statement inside of an if statement?

vast matrix
swift crag
#

you aren't gradually accelerating the player upwards by applying force every frame

#

deltaTime is used when you're doing something every frame, and need to make sure you do the right amount each frame

vast matrix
#

ngl I just copy pasted the other code so didnt really pay attention to the deltatime thing

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

public class SwordCollision : MonoBehaviour
{
    
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("Collision");
        // Check if the collider belongs to the "Enemy" layer
        if (other.gameObject.layer == LayerMask.NameToLayer("Enemy"))
        {
            // Handle enemy hit logic here
            Debug.Log("Enemy Hit!");
        }
    }
}

why doesnt this work?

#

it gets activated during animation

waxen wyvern
#

hey I have a zombie chasing me but it is flying it does nt know where the ground is...

#

the code looks like this

#

public class Zcharacter : MonoBehaviour
{
public float moveSpeed = 3.0f; // Adjust this speed as needed
private Transform playerCamera; // Reference to the player's camera

void Start()
{
    // Find the player's camera
    playerCamera = FindObjectOfType<FirstPersonController>().playerCamera.transform;
    if (playerCamera == null)
    {
        Debug.LogError("Player camera not found!");
    }
}

void Update()
{
    // Chase the player if the player's camera is available
    if (playerCamera != null)
    {
        // Move towards the player's camera position
        transform.LookAt(playerCamera);
        transform.position += transform.forward * moveSpeed * Time.deltaTime;
    }
}

}

slender nymph
#

!code

eternal falconBOT
waxen wyvern
#
public class Zcharacter : MonoBehaviour
{
    public float moveSpeed = 3.0f; // Adjust this speed as needed
    private Transform playerCamera; // Reference to the player's camera

    void Start()
    {
        // Find the player's camera
        playerCamera = FindObjectOfType<FirstPersonController>().playerCamera.transform;
        if (playerCamera == null)
        {
            Debug.LogError("Player camera not found!");
        }
    }

    void Update()
    {
        // Chase the player if the player's camera is available
        if (playerCamera != null)
        {
            // Move towards the player's camera position
            transform.LookAt(playerCamera);
            transform.position += transform.forward * moveSpeed * Time.deltaTime;
        }
    }
}


slender nymph
#

and where are you telling it where the ground is at?

#

because right now all you do it make it point at the player and go exactly that direction

waxen wyvern
#

it is called terrain

#

the ground so i need ot add that?

slender nymph
#

depends on what you mean by "add that"

waxen wyvern
#

add that o the code some how

slender nymph
#

what exactly do you think you need to add based on my previous statement?

waxen wyvern
#

tell it to stay on the terrain ;D

rich adder
#

you need physics/gravity of sorts

waxen wyvern
#

I have that for my player but i need o have that for the other characters

rich adder
waxen wyvern
#

Physics.Raycast

rich adder
#

nah you just need to set the target to a variable and ajust the y post to your own

waxen wyvern
#

but if I go up on a hill it will go under the hill

rich adder
waxen wyvern
#

3d

rich adder
#

so use a navmesh

vast matrix
#
            Jumps == false;
        }
``` This is my code. How do I make Jumps false without triggering the error message " only assign call and increment could be used as a statement"
vast matrix
#

oh

slender nymph
#

that's also not the way to do a ground check

slender nymph
vast matrix
#

ok

waxen wyvern
#

i go sleep cya

cedar prairie
#

I am following brackeys basic tutorial to get my grips on the engine again and on the 5th tutorial about collision he sets up a public variable to put the movement script in

#

why do i need to write the script name then the variable name

#

just for me to set it manually outside

#

does it need to have the script name there?

wintry quarry
#

you always put typename variablename;

#

C# variables all have types and names

cedar prairie
#

sorry maybe i phrased it wrong

wintry quarry
#

Yes your phrasing is part of your misunderstanding here.

cedar prairie
#

he uses the same name before the variable name as the script he uses

wintry quarry
#

when you create a class you are defining a new type

static cedar
cedar prairie
#

i woludda thought i would have done something like Script before hand insted of saying the name of one of the scripts

wintry quarry
wintry quarry
static cedar
#

C# don't just let you assign whatever you want. You don't assign it to an int then a string.

You promise that the variable will only be of that type.

cedar prairie
wintry quarry
#

you need to tell it which instance it's referring to

#

If you have a Cat script, you could have 25 cats in the scene at once

#

this tells it which cat you mean

cedar prairie
#

huh alright i kinda understand lol, i have used GMS for 2 years so its a bit of a change

#

thanks for the elp

wintry quarry
#

GMS definitely has instances of things

cedar prairie
#

yeappers

wintry quarry
#

this is a fundmamental concept in programming basically

static cedar
#

In GMS, I think you get instances by referring by ID. I'm not sure if that's correct.

cedar prairie
#

brakeys doesnt explain it very well as he is doing it, for me to learn i gotta know why certain things needs to be done

cedar prairie
teal viper
#

Brackeys is not the best for learning the basics.

#

He expects you to already know some c#

cedar prairie
#

just need fo find footing then ill branch out on my own

cedar prairie
teal viper
#

Well, that's what you can tell from their tutorials.

static cedar
#

What? UnityChanThink

cedar prairie
#

i am watching the begginner basic one

#

he has constantly explained stuff very simple stuff like variables before in this

#

he just doesnt for some things

#

he said that the basic movement might be hard for the person watching

teal viper
#

Okay, but their tutorials are still not great for a beginner.

cedar prairie
#

anyone who knows even a little but of c# woludent find it difficult lol

teal viper
#

I'm not saying it's difficult. It's specifically because he omits things like that.

timber tide
#

brackys has actual c# tutorials too

static cedar
#

It's still easier to learn C# first before unity.
It should be easier to separate Unity's magic and normal C#.

timber tide
#

you can manage a bit with basic coding knowledge but if you don't have that oop knowledge of classes, objects, and constructors then you're not* going to get very far beyond flappy bird.

cedar prairie
#

so when i am going to refrence a script i need to declare it first as a vairable at the start then i need to drag and drop the same script into it in a public thingy. Still dont know why there isnt just a "script" thing then you can drag and drop it

#

but i shall adapt

iron veldt
#

Anyone know why my laser just freezes (along with my ship) the second I left click? I know without enough detail it might be hard so if you need the script just ask. Thank you

static cedar
timber tide
#

another thing too is not understanding the concept of this monobehaviour class and why we don't have an actual constructor.

#

that'll bite you in the butt later

timber tide
iron veldt
solemn fractal
#

Hey guys this piece of code: cs playerBarShoot.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition); I am using to make sure my playerBarshoot follows my mouse position. Woirks, but as it is UI Image and it needs to be as I am using the filled option to fill every time I shoot.. Like a timer between shoots. But its following inside the UI view. I want it to follow in the screen of the player, not the UI. Any ideas?

timber tide
#

eh, if your screen is larger than the UI then probably need some normalization of coordinates

solemn fractal
#

hmm.. yes its bigger.

#

wayyy bigger hahaha

#

is there a way to create a filler imge like UI image that is not part of the UI ?

timber tide
#

is there a reason you've the player as a UI image and not just in the world?

#

or w/e you're trying to get follow your cursor

solemn fractal
#

well.. i need the Filled option on the Image UI

#

can I get that without being an UI image?

timber tide
#

my solutions usually stink by doing masks and shaders, but you can probably do like a world canvas perhaps

solemn fractal
#

hmm its too much just for a small feature i want to implement

#

is there a way to change my ui size and fit my screen size?

timber tide
#

stuff like that

#

you can do scale with screen size on the canvas

solemn fractal
#

hmm true.. scale might work.. thank you

iron veldt
#

Hey guys so right now when I click somewhere my object looks right down into the infinite void of space, and all I want it to do is rotate toward where I click and not just be pointing down all the time. If I lock all of the rotation it doesn't rotate at all, but if I don't lock one of the axis is points downward. It is probably because of this part of my script where I have it look at where I point, but idk how to make where I click not some area way below the object if that makes any sense. Here is a part of my script where I have it set to look in that direction.

timber tide
#

so the z rotation is changing?

#

debug your target position that it's correct and then your transform rotation

#

ah, maybe want to be explicit on the rotation axis on the lookat I think

#

use the overload method

iron veldt
#

Ok so it says that if I leave out the worldUp parameter, the function will use the world y axis...which is what it is doing. I probably need to add the worldUp parameter, but I have no idea how...

timber tide
#

you probably want to rotate on the z

#

does worldup become z in 2D

slender nymph
#

you ideally don't want to be using transform.LookAt for 2d. just set the object's transform.up or transform.right to the direction to the mouse

iron veldt
slender nymph
timber tide
#

unity is a 3D engine, but there are tools for 2D but if you do want that depth then stick with 3D

slender nymph
#

2d is still 3d. you just typically ignore the Z axis for many things

timber tide
#

yeah true, but I guess you can cut down on collider types, but not sure if say a circle collider is more performative from a sphere collider because math

#

I would assume so though

#

I find it interesting how sphere colliders are generally considered performative, but a cylinder collider is a big nono

summer stump
timber tide
#

basically because math

solemn fractal
#

hey guys. Using this ```cs
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
mousePosition.z = transform.position.z;

    transform.position = new Vector3(mousePosition.x, mousePosition.y - 1f, mousePosition.z);```to make a bar follow my mouse.. it works.. but i feel there is a delay.. I mean very small but if I move the mouse bit faster the bar takes mili seconds to follow and I can see that.. tried fixedUpdate got it worst.. any advices?
verbal dome
#

Though for overlaps, it could basically be a capsule check + box check combined

#

But calculating contact points etc. would be tricky

timber tide
#

Was more that I was suggesting a cylinder collider as a primitive but apparently it's not recommended

#

or at least what I got from scouring some stuff

north kiln
solemn fractal
solemn fractal
#

Thank you

iron veldt
#

So my player controller script works just fine until I add a script to my enemy object. When I add the script and press play nothing works. Anyone know why that is?

north kiln
eternal falconBOT
iron veldt
#

Post code from all the scripts or...

north kiln
#

So far you've provided little to no information, I don't know what scripts you have

iron veldt
north kiln
#

Well, that's not normal behaviour, so yeah, some more context is required

#

Are there errors in the console window? That's the only thing that could help give answers without any code posted

iron veldt
#

Here is a screenshot of my playercontroller script because I am struggling figuring out how to copy from the website:

north kiln
#

You paste it in, click save, and copy the new url

iron veldt
#

ok thanks should I do that with all of the scripts?

#

that relate to what I am trying to do at least

north kiln
#

Add some logs/use the debugger to find out what code's running

summer stump
#

You should put some Debug.Logs into various methods. Nothing here should cease to function based on another script

Edit: 🦥 what vertx said

north kiln
#

because there's nothing immediately obvious that could cause it to not work

twin bolt
#

Why is camera.current not fetching the camera that is currently rendering?

north kiln
#

Is it currently rendering? Because it's only set when actually in the render loop

twin bolt
twin bolt
north kiln
#

Most of the time you will want to use Camera.main instead. Use this function only when implementing one of the following events: MonoBehaviour.OnRenderImage, MonoBehaviour.OnPreRender, MonoBehaviour.OnPostRender.
?

#

And are you using the events that it specifies, ie. the ones where the camera is currently rendering?

north kiln
#

Great, then don't use that property then.

twin bolt
#

So how do i check the current camera in use?

north kiln
#

You don't. Multiple cameras could be rendering.

Most of the time you will want to use Camera.main instead.

summer stump
woven crater
#

scalling wide should i use get set operator to trigger a function or invoke an event when the variable or an object is change or created

teal viper
#

An event invoked in a setter sounds good imho

#

Though it really depends on the exact use case. If there's more logic in the object that owns the property, maybe a setter method would make more sense.

solemn fractal
#

hey guys,. i have this IEnumerator.. but even if I change run time the value of lifeRegenCap , and the value is being changed because I see it on debug.log for some reason the time seems not to change inside the WaitForSeconds. Why is that? ```cs
private void LateUpdate() {
StartCoroutine(LifeRegen());
}

private IEnumerator LifeRegen(){
        Debug.Log("LIFE CAP: " + lifeRegenCap);
        if (playerCurrentHeath < playerTotalHP){

        playerCurrentHeath += lifeRegen;
        OverHeadDamage _dmgOverHead = Instantiate(_overHeadDamagePrefab, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
        _dmgOverHead.meshProText.text = "+" + lifeRegen;
        _dmgOverHead.meshProText.fontSize = 20;
        _dmgOverHead.meshProColor = Color.green;
        
        if (playerCurrentHeath > playerTotalHP){
            playerCurrentHeath = playerTotalHP;
        }
    }
    yield return new WaitForSeconds(lifeRegenCap);
} ```
north kiln
#

Don't start a Coroutine in an update function without a check to see if it's already running. You are just creating a new coroutine every frame

summer stump
solemn fractal
#

Hmm ok, thank you guys, I will try something else.

#

just wanted to control a life regen per second. and coroutines sounds the good way to go.. not sure

summer stump
solemn fractal
visual hedge
#

var go = Instantiate(FloatingText, transform.position, Quaternion.identity, transform);
how do I instantiate this GameObject 1f higher on Y axis?

north kiln
#

transform.position + Vector3.up

visual hedge
#

nope, still doesn't work somehow

#

still spawns it at 0, 0, 0

summer stump
#

No sorry, not quite true with that last part

visual hedge
#

can you elaborate on this pleaase? what do I put to offset it then?

summer stump
#

Sorry, I misspoke before

woven crater
#

why my debug.log return null exception?
i did set public float shootSpeed=10f; in PlayerAttribute

summer stump
#

PlayerAttribute is the null thing there

#

Do you have that component on the same object as this script?

woven crater
#

nope

summer stump
# woven crater nope

Well that's why it's null
GetComponent gets a component on the same object it's called from

woven crater
#

neat i learned something new

summer stump
frigid sequoia
#

weeeell..., hi there!; I have an slight issue that I don't know if you have stumbled with

small mantle
#

I am making a Top Down 2D project. In the game I can walk into a door and it would change the scene to a House Scene. Now I have multiple houses that are in different locations. I am wondering how I can make them change the Scene back to the "Town" scene that all the doors lead back to, but right in front of the door that they went into to get to the other scene. (If more information is needed, let me know.)

frigid sequoia
#

I have this code that just is a base move object in a loop between two positions script, but it does some weird things when it has to move in two axis if the scale/rotation is not the default one like reaching one of the axis position sooner than the others; do you know why that might be?

minor vault
#

can someone help me with this error? error CS1061: 'AnimationEvent' does not contain a definition for 'stringParameter' and no accessible extension method 'stringParameter' accepting a first argument of type 'AnimationEvent' could be found (are you missing a using directive or an assembly reference?)

north kiln
north kiln
#

Are you using Visual Scripting?

summer stump
visual hedge
teal viper
gaunt ice
#

Do you know what is the second parameter of the instantiate you use?

summer stump
teal viper
eternal falconBOT
gaunt ice
#

You want to have a floating text in screen space while the gameobject in world space?

summer stump
minor vault
small mantle
visual hedge
north kiln
# minor vault yea visual scripting 1.9.1

If the package has any updates in the package manager, install them. If not, try to change versions to something else.
That package version must not be compatible with the Unity version you're using

summer stump
frigid sequoia
#

sry first time here, I don't think I have any recording apps at hand though

teal viper
teal viper
small mantle
# teal viper What part exactly is unclear?
        if (collision.gameObject.TryGetComponent<PlayerInput>(out PlayerInput s1)) {
            SendToScene();
        }
}
``` This is attached to the Door Object and has a BoxCollider2D. When the Player Collides to it, it will change Scene. 

```c# private void OnTriggerEnter2D(Collider2D collision) {
        if (collision.gameObject.TryGetComponent<PlayerInput>(out PlayerInput player)) {
            DoAnimation();
        }
    }```  This code is again attached to the Door Object, but is a child of it. It has a PolygonCollider2D and detects the Player before.
How would I implement what you are telling me to here?
teal viper
#

There are many ways, but for example, store the position of the door in the outside scene in a game manager that is persistent between scenes. Then use that position when you transition back to the outside scene.

small mantle
teal viper
small mantle
small mantle
#
 public class GameManager : MonoBehaviour
{
    public static GameManager Instance;
    public Transform playerSpawnPos;

    private void Awake() {
        Instance = this;
        DontDestroyOnLoad(gameObject);
    }

}```  Just the GameManager Script

This code is inside another Script on the Door Object*
```c#
private void Start() {
        newPlayerSpawnPos = GetComponent<Transform>().GetChild(0);
    }

    private void OnTriggerEnter2D(Collider2D collision) {
        if (collision.gameObject.TryGetComponent<PlayerInput>(out PlayerInput player)) {
            GameManager.Instance.playerSpawnPos = newPlayerSpawnPos;
        }
    }``` When the Player collides with the Door Animation Collider which is pretty big is radius, it will set the GameManagers playerSpawnPos to the new Position. This works and teleports the player correctly, however it only works within the scene it was changed it. After I change the Scene it says the Transform is missing. I'm guessing it has to do with the fact that the object isn't found in the scene. How can I fix this?
summer stump
small mantle
summer stump
#

The value will persist, but yes the Transform is destroyed unless THAT object is also put in DDOL

visual hedge
frigid sequoia
#

ok, so I think I figure it out why it is failing; if someone is interested is cause it is moving in a local space instead of global so when rotated it moves in a different vector

#

Reference image

#

I want the coordinate at which it moves to be local though, any way of solving this?

iron veldt
#

How do I make it so that when two objects collide they are both destroyed?

summer stump
frigid sequoia
iron veldt
#

thanks

frigid sequoia
#

try using OnTriggerEnter if it doesn't work with what you have

summer stump
small mantle
#

Why is my GameManager duplicating on returning to a scene? I am using DontDestroyOnLoad();

polar acorn
summer stump
# iron veldt thanks

Also, don't just do OnTriggerEnter if it doesn't work. Only do that if you want to work with trigger colliders. It could be not working for other reasons

polar acorn
summer stump
smoky jetty
#

So I'm trying to get better at decoupling code, it's something I'm struggling to find ways to get around. For example. I have several objects in my game, like a dash pad for instance. This dash pad has a script on it that gets a reference to the player's speed so when the player enters the dash pad, it can manipulate this variable. Is there a better approach to this or is this pretty common practice?

teal viper
#

What's a "dash pad"?

teal viper
unborn sinew
#
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    [SerializeField] GameObject player;
    Vector3 offset;

    private void Awake()
    {
        offset = new Vector3(0f, 0f, -10f);
    }

    private void LateUpdate()
    {
        transform.position = player.transform.position + offset;
    }
}

Player has rigidbody based movement with AddRelativeForce.
The environment is zero gravity and the camera is just supposed to follow the player. The movement is nice and smooth if I make the camera the child of the player, but its jittery when I use this script and there is some weird ghosting of the background.

#

2D btw

teal viper
#

That would indicate that your rb is not interpolated properly.
Also, did you try using Update instead of late update?

unborn sinew
#

I also set the rigidbody's interpolate to interpolate and it didn't work

frigid sequoia
#

Usually combining those eventually gets the result I want for me

unborn sinew
#

okay

#

nothing seems to be working

#

in some cases the background is jittery, and in other cases the player

charred condor
# unborn sinew in some cases the background is jittery, and in other cases the player

I had this issue before. Can't remember how I fixed it but start by checking the following:
• Make sure rigidbody addforce or any rigidbody movement is handled in FixedUpdate()
• Make sure camera follow is in LateUpdate()
• Try using Rigidbody.MovePosition instead of AddForce or AddRelativeForce

playerRigidbody.MovePosition(targetPosition);

I will see if there was something else I missed.

When I had the same issue like a month ago I found a solution somewhere on Google.

teal viper
stark sonnet
#

im receiving these errors and i'm not sure where i'm missing them. visual studios says there are no issues. will post my code in next message

teal viper
#

But to put it simply: don't move or rotate the object in physically incompatible ways.

stark sonnet
#

anyone able to help me pinpoint my errors? i've been at this for awhile and i think lack of sleep is getting to me 😅

teal viper
eternal falconBOT
teal viper
stark sonnet
#

is it saying lines 5 and 46?

#

i was used to VS saying what lines then i had to redownload it and i think thats why its not configured

stark sonnet
#

I did it. Its still saying no issues in VS but I have 4 in Unity.

charred condor
stark sonnet
#

Gotcha.

teal viper
#

Share a screenshot of unity workload in vs and the external tools in unity if you still have the problem.

charred condor
teal viper
#

It's the same as was linked to them earlier...

charred condor
#

Might have to download the latest .NET Framework also

acoustic berry
#

whats the best way for store lots of dialogue text? Do you just have a class that has a gigantic 1000+ size preset array, and then lookup the text at runtime as needed?

stark sonnet
#

okay so i got it configured. turns out the entire script i learned in this tutorial is completely broken from what I'm seeing 🙄

#

thanks for the help guys!

#

oh! and one more question. anyone know how to turn off the suggestion/autocorrect thing? it keeps autocorrecting me to things i don't want typed and I'd just rather not deal with it

fierce shuttle
# stark sonnet is it saying lines 5 and 46?

The first number (5 in your case) is always the line thats producing the log, and the second number (46 in your case) is the number of characters, so if you counted 46 characters, on line 5 in your camera controller script, youd find your error - I always ignore the second number and just focus on the first, usually itll be clear enough that I dont need to count the letters

stark sonnet
fierce shuttle
#

Yup, and in most cases, you can also double-click the message in Unity, and it should highlight it in VS

fierce shuttle
# stark sonnet oh! and one more question. anyone know how to turn off the suggestion/autocorrec...

I believe this is called "CodeLens" or "IntelliSense", this may help: https://learn.microsoft.com/en-us/visualstudio/ide/reference/options-text-editor-csharp-intellisense?view=vs-2022

Though tbh, I always find it a useful feature to have enabled, when you get familiar with it, it can really help save time typing every letter all the time, though while learning, I can see how it can get a bit intrusive

Learn how to use the IntelliSense page in the C# section to modify settings that affect the behavior of IntelliSense for C#.

queen adder
#

i was wondering why this wasn't working it works at the center (0, 0) but whenever i move it away it will just shoot away from the center not the game object go against if anyone has a simpler way to make a simular acting projectile feel free lol im open to ideas

languid spire
eternal falconBOT
queen adder
#

it also broke bc of an update

#

ive been coding without it

#

its fine

languid spire
#

you need a configured ide to get help here

queen adder
#

ik its slower

#

i just need help 😭

languid spire
#

server rules, configure your ide

queen adder
#

fml

#

back to google ig

teal viper
#

Lol, you really like to shoot yourself in the foot.😅

burnt vapor
#

Just configure it, it's not hard

abstract finch
#

Whats the advantage of defining a new list outside of a function in the global variables?

burnt vapor
#

You're really shooting yourself in the foot by not having a properly working IDE

burnt vapor
queen adder
#

ik

burnt vapor
#

The benefit is having access to it from other functions

abstract finch
burnt vapor
#

What do you mean define?

#

Don't you mean assign?

#

Are you referring to the = new List<Item>(); part?

abstract finch
#
    {
        _itemPool = new List<Item>();
    }```
burnt vapor
#

The difference between these two?

abstract finch
#

Hmm the difference is like resetting a list i think

burnt vapor
#

Kind of

abstract finch
#

but by default i should always just define it in the global field right?

#

there literally no disadvantage

#

maybe performance?

burnt vapor
#

Technically they are the same thing. The difference is that you assign a new list to the variable when you call CreateItemPool, whereas the other one will have the list assigned when your class is created

queen adder
#

ok done

#

sorted

burnt vapor
#

The only performance difference is when allocation happens to create the list. Nothing you should worry about

abstract finch
burnt vapor
#

The thing with doing it through a method is that the list will be null for a period until the method is called

#

That's a key feature of reference types, like the list

queen adder
#

done

burnt vapor
#

Again this boils down to allocation which should not matter to you

languid spire
teal viper
#

Target - source

#

If it's towards the target

queen adder
#

we want it to move away and it does at 0, 0 but not at any other cords

teal viper
#

Is your target in the center?

#

Away from what?

queen adder
teal viper
#

Where do you want it to move?

queen adder
#

yes

#

sorry

teal viper
#

From center to where?

queen adder
teal viper
#

Then, position - goAgainst is the direction

#

Draw it on paper.

queen adder
#

it doesnt work the projectiles just stay at a stand still

#

ima keep playing aroound with it

#

sorry for bothing you

teal viper
queen adder
#

i found out smth that works

#

i just dk why

#

it looks the exact same as before

#

idk just glad it works now

acoustic scaffold
#

Hi. I am new to unity and XR development. I am following this tutorial https://youtu.be/D8_vdJG0UZ8?si=0BX08V_WIMjsRU_k&t=378

In this video we are going to learn how to make your first Quest 3 XR game from scratch using Unity. This is the start of a tutorial series that will begin on this Youtube channel so feel free to subscribe to not miss the next one. :)

❤️ Support on Patreon : https://www.patreon.com/ValemVR
🔔 Subscribe for more Unity Tutorials : https://www.yout...

▶ Play video
#

he is unfortunately using ver 57

#

seemingly the meta integration has changed. I am looking for some guidance to replace the OVRcamerarig

#

and the OVRControllerPReFab

#

assets

#

Can anyone direct me on this ?

burnt vapor
#

You're better off asking in another channel, this channel is for coding questions. I doubt anybody would know the answer.

acoustic scaffold
#

@burnt vapor like under platform?

burnt vapor
#

Idk

waxen wyvern
#

hi again I need some help I have a script for a recoil in my fps game how to I make sure the script is running when I start the game?

#

should i attach it to the camera or player object?

frosty hound
#

That's up to you. Place it whenever it makes sense.

waxen wyvern
#

nothing happsn not even in the inspector

twilit heart
#

hi sorry if this is the wrong place to ask but i was wondering what the right way to create tests with the test runner when you are making use of coroutines and invoke? Also i have noticed that Start() doesnt seem to be called also

Perhaps i need to await something but im not sure exactly thanks

burnt vapor
# waxen wyvern nothing happsn not even in the inspector

If you want a script to start when you start the game, all you need to do is attach it to a game object. I'm not sure if it must be an active gameobject or it can be disabled, but as long as you have it attached on an enabled gameobject its Awake and Start methods will play.

#

If you have all that, perhaps make sure you correctly named the methods, and you do not have any compiler errors.

waxen wyvern
#

it works now thanks

keen dew
# twilit heart hi sorry if this is the wrong place to ask but i was wondering what the right wa...

You can use WaitForSeconds inside a test with the [UnityTest] attribute and wait until the coroutine has finished: https://docs.unity3d.com/Packages/com.unity.test-framework@1.1/manual/reference-attribute-unitytest.html#play-mode-example
but that goes a bit against the idea of unit testing, ideally the code would be structured so that you can test the individual functionality of the coroutines without invoking them

twilit heart
#

ah ok thanks mate

waxen wyvern
#

i have a character with joints and it is rigged when i shoot it I want the body to splash any idea how i do that=? ;:D

waxen wyvern
#

yeah or the body to become small cubes or particals

#

what every it could be anything I just want the object/character to change when i left click on it

verbal dome
#

Particle system?

waxen wyvern
verbal dome
#

You can create a particle system in the editor and then spawn or activate it from a script

waxen wyvern
twilit heart
#

is there something smaller than waitforseconds?

#

actually nm 🙂 thanks!

willow scroll
#

No, WaitForMilliseconds doesn't exist

#

I don't know why you'd need this, but maybe you were talking about WaitForEndOfFrame

twilit heart
#

Thanks

verbal dome
#

WaitForEndOfFrame is usually used for rendering related stuff, or when you want to wait for LateUpdate basically

verbal dome
#

Waiting for the next frame is done with yield return null for example

waxen wyvern
#

hi osmal! i have a VFX now but how do i called it with a script any idea?

#

i want to call the vfx when i hit the character with left mouse button

verbal dome
waxen wyvern
#

it is a partical system

#

so should i make a seperate script?

visual hedge
#

is there a way to add the instance of a gameObject to a List<GameObject> and actually keep it there while changing the scenes?
The list is on the GameManager gameObject which has that DontDestroyOnLoad thing

wintry quarry
#

Do note that the instance itself will still be destroyed unless it is also DDOL

visual hedge
verbal dome
amber spruce
#

how do i check if a gameobject is on or not

visual hedge
#

sadly, it didn't

amber spruce
wintry quarry
visual hedge
verbal dome
wintry quarry
#

"Missing" means it's a reference to an object which was destroyed

visual hedge
#

yeah... that's not quite what I would expect 😄 I hoped that the prefab itself will be kept in there as a prefab, you know... also I am sorry, I don't know what DDOL is?

verbal dome
wintry quarry
#

Prefabs only live in the project window

wintry quarry
visual hedge
wintry quarry
#

You have a reference to a destroyed object

#

If you actually referenced the prefab then sure

#

But this was an object in the scene

amber spruce
#

why doesnt this work

public class PauseMenu : MonoBehaviour
{
    public GameObject pauseMenu;
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Escape"))
        {
            if (pauseMenu.activeSelf == true)
            {
              Resume();
            }
            else
            {
              Pause();
            }
        }
    }

    public void Pause()
    {
        pauseMenu.SetActive(true);
        Time.timeScale = 0;
    }

    public void Resume()
    {
        pauseMenu.SetActive(false);
        Time.timeScale = 1;
    }

}
wintry quarry
#

Wait also you spelled it wrong

#

Just use KeyCode not a string

#

And you used ButtonDown instead of KeyDown

#

Many things wrong

amber spruce
#

yeah

#

because im not looking for a sepecific key im looking for the keybind

wintry quarry
amber spruce
#

like i press escape and nothing happens

visual hedge
#

what would be my approach if I would like to?
I am kinda trying to make that "pokemon capture" thingie and well, if I capture that pokemon in a turn-based battle... I kinda lose the whole information about it. Unless I want to make a whole big file with the whole lots of variable strings... and even then I am not sure I will be able to kinda do what is intended...

wintry quarry
amber spruce
#

the script is on my player object

wintry quarry
#

Or a pokemon ID or something

#

I think you're in way over your head if you're trying to make Pokemon without first understanding some basics about object and reference management in Unity

#

And how to deal with save data for your game

visual hedge
amber spruce
# amber spruce the script is on my player object

so i added some debugs and i get every debug like i got the debug Paused

public class PauseMenu : MonoBehaviour
{
    public GameObject pauseMenu;
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Escape"))
        {
            Debug.Log("Escape pressed");
            if (pauseMenu.activeSelf == true)
            {
              Resume();
                Debug.Log("Resume");
            }
            else
            {
              Pause();
                Debug.Log("Pause");
            }
        }
    }

    public void Pause()
    {
        pauseMenu.SetActive(true);
        Time.timeScale = 0;
        Debug.Log("Pauseed");
    }

    public void Resume()
    {
        pauseMenu.SetActive(false);
        Time.timeScale = 1;
        Debug.Log("Resumed");
    }

}
visual hedge
#

@amber spruce

verbal dome
#

There's no loop to break out from

gaunt ice
#

that is not loop
break doesnt work

#

and no jump target, and you will get compile error

visual hedge
#

hmm... oh okay... well... sorry for me being noob and trying to help )

wintry quarry
amber spruce
#

i got it to work i had to change some things but in the end it worked

#

1 question though when im paused if i move around like for example if i jump 10 times it makes me go super high in the air when i resume

visual hedge
amber spruce
#

ok will try that

#

works now thanks

buoyant knot
#

i generally disable the player movement behaviour when paused.

#

and reenable it when not paused

rich adder
#

array is just a " list "

#

nothing complex there

#

techincally its a collection

#

whats there to get?

polar acorn
#

It's a variable that holds many things instead of one thing

rich adder
#

it can be any type you want

oak imp
#

Imagine a grocery list. You have [Eggs, Milk, Cheese] On the list. You cannot add anything to this list because you only have a piece of paper 3 lines big (immutable) You can access lists like this GroceryList[0] will get you "Eggs" GroceryList[1] will get you Milk. Etc...

polar acorn
#

Just read the message above it

rich adder
#

it was basically what byte said

polar acorn
#

It was even a similar metaphor

oak imp
bright zodiac
#

adding that's not mentioned yet, it's a collection of ordered elements of the same type

ivory bobcat
#

Fruit Array:

  • Apple
  • Orange
  • Banana
polar acorn
#

An array is a list whose size can't be changed

oak imp
#

Lists are different from arrays. But don't get too carried away with this.

ivory bobcat
#

Maybe Google the docs?

c# array

oak imp
#

Hey yall, crazy question. I'm trying to print an exception caught by a try catch block using Debug.LogError. Anyone know how to convert the type exception to "object" (idk why its called this... but it is in the docs.)

oak imp
rich adder
bright zodiac
#

wat

oak imp
#

Error for type.

rich adder
languid spire
#

ex.Message

oak imp
rich adder
#

Ohh you want the message

oak imp
#

Wait nope

rich adder
oak imp
#

Cannot convert string to unity object :(

ivory bobcat
#

Show us what you wrote?

oak imp
#
Debug.LogError(String.Format("Scoreboard Overflow! Digit Has gone over Scoreboard Limit! Error: {0}"),e.Message);```
rich adder
#

for LogError you can just do ex.Message like SteveSmith mentioned

#

the second parameter is the object that called this debug

golden otter
# amber spruce so i added some debugs and i get every debug like i got the debug Paused ```csha...

Little note:
If you have any scripts attached to any GameObject of the pauseMenu gameobject and those scripts have some logic such as obtaining settings data or doing some logic on the Start or Awake method it won't be executed since you're disabling your gameobject, what I usually do is putting a CanvasGroup component on the canvas and changing the alpha and interactable properties when i want to, example:

public class PauseMenu : MonoBehaviour
{
    private CanvasGroup _canvasGroup;
    
    private void Awake()
    {
      _canvasGroup = GetComponent<CanvasGroup>(); 
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Escape"))
        {
            if (!_canvasGroup.interactable)
            {
              Resume();
            }
            else
            {
              Pause();
            }
        }
    }

    public void Pause()
    {
        _canvasGroup.alpha = 1;
        _canvasGroup.interactable = true;
        Time.timeScale = 0;
    }

    public void Resume()
    {
        _canvasGroup.alpha = 0;
        _canvasGroup.interactable = false;
        Time.timeScale = 1;
    }

}

The alpha variable changes the opacity of the canvas and the interactable variable changes whether the UI components inside the canvas are interactable or not

In your case it won't be really necessary to do this but when handling more and more things on the pause menu it will be worth it

oak imp
oak imp
#

lmao

#

Mbmbmb

#

Its the little things...

rich adder
oak imp
rare basin
#

why does it work like that, so that if my Unit <- base prefab doesn't work "MINE_VFX" entry in the Dictionary, but my Miner : Unit does, it still cannot get it from the dictionary, because it doesn't "see" it somehow?

#

Miner:

#

and when doing

  if (actionBasedPositions.TryGetValue(actionType, out var transform))
  {
      return transform.position;
  }

  return Vector3.zero;
#

it returns Vector3.zero because MINE_VFX is not present in the Dictionary in Unit

#

but it is on Miner

#

so why it doesn't work?

wintry quarry
#

also it's unclear which dictionary you're looking at

rare basin
#
public class UnitImportantPositions : MonoBehaviour
{
    public Unit owner;
    public GenericDictionary<ActionType, Transform> actionBasedPositions;

    public Vector3 GetActionBasedPosition(ActionType actionType)
    {
        Debug.Log($"Action type: {actionType}");
        if(owner is Miner)
        {
            Debug.Log("Owner is miner");
        }

        if (actionBasedPositions.TryGetValue(actionType, out var transform))
        {
            return transform.position;
        }

        return Vector3.zero;
    }
}
#

so this is the entier class

#

i am calling this function on Miner, who inherits from Unit

#

Unit doesnt have MINE_VFX, but Miner does

#

and it just doesn't pass the TryGetValue, because Unit doesnt have it (but im calling it on Miner) and im confused

#

i'll post some debug logs screrenshots

wintry quarry
#

or use a debugger

#

to double check that the dict actionally contains that

rare basin
#

is it becaues i have reference to the public Unit owner

#

and not the public Miner owner?

wintry quarry
#

no

#

that's irrelevant

rare basin
#

one sec

ivory bobcat
#

Could it be that the dictionary key mine vfx is coupled with vector 3 zero?

rare basin
wintry quarry
burnt vapor
#

Then log the key value pairs from the dictionary

#

Atm this is guesswork

rare basin
#

yes it doesnt SOMEHOW contain it

#

but it does in the inspector

#

and there is no way other unit is calling that method

wintry quarry
#

you're probably looking at the wrong object

rare basin
#

because there is only one unit at the scene

wintry quarry
#

or are referencing the wrong object

rare basin
#

i can print the owner name

#

one sec

#

hm.. it looks like it has prefab referenced instead of the actual object

#

because this is the actual object calling it

#

okay yea.. lmao

#

so i referenced the Unit inside the base Unit prefab

#

and then made a variant prefab from it called Miner

#

and i thought that it will somehow auto assign the Miner

#

instead it was referencing the old Unit (prefab?)

amber spruce
#

hey so im currently making a settings menu for my game and im trying to do resolutions and this is my code but when i play the game no resolutions show up

 private void Start()
 {
     resolutions = Screen.resolutions;
     resolutionDropdown.ClearOptions();
     List<string> options = new List<string>();
     int currentResolutionsIndex = 0;
     for (int i = 0; 1 < resolutions.Length; i++)
     {
         string option = resolutions[i].width + " x " + resolutions[i].height;
         options.Add(option);
         if (resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height)
         {
             currentResolutionsIndex = i;
         }
     }
     resolutionDropdown.AddOptions(options);
     resolutionDropdown.value = currentResolutionsIndex;
     resolutionDropdown.RefreshShownValue();
 }
eager elm
amber spruce
#

the length of it is 19

eager elm
#

print out the options of your dropdown after adding it

rich adder
#

why is this 1?

#

for (int i = 0; 1 < resolutions.Length; i++)

#

should be i

amber spruce
#

yep that was the problem lol

#

i was following brakeys tutorial and must have thought it was a 1

rich adder
amber spruce
#

oh didnt know that

#

thanks

rare basin
#

Owner name prints "Unit" when it has Digger(Clone) (Miner) assigned - yes this is the same object, there is only one Unity in the scene

eager elm
rare basin
#

that's what im doing

eager elm
#

I mean the gameObject of the script

rare basin
#

i don't need that info

#

that's not helpfull for debugging it

verbal dome
#

The fault could be in GenericDictionary 🤷‍♂️

#

Though I doubt it

#

But we haven't seen its code

rare basin
#

the issue isn't related with the Dictioanry im pretty sure

#

the problem is that i ahve referenced the miner

#

but it does print something else

#

as a name

#

this is the Miner

#

when i click on the Owner it doesnt show the prefab in assets, but the object in hierarchy

#

then when I do Debug.Log($"Owner name {owner.gameObject.name}", owner.gameObject);

#

it logs "Unit"

#

instead of "Digger (Clone)"

#

and when clicking on that message, nothing highlights

verbal dome
#

That it highlights

rare basin
#

in the prefab context?

#

that screenshot is from prefab context

verbal dome
#

You are talking about Digger (Clone) but in the inspector I see just Digger

verbal dome
rare basin
#

yes becaues the screenshot is from prefab context

#

i will show you from game one second

#

when i click the message, it points to Unit prefab in asest files (not even Miner prefab)

verbal dome
rare basin
#

there is only ONE unit in the entire scene (this miner)

#

not possible

#

anyway, this is frmo game

#

and it prints Unit and points to the Unit prefab

#

when clicking on that Owner

verbal dome
#

Maybe some serialization bug, try renaming owner to something else and reassigning it?

rare basin
#

it highlights the one in the hierarchy

#

changed to unitOwner

#

let's see

#

same thing

#

nothing has changed

#

Owner name still prints Unit and points to a prefab

#

what the hell is happening

#

is this a Unity bug? @verbal dome

#

it looks like a bug with variant prefabs to be honest

#

because Miner is a variant prefab of Unit

#

when I am in the Unit prefab context, and clicking on the owner variable, it shows the one in the inspector

#

but when I am in the Miner prefab context, and clicking on the owner variable (not overrided), it shows Unit prefab in the assets

verbal dome
rare basin
#

not sure what can I do about it

#

it stops me from development kinda

verbal dome
#

Not sure, try recreating the whole prefab variant

#

Or even the base prefab, at least to test it

#

If you can replicate it, report a bug

rare basin
#

so apparently you cannot add new elements to the variant prefabs such as references, new list elements etc

#

becaues that just wont work and it will reference the Unit prefab

#

great..

verbal dome
#

It should work

rare basin
#

i have made several test cases aswell

#

i know it should work

#

but it doesnt

#

2021.3.23f1 version

verbal dome
rare basin
#

I did

verbal dome
#

Alright

rare basin
#

fcking awesome eh

verbal dome
#

Are you using [SerializeReference] anywhere?

rare basin
#

no

#

actually the bug is more complex

#

the variant prefabs WORKS BUT they don't work when you have a variant prefab with different class assigned

#

so the Unit base prefab has Unit class

#

i created prefab variant out of it

#

removed the Unit class and added Miner : Unit class instead

#

and then it doesnt work

verbal dome
#

So it kinda still thinks that it has the Unit script on it

rare basin
#

yes

#

im not even sure how can i describe this in a bug report lol

verbal dome
#

Well you just described it to me 😄

rare basin
#

that is such a shame i can't even think of a workaround for this :/

verbal dome
#

Steps:
-Make prefab A with script X
-Make prefab variant B out of A
-Remove script X from B and add script Y which inherits from X

#

Right?

rare basin
#

yes

#

ig

verbal dome
#

See if you can replicate it on a separate prefab

rare basin
#

i need to somehow acces the Miner component

rare basin
verbal dome
#

Then you found a bug, report it!

rare basin
#

my first one 🥳

verbal dome
#

Might be fixed in newer versions

#

Prefab variants are relatively new

rare basin
#

but anyway, do you think of a way of accesing the Miner component? :/

verbal dome
#

From where?

#

UnitImportantPositions?

rare basin
#

yes

#

because it takes it from the Removed Unit component

verbal dome
#

You could try using GetComponent to work around this bug, I guess

rare basin
#

instead of the new added Miner

verbal dome
#

Use a GameObject reference + GetComponent

#

See if the bug still persists with that

rare basin
#

no because it points to a prefab

#

not to the instantiaated miner

#

when I do this

#

Debug.Log($"Owner name {unitOwner.gameObject.name}", unitOwner.gameObject);

#

from instantiated Miner

#

it points to Unit prefab

#

not the Miner instance

#

and the Unit prefab doesn't have the Miner cmoponent obviously

verbal dome
#

Yeah that's the bug, try a gameobject reference instead

rare basin
#

oww yea

#

okay i got it

#

let me see and pray lmao

verbal dome
#

Lemme know how it goes

stuck palm
#

if i wanna refefence the current script, do i use "this"?

rare basin
#

same result :/

#

public GameObject unitOwner;

#

and then GetComponent<Unit>

#

is that what you meant?

#

let me try another way, creating a second variable

verbal dome
#

Yeah

rare basin
#

and referening it only in the Miner

#

and leaving it empty in the Unit

#

nah it's the same

#

i think that just by referecing the variant prefab

#

it points to the base prefab

prime lodge
#

Iam trying to get a variable across scenes to show on text but it doesnt work

rare basin
#

thank you anyway Osmal

verbal dome
rare basin
#

oww im curious what if i do another variable public Miner miner

#

i'll experiment 😄

wintry quarry
prime lodge
prime lodge
wintry quarry
#

Also log what value is being set (killsText)

prime lodge
rich adder
#

where do you Set

prime lodge
#

in different scene

prime lodge
#

is making the variable static better for variable transport?

rich adder
#

hmm i barely use PP you might need to do PlayerPrefs.Save()

wintry quarry
#

nothing to do with this code

prime lodge
wintry quarry
#

because it's bad practice for beginners such as yourself who don't fully understand what the consequences are

rich adder
#

i could be wrong

rare basin
#

unity saves preferences automatically on app quit

rich adder
#

I hate playerprefs

rare basin
#

yes

rich adder
#

I never use it

rare basin
#

binary saving > player prefs

rich adder
#

any file saving is fine

#

json is acceptable too

rare basin
prime lodge
rare basin
#

you basially get the array od bytes

#

encrypt it, save it into a file

#

then read the file, decrypt the content

rich adder
rare basin
#

that's true

rich adder
#

less friendly for any prying eyes I suppose

rare basin
#

pure not encrypted json can be just easily modified

#

in notepad or sth

rich adder
#

yea, if the game is singleplayer it wont matter regardless

rare basin
#

yup

polar acorn
#

Stardew saves things in plaintext and it hasn't been a problem

rare basin
#

need to take a look on my save file in stardew valley then

polar acorn
#

If people wanna push the game by messing with their saves, let em

rare basin
#

cheat engine for instance

rich adder
#

Yeah started saving things like Gravity in json just incase my players want to mess around

polar acorn
# rare basin rly?

Yes, I've had to manually edit it before to un-stick myself when I accidentally installs a mod that changes the terrain slightly and my save is now stuck inside a mountain

rare basin
#

but it is better to have a binary formatted saving when you will ever want to develop on consoles

rich adder
#

binary just offers speed

frozen stream
#

if you have an object in do not destroy on load, does awake/start still get called if you change scenes?

swift crag
#

The object is not re-created when you load a new scene.

#

If you want to do something when a scene loads, consider..

wintry quarry
tender stag
#

difference between Physics.OverlapSphere and Physics.CheckSphere?

slender nymph
#

OverlapSphere returns all of the colliders it finds. CheckSphere just returns a bool if it finds any colliders

#

so if you need the info about the colliders that are in the sphere, use OverlapSphere. if you don't need any info about what colliders are there and just care about whethere there are colliders there then just use CheckSphere

tender stag
#

so for ground check it would be more ideal to use CheckSphere

abstract finch
slender nymph
tender stag
#

for my case

abstract finch
ruby python
#

Be careful though, cause if you're doing anything with the player in terms of locking it to the ground, using a checksphere could cause your game to wig out some if it hits a wall or prop etc.

slender nymph
#

that sounds more like an issue of not using a layermask rather than an issue of just using checksphere

ruby python
#

Yeah true, was just thinking of covering the bases. lol.

polar acorn
ruby python
#

Yeah I think pretty much everyone uses a raycast for a ground check tbh. At least in my limited experience (obviously assuming that's what you're doing)

tender stag
#

for my type of movement

verbal dome
stuck palm
#

why is it saying null checking is expensive

patent compass
#

Hello, does C# not have properties like unity? I am trying learn about them but getttin an error.

polar acorn
verbal dome
polar acorn
#

But at no point have you ever been able to put them inside a function

polar acorn
# stuck palm why is it saying null checking is expensive

It's a bit expensive. If you can avoid it by re-engineering your project it's usually a good idea to do so. Basically, is this null check there because itemData being null is a legitimate situation you are intentionally designing into the system or is it a band-aid for hiding an error that shouldn't be there in the first place?