#💻┃code-beginner

1 messages · Page 523 of 1

silver basin
#

oh, that

#

yeah

languid spire
#

so the base type is?

silver basin
#

How do I use foreach for gameobjects though?

languid spire
#

instead of group Group
you use the base type Group

silver basin
polar acorn
#
scarlet totem
#

anyone knowledgeable in animation states?

languid spire
eternal falconBOT
sterile radish
#

hi, im making a top down game similar to that of undertale. how would i go on about making a room system/loading rooms?

dapper arch
#

guys how do i make an ammo system the unity example fps game has inf ammo and inf reloads but i want to have limited ammo and something you touch to pickup ammo

#

i already managed to swap the weapon and add casing but negative ammo and permanently running out of ammo is not ideal

cosmic quail
dapper arch
#

oh

cosmic quail
# dapper arch oh

if you come across problems while following a tutorial, feel free to ask about the problem though

dapper arch
#

@cosmic quail should i update?

#

i want to make a 2d mobile game

#

and rn i have unity 2022.3.20f1

cinder schooner
cosmic quail
cinder schooner
#

so its the latest most refined version

cosmic quail
# cinder schooner it's lts,

i know but if an lts is very new then it may have overlooked issues. it had at least one iirc but it has been fixed by now

cinder schooner
devout flume
#

The differences you'll have will mostly be about pricing

cosmic quail
cosmic quail
dapper arch
#

its installing anyways

#

why is it so slow i only have youtube playing

#

but installing stuff on steam does 50-70mb/s

devout flume
#

It's either their server failing to provide higher data transfer bandwidth, your bandwidth being slower than usual, or other factors that make it so that the download is slower

dapper arch
#

@cosmic quail

#

the tutorial said to create a new C# script but it dosen't let me add it

#

i had to use monobehavior

#

strange

finite dove
# dapper arch <@798203494279938049>

when you want to add a new component from script to the gameobject that script has to be child/derived from MonoBehaviour (it's unity code engine). so make sure your script have that near class name.

dapper arch
#

this is what its complaining about

eager spindle
eager spindle
cosmic quail
# dapper arch it was the lower cased input

yeah that should have had a red line under it to show you its wrong, you need to configure your ide or you will have a lot of problems like this. here's how to do it: !ide

#

!ide

eternal falconBOT
sonic pond
#

im new to scripting so i dont know much about c# but how do i make it so when a gameobject lets name it for example go1 when go1 is deactivated this code runs
this.schoolMusic.Stop();

steep rose
#

is the script on "go1" when it is disabled

languid spire
#

sounds like you have a script on go so add an OnDisable method for that code

sonic pond
#

its on a gamecontroller gameobject thats always enabled

#

but i did refrences

steep rose
sonic pond
#

thanks

valid pasture
#
using System.IO;
using UnityEngine;
using Dummiesman;
using UnityEngine.InputSystem;

public class PressAToInsert : MonoBehaviour
{
    private GameObject loadedObjectPrefab;
    public string modelPath = @"C:/Users/nathan/Downloads/mesh.obj";
    public Vector3 massiveScale = new Vector3(100f, 100f, 100f);
    private Vector3 spawnPosition = new Vector3(64.21851f, 231.9479f, 58.24418f);

    void Update()
    {
        // Check if A button is pressed on Oculus controller or A key on keyboard
        if (OVRInput.GetDown(OVRInput.Button.One) || Keyboard.current.aKey.wasPressedThisFrame)
        {
            SpawnObject();
        }
    }

    private void SpawnObject()
    {
        if (File.Exists(modelPath))
        {
            FileStream fileStream = new FileStream(modelPath, FileMode.Open);
            loadedObjectPrefab = new OBJLoader().Load(fileStream);
            fileStream.Close();

            GameObject instance = Instantiate(loadedObjectPrefab, spawnPosition, Quaternion.identity);
            instance.transform.localScale = massiveScale;
        }
        else
        {
            Debug.LogError($"Model file not found at: {modelPath}");
        }
    }
}
#

i have this script for oculus and i need help cuz my scripts just crashing

wintry quarry
valid pasture
#

it will say that it is not responding

wintry quarry
valid pasture
#

no

wintry quarry
#

or just right when you run it

valid pasture
#

when i run it

polar acorn
#

The thing you're spawning wouldn't happen to also have this script on it, would it?

wintry quarry
#

seems unlikely to be related to this script then unless the button is always pressed on your OVR: OVRInput.GetDown(OVRInput.Button.One)

wintry quarry
#

But basically you are kind of breaking one of the cardinal rules of interactive programming - you're doing I/O on the main thread

valid pasture
#

how might i be able to fix that

wintry quarry
#

There's also the problem that you're not properly handling your file handle

#

You should use a using statement to make sure it gets closed properly

#

and hwo big is this file

#

it may just be taking a very long time to read/load it

valid pasture
#

its 8878 kb

wintry quarry
#
            using (FileStream fileStream = new FileStream(modelPath, FileMode.Open)) {
              loadedObjectPrefab = new OBJLoader().Load(fileStream);
            }``` this is the preferred way to handle filestreams
wintry quarry
#

certainly bigger than you should try to read on the main thread

#

It depends how this OBJLoader() library works

valid pasture
#

im using

cedar kernel
#

but it doesnt even have a rigidbody component??

#

i mean the object selected

#

idk why this error keeps on popping up

polar acorn
cedar kernel
#

wdym the parent?

polar acorn
#

I mean the parent

cedar kernel
#

im sorry idk what a parent is

steep rose
#

the parent is the utmost object in the child's hierarchy

#

or the parent is an object that contains other objects under it (known as children) in the hierarchy

toxic frigate
#

hey everyone, when i delete an object at start, how do i make it sort the array it was in?

polar acorn
#

And then remove the object from the list when it's destroyed

weary plover
#

I was wondering if someone could help me out with an issue I'm having related to Tilemaps. I'm making a 2D game, using a tilemap to create a large map. I have a grid, and two tilemaps under it. One is a background tilemap where I place all my background tiles, and that works fine. The background tiles are solid colored tiles and they come from a sprite sheet that I sliced up. It's a PNG. The other tilemap is for my outline tiles. I'm using a transparent sprite with a square dotted line and place one of these for each tile that exists on the grid. The issue I have is that when I programatically place the outline tiles, they get stretched and look pretty bad, filling the tile up. The interesting thing is if I fill the transparent background with a solid color, the issue goes away and the dotted outline is not stretched. This is not ideal, as I'd like a transparent outline. I'll show an image of both the transparent and solid background examples as shown during runtime of the game:

#

Am I in the right channel for this question?

toxic frigate
#

how are you placing them programatically

#

is the spacing correct

weary plover
#

Here's the code:

foreach (TileMapData tileData in tileMapDatas)
{
// Generate Vector3Int from x, y
Vector3Int pos = new Vector3Int(tileData.x, tileData.y, 0);

// Key is the position of the tile, Value is the tile data
bgTilemap.SetTile(pos, (Tile)GetTileByGuid(tileData.guid));

// Set outline tile
outlineTilemap.SetTile(pos, outlineTile);

}

#

I'm using SetTile the same way I'm setting the tile for the background tiles (which are currently working)

glad shuttle
#

hey, I am making a little platformer using Unity2D. I have a smoke animation that plays under my characters feet when I jump (pressing the spacebar). And it Sorta works, The smoke animation plays once when I press the space bar. How do I make it so the animation only play when I hit the spacebar over and over when the character jumps?

Here is a video of What is happening.
Here is my Script for the Smoke appearing and disappearing
and here is my layout

rich adder
jaunty wing
#

Coroutining is like creating a new thread in the script

#

So you are making a new thread on your CPU every time

timber tide
#

you'd think but no

glad shuttle
#

@rich adder alright so i rearranged my code a little bit, and now it works better. When I jump, the Sprite Renderer appears for a scond then disappears. I jump Again and the Sprite Renderer is enabled but then stays enabled.

timber tide
#

oh huh can you not embed mp4

glad shuttle
#

its a spritesheet

weary plover
#

FYI, for my issue above this one and for anyone that was curious, I fixed the problem. I believe it had to do with using the right material for tilemap. I switched everything over to use the Sprites-Default Material.

rich adder
#

if you want to make it turn off after you jump, then put the StartCoroutine inside the jump.

#

You probably want to store it in a Coroutine variable so you can figure out what to do if you press space again while its already running a wait, for example you can stop previous and reset it

upper forge
#

any tips on flying enemy dashing at player?

timber tide
#

What are you using for pathfinding for the enemies so far?

toxic yacht
upper forge
upper forge
toxic yacht
#

If your trying to figure out how to differentiate patrolling logic from dashing logic, the simplest thing would be make a small state machine:

public class FlyingEnemy : MonoBehaviour
{
  public enum EnemyState
  {
    Patrolling,
    Dishing
  }

  EnemyState curState = EnemyState.Patrolling;

  void Update()
  {
    switch (curState)
    {
      EnemyState.Patrolling:
        PatrollingUpdate();
        break;
      EnemyState.Dashing:
        DashingUpdate();
        break;
    }
  }

  void PatrollingUpdate() { ... }

  void DashingUpdate() { ... }
}
upper forge
#

Awesome thats for the info! i believe this will help me!

radiant glen
#

Trying to call my bossScore int from one script and use it in the other, to make the maxhealth scale with with bossScore, but when I try something I keep getting error codes like cannot make void into int, how should I go about this?

naive pawn
#

what exactly is the error and where are you getting it?

radiant glen
#

Well, I am recieveing a few, just trying to call the variable from one script to the other, with this code I am recieving none, but I still want to call the boss score int variable

wintry quarry
#

but currently it seems like you're probably coding without a configured IDE

#

So you should probably start by configuring it.

naive pawn
#

we can't help you solve a problem when you don't show us the problem

radiant glen
wintry quarry
#

!ide

eternal falconBOT
radiant glen
naive pawn
#

you just access it like you would any other member

wintry quarry
radiant glen
#

When I try to set bossScore = BossHealth I get this error

wintry quarry
naive pawn
#

of course, because your BossScore is the entire class, not the score itself

wintry quarry
#

BossScore.instance.currentBossScore

#

Is this what you mean^ ? @radiant glen

#

I'm very confused about what you're even trying to do with that line of code

radiant glen
#

Maybe... I want to set the boss score which is in one script, to the bosshealth which is in a diffrent script

wintry quarry
#

What is BossHealth, anyway?

wintry quarry
radiant glen
#

The BossHealth is the maxHealth the boss can have

naive pawn
wintry quarry
naive pawn
#

it's in the field, int currentBossScore, not the type, class BossScore
the word before the name tells you what it is

radiant glen
wintry quarry
#

no

naive pawn
#

no, not the physical code

#

er, i guess no physical, but not the text of the code

#

the structure where it's stored

#

it's inside BossScore, it's not BossScore itself

wintry quarry
#

I still think you're not even understanding how = works and probably have the order backwards.

naive pawn
#

it's like you're trying to change a line in a document, by replacing the entire document
the document has more than just that line, so that doesn't make sense

wintry quarry
#

in addition to not understanding references and variables.

radiant glen
# wintry quarry whya re you trying to change it then? This code doesn't make sense.

I am lost sorry, I have a BossScore int in my BossScore script which is increased or decreased based on actions inside of the game, in a diffrent script, I want to call the BossScore int so I can use that number to set it equal to the health of the boss therefor the Boss's health is diffrent depending on what you are doing in the game, I hope this explains it

naive pawn
#

you don't have a BossScore int

#

you have a __current__BossScore int, inside the BossScore class

wintry quarry
#

if you want to change boss health you need to do:

BossHealth = something

#

Again = sign changes the thing on the LEFT side of the =

#

not the thing on the right

radiant glen
wintry quarry
#

So do it

radiant glen
#

I think I see now thank you guys!

wintry quarry
#

BossHealth = BossScore.instance.currentBossScore;

radiant glen
#

That worked, I truly appreciate the help from you guys!

wintry quarry
#

we're not even supposed to help you unless it is

radiant glen
#

I think I am going to go back through and check though

wintry quarry
radiant glen
#

Okay!

glad shuttle
sharp abyss
eager spindle
#

I'm not sure how you set up your chain here

finite mango
#

how can i reference a tilemap in my script without using public Tilemap tilemap and dragging it in from the hierarchy?

sharp abyss
#

I used hingejoints

eager spindle
#

but dont do it at runtime in update

finite mango
#

was just planning to do it on void awake or start

#

does it matter which i use? kinda beenn using them interchangibly

eager spindle
#

Awake happens immediately, before start. Let's say you instantiate something. Awake is called immediately when the object is instantiated, while Start is called at the beginning of the next frame.

finite mango
#

oh okay so just a one frame difference

#

thanks

hushed rain
#

can anyone help me with this problem

#

this is the code and my error is

#

i know that the (20,48) is talking about the line (20) and character (48) and it says i should have a ; at character 48

#

the ; is on the 47th character but even if i put it on the 48th it still gives me an error

#

and if i remove it entirely it gives me a whole new error

north kiln
eternal falconBOT
hushed rain
#

!ide

eternal falconBOT
hushed rain
north kiln
#

Have you read the message at all?

hushed rain
hushed rain
hushed rain
#

i fixed the issue i just did the ide and used the quick solves

languid spire
north kiln
#

I'm glad they asked, as now they have a functioning IDE and can learn that easily

languid spire
#

indeed, which is why I did not reply until they had fixed that

hushed rain
keen dew
#

His code wasn't the same as what you wrote

dapper arch
#

do you lads know what is the problem

#

this exists

cosmic dagger
dapper arch
cosmic dagger
#

at the top of the script. you should have a red squiggly error underneath TextMeshProUGUI. if not, make sure your !ide is configured . . .

eternal falconBOT
cosmic dagger
#

the IDE will pop-up a light icon that suggests how to fix it . . .

dapper arch
#

and the suggestion is not helping

queen adder
languid spire
dapper arch
north kiln
#

There's more than 1 step to configuring VS Code

dapper arch
#

also unity by default opens my Visual studio app

keen dew
#

The extension shows an error. Click the red block at the bottom

dapper arch
#

so why is the script not working

tawdry quest
#

@dire grove post your code here using the appropiate thing from !code and provide the animator again

eternal falconBOT
tawdry quest
#

Thx

dire grove
#

wait sorry

tawdry quest
dapper arch
#

i don't think this is important for my project error

dire grove
#

!code

eternal falconBOT
dapper arch
north kiln
tawdry quest
#

Why is your game in onedrive, move it out of there

#

Use git if you want a backup

#

Onedrive is prone to breaking unity projects

dapper arch
tawdry quest
#

Your user is called OneDrive lol

dapper arch
#

no its just passed through it

tawdry quest
#

Wait what

dapper arch
#

i am Asus

tawdry quest
#

Never seen that

#

As long as you removed onedrive it should be fine

dapper arch
dire grove
dapper arch
#

its complaining about TextMeshProUGUI but its written right

north kiln
tawdry quest
#

@dire grove erm you do animator. but never create a reference to said animator

#

Thats the problem

dire grove
tawdry quest
#

Bad tutorial ig

dapper arch
#

also

north kiln
#

!ide

eternal falconBOT
dire grove
#

i did exactly as instructed

tawdry quest
#

Or you skipped a step in the tutorial by accident

cosmic dagger
# dapper arch so why is the script not working

i linked you the instructions for configuring your IDE. just because you installed a Unity extension from VSCode does not mean your IDE is configured with unity. follow the link as you were told multiple times . . .

dire grove
#

his player was working just fine 😭

tawdry quest
#

You need to have a reference to the animator

dire grove
dire grove
#

i did exact thing as the dude

north kiln
tawdry quest
dapper arch
languid spire
tawdry quest
#

@dire grove did the tutorial guy put that Animator animator; down there too and not at the start ?

#

Or was that you

dapper arch
#

@north kiln do you know why its complaining about TextMeshProUGUI

north kiln
dire grove
#

should i share video link?

north kiln
tawdry quest
#

Yeah the guy sounds incompetent if he puts declarations of variables mid code

languid spire
dapper arch
north kiln
#

No.

tawdry quest
languid spire
dapper arch
tawdry quest
#

What what

dire grove
north kiln
#

There's nothing wrong with it, they just need to install the .NET SDK and relog so it's on their PATH

tawdry quest
#

The red error you showed me clearly stated that youre missing Text Mesh Pro, so go install it

languid spire
north kiln
dapper arch
#

but i still don't know what the problem is

tawdry quest
cosmic dagger
languid spire
tawdry quest
#

Maybe watch a goddamn C# Tutorial first

#

@dapper arch

cosmic dagger
tawdry quest
#

Without that you wont come far anyways

dapper arch
north kiln
#

Yes

dire grove
dapper arch
dire grove
languid spire
# dire grove

ok, so there is your problem, in your properties you need to set both bools not just one
tbh you would be better using something other than bools for this

dire grove
#

is moving = true? for both

tawdry quest
cosmic dagger
# dapper arch so all i was missing was this?

as i mentioned from the first post; you need to add the text mesh pro namespace in order to use any of its types. just like you need the using UnityEngine; namespace to use any of its types . . .

languid spire
# dire grove how so

it will make your transition conditions easier to understand. or you can use an Any State state to simplify the transitions

dire grove
#

oof ok

#

thanks man

north kiln
#

Please keep the inappropriate statements off the server thanks

jaunty bay
#
    {
        base.OnCollided(collidedObject);
        if (isInteracting)
        {
            OnInteract();
            isInteracting = false;
        }

    }
    protected void OnEnable()
    {
        interact.action.performed += PerformInteract;
    }

    protected void OnDisable()
    {
        interact.action.performed -= PerformInteract;
    }

    protected void PerformInteract(InputAction.CallbackContext obj)
    {
        isInteracting = true;
    }

    protected virtual void OnInteract()
    {
        Debug.Log("OnInteract() is executed.");
    }
}```

jello friend.
these lines of code made my button Interact pressed twice (or maybe more) when i press it only once. why?
red igloo
#

I need some advice, I am a complete noobie at coding C# and I want to gain more knowledge of c#. What should I do I'm kinda lost. I have escaped from tutorial hell as it wasn't helping me at all and I wanted to use my own brain to figure things out. How can I figure things out when I don't know how to do stuff? What would you do in my situation?

red igloo
jaunty bay
#

i think itll help u at least for the basics

vague adder
#

whenever i add curly braces, it keeps giving an ''problem'' even though everything works fine in the tutorial

vague adder
#

oh

timber tide
#

Your IDE is giving you some help there with the squiggles

jaunty bay
#

aye

#

best might be to look for those reds when looking for errors

vague adder
#

i didnt see the squiggles lol

naive pawn
#

to clarify; statements like if, else, while, for, etc take a single statement as a body, which is why if (c) DoThing(); or while (c) DoThing(); work.
there's 2 "special" statements that don't really say anything, the empty statement ; and the block statement {}
the empty statement just does nothing. it's sometimes used to indicate, "i didn't forget, i just don't care" or to really just do nothing
the block statement can hold other substatements, which execute in order
if (cond) { stmt* } isn't the structure, it's if (cond) stmt where {} is a single statement that holds other statements
(c-family languages inherit this behavior)

strong wren
#

@inland dirge First lesson is to follow community conduct. Don't cross-post.

polar wasp
#

do you guys tend to look more to microsoft's documentation of c# or unity's more when developing client side things?

strong wren
strong wren
modern talon
#

Hi, I am new here and exploring this field. I wanted to know that currently I am using C++ in my college for coding problems. To switch into game development, do I completely switch to C#, I don't know if I should do them both or just one.

naive pawn
#

different languages have different usecases

#

the more you know, the more you'll be able to do

#

don't just drop one because you're starting another. you can put it on hold, but you won't forget those skills anytime soon

#

experience in any programming language translates to a better time in any other, since you'll already know how to program, you'll just need to learn the features, syntax, and interfaces

polar wasp
#

is there any specific situations that you would want to go to microsoft instead?

naive pawn
#

c# docs for csharp language (ie, enums, properties, delegates) and interfaces (primarly System, System.Collections, System.Collections.Generic, in this case)
unity docs for unity features and interfaces

#

by "interface" here i mean API, not the type interface

strong wren
modern talon
#

Is there a YouTube channel for Unity C#?

#

From basics

steep rose
#

Imphenzia and !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

steep rose
#

do not get solely dependant on youtube though

#

try to retain all of the information you receive by practicing

polar wasp
steep rose
#

yes books are good

polar wasp
#

bc they normally focus on teaching you the concept and challenging you to find out where to find the info you need to solve a problem you have

#

i'm an airplane mechanic in the military, so there is a lot of overlap between that and programming

all you need to know is the concept of what you're doing and where to find the information that takes you through it

steep rose
#

but this only applies if you can get one or already have one

modern talon
#

Any good books?

polar wasp
polar wasp
#

but i can't talk about it too much since it isn't on topic here, just where the overlap meets like i said

steep rose
#

student pilot here 😁 but yeah its off topic

timber tide
#

stackoverflow best book

naive pawn
#

just don't stop reading at the questions

#

a surprising number of people do

#

"i got this from stack overflow [link]" and it's from the question...

steep rose
#

also books are a real world copy of information that you can use anytime without you needing the internet, I have a C# book and it explains everything you need to know as a beginner, But you need to retain that information or it will be useless

#

I do not know if unity has their own book, most likely not

rich adder
steep rose
sterile radish
#

in my game the player can talk to an npc by pressing "E" in their vicinity. if the player is moving at the same time they press "E", they start talking to the NPC whilst moving in one direction forever regardless of input until the dialogue is finished and the dialogue box closes. how can i fix this?

https://hatebin.com/wsanehbnld

timber tide
#

You return early when dialogue is opened in your update loop so your velocity is now stuck to the last read value

keen dew
#

Set the velocity to zero when dialogue starts

sterile radish
timber tide
#

one post up for the fix ;)

#

If you were just using forces, that would actually resolve itself

sterile radish
keen dew
#

If it didn't work you did it wrong but using forces is probably better overall

sterile radish
keen dew
#

When the dialogue starts

#
if (Input.GetKeyDown(KeyCode.E) && dialogueUI.IsOpen == false)
{
    // here
    interactable?.Interact(this);
}
sterile radish
#

the problem still persists sadly

keen dew
#

You also have to prevent it from setting the velocity when dialogue is happening

sterile radish
#

sorry i don't understand could you explain further?

keen dew
#

Do you know where the code sets the player's velocity?

sterile radish
#

nowhere else besides PlayerMovement

verbal dome
keen dew
atomic holly
#

Hello
I want to use in a script the function collider2D.excludeLayers but I don't see how I say if I want to exclude or not a layer ? Can someone explain me, there is no example in the documentation

naive pawn
#

that's a public field, you can set it in the editor

#

if you want to modify it in code, you could modify its value or create a new LayerMask to replace it

atomic holly
naive pawn
#

like any other value

#

it's a bitmask though, so be aware of that

#

i'd recommend you just use the inspector if you can though

normal tapir
#

if you use visual scripting in unity can you use classes and stuff in other visual scriptings and can you use it in c#

finite patrol
#

How can I prevent wall sticking w/o using a 0 friction material?

normal tapir
fickle plume
naive pawn
wintry quarry
#

If you think about it objects in real life cannot push themselves into a wall in midair and that's the root of the problem

sterile radish
#

is it allowed to turn on pings when you're replying late to someone who helping you earlier?

naive pawn
#

it's not disallowed, but just be considerate

#

consider using a silent ping

sterile radish
#

okay

sterile radish
naive pawn
#

(that was not a silent ping, but hey, more power to ya.)

#

(why not moveDir * moveSpeed btw)

fickle plume
#

You need to zero out moveDir if it still has value during dialogue, or put it behind condition.

sterile radish
naive pawn
#

that disables the ping entirely
you can prefix a message with @silent and have an actual mention (including a reply) and it'll have the mention bubble thing without triggering a notification, like this one @sterile radish

keen dew
sterile radish
naive pawn
#

you can check to see if it's appropriate to add velocity before doing so

keen dew
#

So when I said that you can fix the issue you're having by preventing the code from setting the velocity when the dialogue is happening, you now know how to do it

sterile radish
wispy token
#

Guys, im a bit confused with what I did wrong. I tried to check with chat gpt but it still isnt working. I don't think i connected my restart and quit button correctly to my script. Because in my "GameManager" script i tried referencing them and then tried connecting them with the on click on the inspector tab. But the script still isn't working how I intended it to

languid spire
#

maybe share the !code for the Restart method ?

eternal falconBOT
wispy token
#

'''cs
// void Start()
{
UpdateScore(0);
UpdateTime(timeRemaining);

   gameOverText.gameObject.SetActive(false); 
   restartButton.gameObject.SetActive(false);
   quitButton.gameObject.SetActive(false);

'''
//to hide during the gameplay

'''cs
// public void GameOver()
{
Debug.Log("GameOver called");

    gameOverText.gameObject.SetActive(true);
    restartButton.gameObject.SetActive(true);
    quitButton.gameObject.SetActive(true);
    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
}

'''
//to reappear when the game is over. My game over text appears but not my buttons

normal tapir
#

if you use visual scripting in unity can you use classes and stuff in other visual scriptings and can you use it in c#

so like if you make a class or variable in visual can you use it in C# or other visual scripting scripts

normal tapir
#

oh ok thanks i see that a lot of people dont get answered there so i hope someone answers XD

languid spire
#

well your other option is to try it yourself and see

normal tapir
#

yea true XD

upper forge
#

So i have a bat and i set it as kinematic so if can stay in the sky flying, but when i add my knock back to it when player hits it it just goes flying in the sky... but it i change this to dynamic and have gravity on 1 it wont do that and knockback works... how would i fix this for my bats knock back to work and stay flying in the sky?

naive pawn
upper forge
naive pawn
#

or have it ease back to a specified height

wintry quarry
#

So you'd add forces up when flying to counteract gravity

sour nimbus
#

How do I make objects not collide with the camera?

rocky canyon
#

why would they? unlessur camera has a collider on it?

sour nimbus
granite mason
#

howdy, this code seemed to work last time i opened the project, but now the bool for being looked at isnt staying true when being looked at, and only flickers on intermittently. I dont think ive changed anything but apparently i did, do yall have any tips?

rocky canyon
wintry quarry
#

Why use send message btw

#

(just saw the third image)

#

Your logic around line 33 is wrong

granite mason
granite mason
wintry quarry
wintry quarry
#

Don't use code you don't understand

rocky canyon
#

share your code using a patebin website or something so i aint gotta squint

granite mason
rocky canyon
#

thanks

granite mason
granite mason
#

i figured the raycast stops when it hits one colider, and so couldnt hit multiple at the same time, is that not the case?

wintry quarry
wintry quarry
upper forge
rocky canyon
#

i think Praetor is on to something.. i think you dont have enough logic to do what u want to do..
you probably need logic to check if the target was the same as last time..
if it is hitting a different new valid target we should tell the old target that its looked away from.. and the new one that we're now lookin at.. or if ur raycast hits something that isn't valid we could check if there was a valid target last time.. as lookaway from it.. etc

granite mason
#

ok. so could i make a seperate gameobject variable like OldTarget to test against, and a bool to say whether the target is valid or not, and fix the logic?

rocky canyon
#
        Ray ray = new Ray(cam.transform.position, cam.transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, maxDistance, targetLayer))
        {
            // new target was found
            GameObject newTarget = hit.collider.gameObject;

            // if the new target is different from the current target,
            if (newTarget != currentTarget)
            {
                if (currentTarget != null)
                {
                    // notify the old target (if any) to look away
                    currentTarget.GetComponent<TargetBehavior>()?.OnLookAway();
                }

                // notify new target its being looked at
                currentTarget = newTarget;
                currentTarget.GetComponent<TargetBehavior>()?.OnLookedAt();
            }
        }
        else // no target is being looked at
        {
            if (currentTarget != null)
            {
                currentTarget.GetComponent<TargetBehavior>()?.OnLookAway(); // notify old target to look away
                currentTarget = null;
            }
        }
    }``` heres all those conditions
#

should be able to do it with just 1 variable

#

if we're lookin at a new target (check the old target first.. if its different than look away from the old one look at the new one)
if theres no current target then we can just look at the new one

#

if its the same target we can look at it again.. or do nothing.. thats up to you and ur game

#

i do the same w/ an interact raycast.. (we just cache the result).. then use that to do any comparisons on the next frame or the next time we look at something

granite mason
#

ok

rocky canyon
granite mason
#

thats how chat gpt said to do it

rocky canyon
#

ahh, ok.. makes sense

vale karma
#

So blendshapes and BakeMesh() work, but extremely expensive, before I go another route to use or not use skinnedmeshrenderer, is there a cheaper method to find the highest vertex of a skinnmesh?

granite mason
#

all i really want is a bool saying whether an object is being looked at or not, so i didnt look as far into it as it seems i should have now

vale karma
#

if you want something to tell you what its looking at, use a Raycast

granite mason
#

is that not what im doing here?

rocky canyon
#

i was just curious.. i just used regular functions.. and after i grab the component i just call the method

vale karma
#

forgive me i did not scroll up far enough

rocky canyon
#

heres how you could check a bool.. just put that logic in ur methods for lookin and looking away

#

then each TargetBehaviour would change depending on ur raycast logic

steep rose
#

is that rider? or is that the intellicode from VS doing that

rocky canyon
#

codieum/ vscode

granite mason
rocky canyon
rocky canyon
# rocky canyon

the targetbehaviours are on all the objects we can look at

#

the raycast script i used could be on any gameobject. b/c it uses the MainCamera tag to find and use the camera as the rays starting point

vale karma
#

So im able to get exactly what i need, but using BakeMesh() is expensive. Is there any cheaper method? Heres a short vid on what it is supposed to look like.

rocky canyon
#

here you can see that boolean i just made

granite mason
rocky canyon
#

when i select the red object the boolean flicks on and off depending on when i look at it

rocky canyon
#

its up to you

granite mason
#

ok

#

lmao, everything i try to do always ends up a lot more complicated than i expect

rocky canyon
#
        // Create a ray from the camera's position and forward direction
        Ray ray = new Ray(transform.position, transform.forward);
        RaycastHit hit;``` this one would be on the camera itself (using transform.forward and transform.position)
#
        // Get the main camera
        Camera mainCamera = Camera.main;

        // Create a ray from the camera's position and forward direction
        Ray ray = new Ray(mainCamera.transform.position, mainCamera.transform.forward);
        RaycastHit hit;
``` this one could go on any object.. b/c we're grabbing the position and direction from the camera no matter where it is
rocky canyon
#

the last 20% of building a game.. takes 80% of the time

#

80/20 rule

granite mason
#

There are going to be a ton of these game objects (they’re buttons for a control room), would there be a significant difference in computation? We’re going to need a lot of computer power to run calculations in the background

rocky canyon
granite mason
#

Ok

rocky canyon
granite mason
#

Thank you

rocky canyon
#

hers a little video where guy goes thru and does optimzation tests

#

i think he even does SendMessage in this example

granite mason
#

Ok

rocky canyon
#
  • not good practice
  • slow
#

two good reasons for me to avoid it lol

granite mason
#

Ok

rocky canyon
#

Chatgpt just doesnt know 😈

granite mason
#

Humans > ai

rocky canyon
#

for now 😄

rocky canyon
# granite mason Humans > ai

heres a hint.. if you must use AI..
make sure to tell it how you want it done..
when you learn things like send message being slow for example..
point that out to it.. and have it refactor/ come up with better solutions

granite mason
#

Ok

steep rose
#

or use google which is better than AI

granite mason
rocky canyon
steep rose
#

I just don't use AI as the unreliable answers are error prone and are slow, it will probably just steal from stackoverflow anyway 🤷‍♂️

rocky canyon
rocky canyon
vale karma
#

could I get that to work with multiple types of branches and leaves?

rocky canyon
#

why not use VFX graph for that?

#

seems like something it'd be perfect for

#

I've been working on a variety of ways to "grow a plant" on #unity3d, and in this example, I'm experimenting with deforming a mesh to reshape a quad and grow the stem and leaves of a plant.

If you like the content, please consider supporting us on Patreon and joining our Discord to discuss Unity, game building, and code
https://patreon.com/Dan...

▶ Play video
turbid shell
#
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;

public class CharacterController2D : MonoBehaviour
{
    private Rigidbody2D rigidbody2D;
    private Vector2 movementDirection;
    public Animator animator;
    public float moveSpeed;

    private void Awake() {
        rigidbody2D = gameObject.GetComponent<Rigidbody2D>();
    }
    

    private void Update() {
        Vector3 moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
        
        transform.position += moveDirection * moveSpeed * Time.deltaTime;

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

        if(Input.GetKeyDown(KeyCode.Space) && rigidbody2D.linearVelocityY == 0)
        {
            rigidbody2D.AddForce(new Vector2(0, 20), ForceMode2D.Impulse);
        }
    }

    private void FixedUpdate() {
        animator.SetFloat("Horizontal", movementDirection.x);
        animator.SetFloat("Vertical", movementDirection.y);
    }

}```why does it keep playing the idle animation, even when I'm moving?
short hazel
turbid shell
#

so what do i do?

short hazel
#

I guess here:

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

You meant to assign to movementDirection instead of moveDirection?

#

On line 22

turbid shell
#

no way i did that🤦‍♂️ sorry

vale karma
rocky canyon
#

ya, not the easiest mechanic to make

pastel knot
#

When the runtime yells at me about a null reference of a line, does the output specify what exactly it is that is a null reference?

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.AI.NavMesh.CalculatePath (UnityEngine.Vector3 sourcePosition, UnityEngine.Vector3 targetPosition, System.Int32 areaMask, UnityEngine.AI.NavMeshPath path) (at <77c95d4fdf1c463496f3c7ba3c00fe51>:0)

NavMesh.CalculatePath(
    state.Me.transform.position,
    state.Enemy.transform.position,
    NavMesh.AllAreas,
    state.NMPath
);

I can't tell if it's state, Me, Enemy, either of the transforms, etc., I think it's not NavMesh because that's a static class

rocky canyon
#

debug each value before you use or comment em out one at a time

#

should be able to figure out which one is null

pastel knot
#

Is that a no

rocky canyon
#

it wont tell you specifically which one is missing.. just the line it occurs on..

#

to pinpoint the exact cause you should

  • debug the values
  • use error checking / catch the error when it happens
  • use debugger and breakpoints
pastel knot
#

I know that, and that wasn't my question - I was just hoping that the error message would tell me where the null reference is outright

rocky canyon
#
if (state != null && state.Me != null && state.Enemy != null)
{
    NavMesh.CalculatePath(
        state.Me.transform.position,
        state.Enemy.transform.position,
        NavMesh.AllAreas,
        state.NMPath
    );
}
else
{
    Debug.LogError("One or more variables are null!");
}```
rocky canyon
#

i answered as well as gave methods to help you figure it out

#

you could probably turn on Debug mode in the inspector to check which variables are assigned or not.. that'd be the quickest way imo

pastel knot
#

okay fair enough

#

oh wait, you didn't initially say "no"

rocky canyon
#

for example PickedUpObject is a private variable.. but debug mode allows me to quickly glance and see if its assigned the way it should be during runtime

#

without doing anything extra

blissful yew
#

Obviously I know this doesn't work, but is there a generic way to copy the fields over without reflection?

cobalt sigil
#

i just want to make a vr game

rocky canyon
frozen star
#

Anyone know a fix for Visual Studio (not vscode) constantly losing Unity based intellisense?
I have a stock setup, installed unity through the hub, selected to install VS, installed the Unity VS extension, its connected and works the first time I boot it but then stops.
Heres an example: you can see Unity specific namespaces are not colored

timber tide
#

Lot of people reporting that issue lately

frozen star
heavy zodiac
#

i need help on fixing this bug.

timber tide
#

Yeah, linking seems to become removed when the project becomes updated. I've had it doing it to me too, but I'm been using vs code so I've not the need to debug it ;p

rocky canyon
steep rose
#

VScode has been slower than VS for me for some reason

heavy zodiac
#

so for my game i made a "ai" that will follow the playe. but if you go up a level is elevation it jiggles and something. and it clips into corners

rocky canyon
#

even while bugging me about not being signed in..

steep rose
#

I didn't even know you could sign into VScode.

rocky canyon
#

i do need to grab rider while im thinking about it.

#

no harm in having all 3 editors >8)

rocky canyon
steep rose
#

for what?

rocky canyon
#

liscensing i guess

steep rose
#

Seems to work fine without it lmao

rocky canyon
#

it says "sign in ur microsoft account to use c# dev-kit"

#

but its been working fine w/o the sign in

rocky canyon
steep rose
#

it does a miserable job at stopping you if you don't sign in.

rocky canyon
#

i just noticed it..

#

been using it for months now..

steep rose
#

yeah

rocky canyon
#

i think i may have been signed in when i first installed the c# kit

#

but not since

frozen star
#

The reason I decided to use VS, is because I though it was more solid than VSCode... i guess not.
Is Rider... the most solid? (God forbib one of them implements the language server correctly... hehe)

rocky canyon
#

i like VSCode.. b/c with the right extensions it does everything i need it to do..

#

and I can use it when developing for MicroProcessors etc..

#

when it comes to being the most solid.. i think it goes

Rider > VS Studio > VS Code

steep rose
rocky canyon
#

but this is absolutely speculation..

#

and u can use whichever IDE u want

steep rose
#

VSCode imitates a real IDE via extensions

rocky canyon
#

use whichever one you feel works best for you..

#

don't be a bandwagoner

frozen star
#

I need... a program that can read and edit ascii, run a language server to syntax highlight and give intellisense, and save ascii.
Thats it...
😁

#

im joking... yeah ill probs setup vscode now

rocky canyon
#

ignore the PlatformIO and the C/C++ .. as those are extra for embedded chips (programming microcontrollers and stuff)

#

the rest are super useful tho (Codeium can be omitted as well, its just a built in AI-tool)

timber tide
#

Rider is free now btw

rocky canyon
#

for non-commercial purposes..

#

keep that in mind

timber tide
#

Just dont use their macros :p

steep rose
#

I know VSC is more lightweight but right now it has been acting up for me, the base extensions for VSC are Unity Code Snippets, .NET Install Tool, C# and Unity for VScode People say you do not need Code snippets but for me some functions do not show up if I do not have it

#

you don't need codeium or C/C++ or winter is coming theme, I didn't even know you could install themes

nocturne kayak
#

This isn't a specific question, it's moreso to confirm a hunch i'm getting:
I'm not really a programmer, mroe on the 3d modelling\ux part of things
I'm working on what's essentially a Tech Demo, and so far everything seems pretty straightforward programming-wise, i have a rough idea of what subroutines are but never really use them, i can use switch statements and golly gee my stupid ass even learned how to make a subclass the other day, i'm even avoiding the stupid meme stuff like a bunch of if else statements in a row, even having the most basic understanding of programming, i'm getting by so far.
But the thing is, again, i'm working on a tech demo, nothing's really scalable, i doing all the "assets" by hand (what would be repeated\dynamically spawned), right now i'm only working with vectors, the basics of the basics of physics, some UI stuff, raycasting, getting bounds, what i think is fairly low level stuff, so my hunch is:
Am i just working with the overtly simple stuff by chance (and some of you here will know that two weeks ago it wasn't simple for me) or does scripting really gets REAL difficult once your scope is fairly big? like, making ONE thing is real easy but making MULTIPLE things that connect and talk between one another is where the real difficulty's at?

rocky canyon
#

if ur learning i say let it happen organically.. refactor as you go.. when u learn something new/better replace the old stuff..
If it works it works.. don't dwell on optimizations until you need em

steep rose
nocturne kayak
#

that's what i'm doing right now, i know i need to do something, i look up a tangentially-related tutorial, try to take what i need from it and implement, and so far while it hasn't been smooth sailing it's moreso that when i hit the solution it's "oh, it's that simple"

#

I find myself second-guessing my decisions a lot or asking myself "ok but how to the REAL programmers do it?", i don't know if you lose that eventually and if you do, when

rocky canyon
#

ahh, you'll find urself on the other side of the table soon enough
"oh, this is way more complicated than it seems"

spiral narwhal
#
  1. Are we allowed to change the execution order of OnEnable methods of objects, or is that something we should NOT try to do? I want Obj A to always have its OnEnable called before Obj B.
  2. This is because OnEnable has an event subscription, and i want to prevent workarounds like introducing a new event
rocky canyon
nocturne kayak
#

First question i asked here (i think) was trying to implement the transform functionality from the editor at runtime, like, have an axis and drag an object around in that axis, i assumed that was pretty simple

#

(turns out it wasn't)

#

but hey now i know how to raycast and create planes and project points so that was worth a lot of knoweldge

rocky canyon
steep rose
nocturne kayak
#

but when i did get it working i got to "oh damn that wasn't so hard"

rocky canyon
nocturne kayak
blissful yew
#

Hmm, am a bit confused. Am trying to do PlayerInfo loadedInfo = JsonConvert.DeserializeObject<PlayerInfo>(File.ReadAllText($"{_playerDataDirectory}{_slash}{PlayerDataFileName}.json")); where PlayerInfo is a scriptableobject. But I guess you can't do this with scriptableobject classes?

rocky canyon
nocturne kayak
rocky canyon
#

im doing the same project! 😅

blissful yew
#

How are you supposed to deserialize scriptableobject datatypes

#

I guess you have to make a regular class which contains all the data for that scriptableobject...? Blegh, so redundant

timber tide
#

why are you serializing scriptable objects

#

you just need the ID to them

pastel knot
#

How are you supposed to deserialize

jolly imp
#

Fala galera. To começando agora e nunca tive tanto problema na vida como estou tendo agora, que puder por favor me salva

jolly imp
#

more or less

steep rose
#

what is your issue?

rocky canyon
jolly imp
#

Having problems with the scripts and for some reason with "+="

#

I'm not sure if it's the code or something else, I started studying it recently

steep rose
#

are you getting an error?

#

if so please post it using this !code bot

jolly imp
#

Yes

eternal falconBOT
rocky canyon
#

+= work like

thisValue += thatValue;
thisValue = thisValue + thatValue;```
lost dune
#

so i have a texture i need to update very frequently during runtime thing is its a high resolution texture how would one go about doing this, is there not a way to update only part of a texture?

#

instead of the entire thing

jolly imp
#

Can I send images here to make it easier to understand?

slender nymph
#

just share your code the way the bot described

jolly imp
#

I put a code in one of the links but I don't know how to use it.

slender nymph
#

share the link

jolly imp
slender nymph
#

and what is the actual error you are receiving?

jolly imp
#

Assets\Scripts\Enemy\MeleeEnemy.cs(19,9): error CS0019: Operator '+=' cannot be applied to operands of type 'UnityEvent' and 'method group'

slender nymph
#

UnityEvent is not a delegate that you can += to, you call the AddListener method on it

hollow zenith
#

Hey, is there a way to fade out button with text without fading in/out button image + text separately?

rocky canyon
jolly imp
hollow zenith
#

But I need to fade in/out both button image and text, will it not just fade out text alone?

rocky canyon
hollow zenith
#

Thanks!

#

Do those settings change default behaviour of a button?

#

"block raycasts"

rocky canyon
#

ur just changing the alpha..

#

the elements are still there

hollow zenith
#

Yeah I mean the canvas group adds some properties

rocky canyon
#

oh yea ur right

#

i'd just disable em all

#

shouldn't affect anything then

hollow zenith
#

Thanks

#

actually

#

"interactable" might be necessary lol

#

idk

rocky canyon
#

it may be..

#

i was thinking that.

#

i'd just test it both ways

#

see if its a viable solution

hollow zenith
#

alright

rocky canyon
#

if not.. you may need to use an array or list of all the components

#

and fade them all using a forloop or something

#

but the canvas group should be good enough

hollow zenith
#

yeah it seems to be made for it 😄

rocky canyon
#

👍 good luck

hollow zenith
#

Thanks

nocturne kayak
#

Is there a way to check if an animation is finished playing?

#

let's say i have an animator, when X happens, i want Y animation to play and then do something else in the code

jolly imp
#

Hi again, I'm having the following problem

UnassignedReferenceException: The variable groundCheck of IsGroundedChecker has not been assigned.
You probably need to assign the groundCheck variable of the IsGroundedChecker script in the inspector.
UnityEngine.Transform.get_position () (at <7b2a272e51214e2f91bbc4fb4f28eff8>:0)
IsGroundedChecker.IsGrounded () (at Assets/Scripts/Player/IsGroundedChecker.cs:11)
PlayerAnim.Update () (at Assets/Scripts/Player/PlayerAnim.cs:25)

Do you know if the problem is in the code?

sterile radish
#

whats the most optimal system for saving and handling lots and lots of bools deriving from dialogue interactions within my game (for example, the player talks to a road sign and decides to break it, setting a bool true so that next time they play the game the road sign remains broken)?

sterile radish
eternal falconBOT
steep rose
jolly imp
steep rose
#

it says what script it is in

#

and the path to it

#

at Assets/Scripts/Player/IsGroundedChecker.cs:11

jolly imp
#

The problem is then in the script, right?

steep rose
#

is that variable supposed to be assigned in the inspector?

#

also we would need to see the code

#

I'm guessing yes it is some sort of transform, which is public or a serialized private

teal viper
jolly imp
#

It would be assigned to the player to check whether he is on the ground or not

steep rose
#

show us your script

steep rose
#

yes so assign it via inspector

#

drag and drop a transform into it

jolly imp
#

I don't know if I understand, would I have to take the script to the character?

steep rose
#

no, you would drag and drop a transform from an object into the empty field

#

which in your case is groundCheck

#

your script should already be on an object since you are getting an error

jolly imp
#

I think I understand, you will see if you place yourself in another object

steep rose
#

I'm not entirely sure how to respond really, all you would do to fix your error is to do as I said above

nocturne kayak
#

This may have a plethora of answers, but:

#

Is there a "best" way to disable a gameobject after an animation is done playing?

light briar
#

For the life of me I cannot find how to make one.

How do I create a string table collection asset.
All of google just talks about how to make one at runtime which I do not want right now

#

I just needed the localization package facepalm

jaunty bay
#
{
    public PlayerInputActions playerControls;
    public InputActionReference interact;
    private bool isInteracting;

    protected override void OnCollided(GameObject collidedObject)
    {
        base.OnCollided(collidedObject);
        if (isInteracting)
        {
            OnInteract();
            isInteracting = false;
        }

    }
    protected void OnEnable()
    {
        interact.action.performed += PerformInteract;
    }

    protected void OnDisable()
    {
        interact.action.performed -= PerformInteract;
    }

    protected void PerformInteract(InputAction.CallbackContext obj)
    {
        isInteracting = true;
        Debug.Log("isInteracting is " + isInteracting);
    }

    protected virtual void OnInteract()
    {
        Debug.Log("OnInteract() is executed.");
    }
}```
does anyone know why does isInteracted is being logged twice here? the results also showed that OnInteract is executed twice
#

(i have a set of 2 doors btw)

vale karma
#

is there no way to do this in code? XD i am thinking wayyyyy too hard i think

#

It SHOULD be, just a lerp or similar, but its not working correctly because I dont have an object instantiated at the end of the branch, just the movePoint, that moves each time it grows. FSR it just stays put, or does some crazy transforms using localPosition, is there a better way to make the two leaf game objects to travel up the branch?

naive pawn
#

do... what, exactly?

#

i have no idea what you're trying to convey there

vale karma
#

this is what needs to happen, but using BakeMesh() on SkinMeshRenderer is really expensive. is there a simpler way to follow the top vertex of a skinmesh?

#

sorry this is the only vid i have before i started trying different methods

#

just moving the leaves using lerp or something works, but doing something like Vector3.Lerp(transform.position, transform.parent.position + new Vector3(0, skinMesh.bounds.size.y, 0), speed * Time.deltaTime); doesnt do anything

#

transform is the leaf, the parent and skinmesh is the branch

jaunty bay
vale karma
#

hawk tuah XD

#

yo chat i may have fixed it...

#

assigning the vector3.Lerp to something really helps

jaunty bay
vale karma
#

lol im far from it. just balls deep in this atm

#

nah still broke

#

hold on

timber tide
#

I think we went over this before, but why are you using skin renders for this again

vale karma
#

theres a problem with just scaling the parent object

#

child objects reek havock without needing inverse everywhere

#

blendshapes easily give some length and have perfect mesh distribution. but a regular mesh is either blocky, or super hard to alter a script for different lengths, or types of branches

#

using the blendweight, i can time each branch to grow, faking the spot it grows with good timing, but the leaves need to follow the top of the mesh

timber tide
#

I would probably tackle this using splines, and segment it out as it grew to add branches

maiden island
#

quick question guys

vale karma
#

i thought of that! there must be a way

#

theres not alot of documentation

#

mostly paths, but theres probably a hacky way to had multiple splines.

#

it just really sucks, even doing BakeMesh() a fraction of the time is still terrible for the game. i spent months getting to that solution lol

teal viper
eternal falconBOT
vale karma
#

i know dlich, i been here plenty. Ive been at this problem for months. im trying to find the best performant method to move leaves along a blendmesh. if blendmesh is too expensive then im having an error with my lerp function not going along the local transform. u right tho i was complaining

vale karma
#
  transform.position = Vector3.Lerp(transform.position, transform.parent.position + new Vector3(0, skinMesh.bounds.size.y, 0), speed * Time.deltaTime);```
timber tide
#

Do you have CPU skinning enabled? The bounds may not be updated correctly like this

vale karma
#

oo how would i figure that one out?

timber tide
#

Don't have Unity open but it's either on the component itself or in project settings

#

unless there's an instancing bool somewhere

vale karma
#

i thought it was GPU instancing or something

#

i think i have it off, let me double check

timber tide
#

well, there's a bit more to instancing

#

skinning is done via compute shader mostly, but Unity provides CPU skinning for web/mobile builds

#

for matrix calcs, then instancing is for rendering

vale karma
#

yea im in way over my head, and kind of dont know what to research next. I have been dabbling with shaders, but it seems easier to just move the leaf through normal code? i may want to do stuff with it later, and raycast may need to be used on the leaf. I have been researching matrix stuff, but i dont see alot of documentation with how its used in my case

timber tide
#

Like I was saying, splines seem to be the idea if you're trying to some procedural growing. Then sprout some leaves meshes / more splines on the segments would be what I'd do.

vale karma
vale karma
snow warren
#

Hi

#

i am having some trouble with syntax

#
            {
                //key value pair, saving the allskins array as a string to the playfab cloud
                {
                    ("Pfp", Encoding.ASCII.GetString(tex.EncodeToPNG()),
                    ("Width", tex.width.ToString()),
                    ("height", tex.height.ToString())
                     }
            }```
#

how to fix it?

teal viper
snow warren
#

cant do that

#

or else it wont work

teal viper
#

What API errors..?

#

It would result in the same dictionary

snow warren
#

this is the whole result

#
        {
            Data = new Dictionary<string, string>()
            {
                //key value pair, saving the allskins array as a string to the playfab cloud
                    { "Pfp", Encoding.ASCII.GetString(tex.EncodeToPNG())}
            }

        }, OnSetPfpSuccess, OnErrorPfp);```
#

well you are right

#

i can do that

teal viper
#

I feel like you're confusing C# dictionaries with json objects or some other data structure outside of C#...

feral oar
#

fellas, i've got an object that just flies in an arbitrary direction, and i'm trying to check for a collision during its flight but i can't get it to work. i can see that the object does collide with other objects as it passes through them, but the collision method doesn't seem to be detecting anything, as nothing shows up in the console during the collision. the collider is not set as a trigger, and i made sure it has a rigidbody component. not sure what to look into now, so i come here.

    void OnCollisionEnter(Collision collision)
    {
        //EnemyBehavior damageable = collision.gameObject.GetComponent<EnemyBehavior>();
        //if (damageable != null)
        //damageable.TakeDamage(attackDamage);
        GameObject gameObject = collision.gameObject;
        if (gameObject != null)
            Debug.Log("hit");
    }
feral oar
#

seems i may have fixed it by setting the object to be a trigger, and using the method that checks for a collision with a trigger. what do they do differently that's giving me the intended result? i thought they would both check for a collision pretty similarly

north kiln
feral oar
#

that was quite handy, thank you. so it seems i was just using the wrong method for what i was intending to do. a little bit more googling on top of that showed me that a Trigger checks moreso for an overlapping of hitboxes, which is what i was trying to do, where the OnCollision methods check for actual act of two physics objects colliding.

#

do you have any other pages like that? this must have been a common enough topic of confusion for you to have made an article for it

teal viper
marble hemlock
#

are there any particular downsides to creating an empty game object called ScriptManagers, and then shoving every manager type script in it? I kind of just want it to be independent of everything and out of the way, so not attached to a gameobject thats going to be constantly changing

eager spindle
#

honestly up to you

#

some people dont like it

#

i like it

astral falcon
burnt vapor
#

You can initialize a dictionary like this, and add new rows the same way.

vas a = new Dictionary<string, string>()
{
  { "Hello", "World" },
  { "Foo", "Bar" },
};
#

I believe it has to do with some C# trickery and the usage of Add in collections

eternal needle
burnt vapor
#

Weird, LGTBM

#

Unless I am blind

eternal needle
#

oh sorry i was looking at their first message, not the one you replied to

burnt vapor
#

Ah, no problem 😄

normal tapir
#

they dont mention you can use C# variables within visual scripts

#

well idk i can';t figure it out prob doing normal scripting then 🤣

burnt vapor
tulip nimbus
#

Why is line 28 causing this Problem? It works fine with card.OnHover

short hazel
tulip nimbus
#

It compiles, however it is never called due to the errormessage and i cant figure out why

short hazel
timber tide
#

Ya IDE has a bunch of squiggles which you should probably check out too (not totally related to the issue)

short hazel
#

If you're trying to run some code when you stop hovering the card, then you should be storing the currently active card in a field (a variable at the level of the class), so you can keep track of it and execute code on it

tulip nimbus
#

Thank you!

timber tide
#

I'm actually confused what the IDE is trying to tell you here. Looked like it was warning of unused methods, but it's just highlighting a bunch of random stuff for some reasons

short hazel
#

Spellchecker extension I think. Their VS seems to be in German (see code lens indicators above Update), so it might false trigger on these non-German words

timber tide
#

Ohh, yeah that's it good eye

short hazel
#

I have one for VS Code at work, and the color is similar

#

<@&502884371011731486> crypto scam

frosty hound
#

!ban 1305263437672349797 scam

eternal falconBOT
#

dynoSuccess j_biniance_ was banned.

rich maple
#

im having trouble setting shader for entire scene

#
            Camera.main.SetReplacementShader(FlexibleCelShader, "Cel Silhouette");
#

this code doesnt work

#

all the gameobjects disappear

rich adder
rich maple
rich adder
rich maple
#

yes

rich adder
# rich maple yes

and the materials/shaders you want to target have the Cel Silhouette tag in the shader code?

rich maple
#

i downloaded an asset for built in render pipeline

rich adder
#

wouldn't that tag be in the shader code itself ? like the code on page I sent?
I'm not 100 familiar on this function so just going by what the docs say

hasty tundra
#

I could do this kinda inneficiently with a loop, just wondering if theres an easier way:

Say i have a list of 10 game objects, and i want to remove everything after index 6:

Instead of for(...){ List.Remove(List[i]);

Is there a simpe single command i can use like a:
List.Truncate[6]
or
List.DeleteAllAfter[6];

(Example names but u get me)

naive pawn
#

also using a loop yourself is not anymore inefficient; the issue is more so iterating while mutating. you would remove elements 6, 8 then error unless you went through backwards, but it's generally just better to avoid the potential for that mistake and just use the method instead

hasty tundra
#

thx 👍

prime hinge
#

hello

#

i did a method and it does not shown on "on click" filed on the inspector of the button

prime hinge
#

so i have to remove the color parameter

slender nymph
rich adder
eternal falconBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

carmine star
#

hi hi 🫠 im about to ask something really basic, but how can i make a camera move with a button press and stop at the coordinates i want? right now i have this which is fine to controlling it myself, but i dont want to control it myself, i want to press right and it automatically moves right until it stops on the location i want

wintry quarry
#

what location do you want

#

but basically the short answer is something like:

void Update() {
  if (Input.GetKeyDown(Whatever)) {
    targetPosition = something;
  }

  // Move towards the current target position
  transform.position = Vector3.MoveTowards(transform.position, targetPosition, Time.deltaTime * speed;
}```
carmine star
#

it has three positions and i want the camera to move and stop at all three pretty much

wintry quarry
#

Also your whole:

Transform transform; and transform = GetComponent<Transform>(); stuff are completely unecessary/useless

#

you should delete them

wintry quarry
carmine star
#

oh so like, if pressed a button move towards object X and stop?

wintry quarry
#

well I showed the code for how to do the moving and the determining of the target position already

#

all you need to do is fill in the "something" I wrote with code that determines the positions you want

carmine star
#

okay i see , i will try

#

thank u very much

carmine star
#

im probably fucking up smthg rly obvious, before i give any input it moves to location 2, and the when it goes from 3 to 2 it locks there automatically

#

oh right i forgot to delete the useless part

devout flume
#

I'm a bit confused with the indentation of the if blocks ({}) that you made

wintry quarry
#

third why do you have multiple lines with transform.position = MoveTowards

#

that's not correct and not necessary

devout flume
#

It's not even belonging to the if block

wintry quarry
#

Please see my example above

devout flume
#

It's just blocks that serves no purpose & are quite hidden on the left part of the screen as they're not indented

carmine star
#

i thought if i followed the example for every different location it would work ? sorry

wintry quarry
#

you shouldn't have three different target position variables either.

carmine star
#

even though there's three locations?

wintry quarry
#

three stop at variables makes sense

#

ONE target position variable. It tracks the current target position

carmine star
#

oh !

wintry quarry
#

and ONE line that moves towards it at all times

carmine star
#

okay so keep just the stop at's remove the target position 2 and 3

wintry quarry
#

the rest of the code should just be deciding what the current target position is

#

nothing else

carmine star
#

i will try 😅 sorry for sounding like an idiot im very new

devout flume
#

This is your code flow

if (Right) {
  Assign tpos1
}

change transform

if (Right) {
  Assign tpos2
}

change transform

if (Left) {
  Assign tpos3
}

change transform

if (Left) {
  Assign tpos2
}

change transform
mystic dawn
#

Hey there everyone! i'm currently making a upgrade system for my game similar to a typical roguelike level-up system where you get new abilities and or stat buffs

i want the player to be prompted with 3 randomly picked upgrades as buttons for the player to select, some of those upgrades can lock or unlock new upgrades from the pool to have different builds, however i can't find any ressources that could help give me an idea of how to make something like this efficiently!

does anyone have some ressources or tutorials i could check out for a modular system similar to what i want to do?

carmine star
devout flume
#

Yeah brackets are not placed properly imo, and also a I do agree that you may need only 1 target. Another thing is that you are changing the transform quite frequently, which may explain why there are some visual glitches (?), also you don't need to assign transform in start as each class inheriting from MonoBehavior automatically have the variable transform assigned, same goes with gameObject of course, but that's a detail

#

Last but not least, if you want to assign fields in your inspector, but you actually don't want those fields to be publicly accessible from other classes, you may want to transform

public type fieldname;

into

[SerializableField] private type fieldname;
carmine star
#

i will...try my best... when you use change transform in your example is it the same code i have now?

devout flume
#

To me the flow is overly complicated and prompts issues for what you want to do

carmine star
#

oh were you giving an example that it's what i have right now and its bad- or were you telling me to change it to something more like that 😅

carmine star
#

ahhhh . yeah okay i know that much. doesnt mean i know how to make it better

naive pawn
devout flume
#

Yes, when you write

if (a)
  b;
  c;

You are basically writing

if (a) {
  b;
}
c;

The if statement with no bracket will, by convention (and as mentioned it is a behavior from the C language) only conditionalize the very next statement. That's why only the statement b is conditionalized by a.

carmine star
#

so i need the condition of the location first and then the button press?

#

no wait i think i got what you meant

#

i dont want the first thing in brackets cause its part of the condition

#

in theory this should just work and i wouldnt even need targetposition if i just want a marker of present location right

naive pawn
wintry quarry
wintry quarry
#

and again your if statement syntax is all messed up

naive pawn
#

you have if (cond) a; { b; } instead of if (cond) { a; b; }

carmine star
#

oh Oh

#

Im so sorry 😭

naive pawn
#

anyways you probably want to just step back for a sec

#

you're misunderstanding the logic here

#

so step away from the code for a sec

carmine star
#

yeah im probably confusing myself more

naive pawn
#

get an idea of the problem, then of the solution

#

and after that, a code implementation

stuck palm
#

is there a way to get every animator parameter in code?

#

as like an array or list?

stuck palm
#

damn

#

i guess i'd have to set each one manually then

naive pawn
#

so right now what you want is:

  • when a key is pressed, have the camera go to a specific point automatically.
    • depending on the key pressed, have the camera target different points.
  • regardless of whether a key is pressed, the camera should keep moving if it's not already at the target.
    that first one is conditional (on what key is pressed), the last one is not (hence "regardless")
    so a system for that, the "solution" could be something like this
is a key pressed?
  get the target for that key
is the camera at the target?
  if not, goes towards the target
```but really, "going to the target" if we're already on the target would just be not moving, so we could omit the check

is a key pressed?
get the target for that key
camera goes towards the target

||```
let target be some position
if key for targetA is pressed:
  set target to targetA
otherwise, if key for targetB is pressed:
  set target to targetB
move camera towards target
```||in pseudocode, typically indents are used to indicate the scope of statements, ie what the statement controls. but in c#, braces are used, and indents aren't important to the computer
#

@carmine star make sure you understand all that before going to code

carmine star
#

i can understand the logic of what you are mentioning! i just dont know enough code to know what to write to make such things happen, if that makes sense? im in a post graduate and we only had 10 hours of basics and now we have 11 days to deliever a game with no extra classes 🥲
this does help Understand what I want to do, I'm just confused on what I need to write to make it do it

#

i thought that as long as i had something like 'if camera at 1 then when key pressed move towards 2'

steep rose
#

you could probably just use a list

#

I do not know if this works, but it would go something like this

[SerializedField] List<Transform> Spots; 

int T;

Transform CurrentSpot;

void Start(){
   T = 0;
   CurrentSpot = Spots[0];
   transform.position = Spots[T].position;
}


void Update(){
   if(LeftKeyDown && T >= -1 && T <= Spots.count + 1){
       T += 1;
       CurrentSpot = Spots[T];
   }

   if(RightKeyDown && T >= -1 && T <= Spots.count + 1){
       T -= 1;
       CurrentSpot = Spots[T];
   }

   transform.position = Vector3.MoveTowards(transform.position, CurrentSpot.position);
}

I am most likely getting the list wrong, but I hope it is correct.

carmine star
#

i thought that was what i had tried by now but amidst all the confusion i probably messed it up

steep rose
#

you would want to use GetKeyDown as it only calls whatever is in the if statement once while GetKey calls continuously as long as the key is held down

carmine star
#

oh that i can at least understand thank you

#

i will check out the basics again yeah, its impressive how the more i try to fix it the less it does what i want

#

when i recorded that first attempt at least it moved

naive pawn
#

also CurrentSpot is redundant to T, and T would be an int there for an index

#

and it'd need to check that T wouldn't go out of bounds i suppose

steep rose
#

yeah forgot it was an int, and yes I should check if it is out of bounds

lean spade
#

is there a simple way to render a Texture3D to the scene?

steep rose
#

yes I know I am nesting but its not that bad

naive pawn
#

uhhh that's not how you do it

devout flume
#

Assuming LeftKeyDown & RightKeyDown are checks to perform using Input

naive pawn
#

||```cs
[SerializeField] List<Transform> positions;
[SerializeField] float maxSpeed;
int currentPos = 0;

void Update() {
if (positions.Count > 0) {
if (LeftKeyDown && currentPos > 0){
currentPos--;
} else if (RightKeyDown && currentPos < positions.Count - 1){
currentPos++;
}
transform.position = Vector3.MoveTowards(transform.position, positions[currentPos].position, maxSpeed * Time.deltaTime);
}
}

devout flume
#

Why are you doing a list of transform btw? Does Vector3.MoveTowards take Vector3, Transform as params?

naive pawn
#

yknow, inputsystem would make it quite a bit more straightforward

devout flume
#

Answered my question wonderful

naive pawn
#

lmao

devout flume
#

😂

naive pawn
#

the list of transforms is so you can just drag gameobjects in in the inspector

devout flume
#

Ok, so it's just so that you actually place gameobjects around, instead of having to manually enter vectors

naive pawn
#

i'd probably use SmoothDamp though fwiw

vague adder
devout flume
#

There's a time for all ig

naive pawn
#

it's all pretty basic. if you're unfamiliar with it then it might look daunting, yeah, but that's more about the size i think
it's basic, there's just a lot

#

if you're curious, feel free to ask

#

mm i guess it is quite a few basic programming things that a unity beginner might not have had to deal with yet

#

-# god i hate english

steep rose
devout flume
#

Since you're not passing via indexes, if you don't press left nor right, the reference is empty when reading it at the very end of the update method

#

You're not doing a direct access to the list, so either set it to List[0] in Start (assuming it exists), or do list access like @naive pawn did

steep rose
#

yes I forgot to set it to the first transform in the list my bad

#

Also the way I'm checking if the number of T is in bounds would technically work, but checking it the other way would be better

devout flume
#

You're also grabbing the transform from the list by doing list[i].transform, whereas the list is defined as List<Transform>

steep rose
#

yes because I'm assigning CurrentSpot

naive pawn
devout flume
#

Yes but CurrentSpot is of type Transform, and List<Transform>[i] returns an existing transform

#

I'm also confused with int >= Transform (T >= Spots[0])

naive pawn
#

yeah that should be T > 0

#

oh actually, dec your method wouldn't work

#

you would need to inc/dec after the bounds check

devout flume
#

Overally both methods look alike, one uses a tamper variable (CurrentSpot) whereas the other does not

#

Also yes

steep rose
#

I did not know Spots[0] returned a transform

#

I thought it would return an int haha

naive pawn
#

why would subscripting a list of transforms give an int

steep rose
#

I just wrote it off the top of my head, so I must have gotten confused

devout flume
#

Yeah ig that's just it, as said both ideas are the same in the end

naive pawn
#

i mean, how else would you make it

steep rose
#

fixed the mistakes, now it should work

naive pawn
#

other than using inputsystem and having a different flow to begin with

naive pawn
#

you would allow T = -1, Spots.Count, Spots.Count+1

#

(btw typo'd Currentspot in Start and declaration of Spots is still wrong)

#

sorry im treating this like a code review session now lmao

#

if we keep going it's just going to turn into my snippet with a few changes since i based mine off of yours lol

ancient eagle
#

Hello! I'm very very new to coding and I'm trying to make it so that if the "Player" has picked up a "Match" and collided with the "Fire" then a sliderTimer ticking down will reset to it's max value, but I don't know how to go about that.

I tried a couple different ways to create statements using "if () && if () then ()", but I keep getting error messages related to my syntax so I think I am fundamentally missing a step in order to create this system

Here is my timer code:
https://paste.ofcode.org/cEyqV4d34tpJWTayNkSBfd
Here is my match code
https://paste.ofcode.org/3USPeMntG8WpdVTW7mVpS3
Here is my timer code where I tried an if && if then statement
https://paste.ofcode.org/XYXkbDLHV8TLrwJe4K6dtf

I would appreciate any help or guidance and if there's anything else I should clarify in order to make my question more understandable please let me know! :)

languid spire
#

the fundamental step you seem to be missing is understanding C# basics so I suggest you learn them

short hazel
#

"Inside" means between the parentheses

hexed terrace
#

this is the kind of question that should have just been googled -> C# if

snow warren
#

Hi

#

I have an image that takes 50 mbs in memory

#

I wanna compress it to the size of 2 or 3 kbs

#

At the cost of computation