#šŸ’»ā”ƒcode-beginner

1 messages Ā· Page 441 of 1

eternal needle
#

That would indeed be where animation talk happens

strong wren
#

just post it here dawg no one rlly cares

north kiln
#

Don't post it here if it's not related to code.

eternal needle
#

Honestly I'm not sure what your issue is, because the original text doesnt make too much sense.

eternal needle
# silver forge expected result

Did you look at the scale of how you have it in the expected result, because I'd suspect that your original laser is longer on the y axis

eternal needle
#

I'd also try to use like a line renderer here instead where you can define the start and end point

north kiln
eternal needle
# silver forge wdym

Like your object at 1,1,1 scale might not actually fit within a box of 1 unit. For example if you look at a player model, the scale is all 1 yet the model is clearly taller than it is wider

#

Also im just speculating at what the issue could be, since the code made sense logically from what I skimmed through

silver forge
#

]+9-****

#

my cat stepped on my keyboard lol

#

the scale isnt multiplied or added or anything, it is directly set so im not sure how that would matter as much

#

the texture is a 600x600 square

eternal needle
#

Still, did you look at the scale of an expected result and compared that to the actual distance between objects?

#

It doesnt matter if its being set or multiplied, I was saying that the visuals of the object might be larger than 1 unit which is why visually that could happen, though this is still speculation at the issue

silver forge
silver forge
mint remnant
silver forge
steep walrus
#

I am following this youtube tutorial exactly how he writes his code after trying to change some of the variable names and getting an error but I am still having the same issue
https://www.youtube.com/watch?v=k-K2JWoEaS8&list=PLadYLGMfR6Lpvh3xX3a7LXbqJqY_WjIk7&index=6&ab_channel=GameDevHQ&t=4m25s
As in the video I applied MyPlayer to my game object which is a capsule instead of a cube but I know thats not the issue

Welcome to GameDevHQ Online Unity C# Tutorials

FREE BEGINNER TO ADVANCED UNITY C# TUTORIAL COURSES:
Check out our other youtube videos below, or Sign up officially at GameDevHQ.com and join a community of self taught developers who use our educational platform.

In this Unity C# Tutorial Intermediate video we discuss the continuation of cours...

ā–¶ Play video
#

thats the error code i am getting

mint remnant
#

need to assign myProperties to an instance of the class

#

like myProperties = new Properties();

summer stump
#

Don't ever new() a MonoBehaviour

mint remnant
#

opps, was thinking general C# there

summer stump
#

To reference the properties, you are likely supposed to use GetComponent in this case since it is a private variable. That is assuming the the object that has MyPlayer has Properties as well

#

Also, you seem to have a script called MyPlayer as well as Player, both of which have an error on the same line

steep walrus
summer stump
#

HA! In the video he GOT a nullref

steep walrus
summer stump
#

He tries to do new() on Properities, which is very wrong

grave furnace
#

how do i change only my of the rotation?

summer stump
#

I didn't watch more than there. It is a garbage tutorial

summer stump
#

Make a variable for rotation. Change z of that variable, assign the whole thing back.

grave furnace
#

whaat

summer stump
#

Well not gonna help you now after calling me a clown

#

Blocked

grave furnace
summer stump
#

It is a very rude thing to do

grave furnace
grave furnace
#

im sorry not meant to offend you

#

not even near it

summer stump
#

I do hope my instructions made sense and were helpful for you

grave furnace
summer stump
cinder crag
#

https://paste.ofcode.org/g2ajsTekQHhndQCzPxuR7i (WeaponUpgradeBenchManager script)

so im having a small problem , im confused on how i could like set the WeaponName adn WeaponIcon from WeaponUpgrades to the name and icon from the WeaponSO , i know i could do it in the WeaponItem() method but that supposed to only run on Start() method and i want the WeaponName and WeaponIcon to change based on what gun you currently have so it has to be in the Update() method but since my weaponUpgradesArr is an array , im not sure on how to do it icl

ionic zephyr
#

Hi guys, Ive got aproblem in which I have 3 menus that show three different types of objects but the information display in each of them shares some data like the name or the description of the different objects, however, there are some things that they don“t share, for example, weapons have damage quantity but resources don“t, any ideas of what should I do code-wise?

teal viper
edgy vine
#

How would I go about a script where when someone clicks on an object the object follows the mouse on a 2D game?\

sour fulcrum
ionic zephyr
# teal viper What do you have so far?

Ive tryed doing a class with the data all of the menus should have and the child classes for all of them but with their exclussive data, however, when I’m going to display the data, the slots have a method that sends their own data for the components previously mentioned to display

#

However, if the display method is in the parent class, this doesnt include the exclusive data of the different menus so the slot can only access the parent class (because I dont want to create different types of slots for each menu so I can reuse code)

#

I dont know if I am explaining myself well

ionic zephyr
# teal viper What do you have so far?

So the slot has a ā€œDisplay componentā€ that calls the ā€œDisplayInformationonMenuā€ component and passes its information but the component only stores the information of the common data between menus, if I wanted each menu to display its exclusive information I would have to creat a ā€œWeaponsMenuā€ Component, ā€œResourceMenuā€ component. These components are the ones I would have to access but I want to reuse code. Any suggestions on how the arquitecture should be?

teal viper
mint remnant
#

when you call Instantiate on an object, I'm guessing that's when it's Start() gets called and would complete before the next line of code executes after the instantiation

mint remnant
rich adder
teal viper
#

No, Start is called later on in the frame

mint remnant
#

oh Hrmm

teal viper
#

At the start of the next frame to be precise.

rich adder
#

if you want to wait for specific frame like physics, you can do coroutine

#

IEnumerator Start()
yield return new WaitForFixedUpdate()

cinder crag
#

not sure what index to put tho , since i dont use the weaponUpgrades array outside of the WeaponItem() method

#

0 i guess

teal viper
cinder crag
jaunty bay
#

hi, i am planning to set spawn for each room, so that whenever the player enter the room, it'll create the player object accordingly on the spawn.

for example, the player exits through the red door, so when he comes back to that room, he's going to spawn from the red door.

here's how im gonna do it:

1.) create a spawn prefab with ISpawn interface to be landmarks
2.) set the Warper script so that it sets the spawn to the Spawn object's location every time the player interact with it.
3.) update the PlayerMovement script's Start function to set the coordinate to the spawn, so that it will spawn on the Spawn object every time it enters the previous room.

is my approach good?

teal viper
# cinder crag Wdym? I'm confused

I'm not sure how to clarify it any more than that..?
Your icon and name are in stored in one of the elements of the array, right? So you just need to get the data from the correct element.

cinder crag
#

and i use them like this

teal viper
#

So... What is the problem?

teal viper
#

If you have a specific error, then share that.

cinder crag
#

im not having an error , its just the weaponUpgrades field is an array and im using it in the WeaponItem method where i set everything the name , quantity n such and i call the WeaponItem method in start cause if i do it in Update and i have one upgrade in the array , it will continuosly create that upgrade and i dont want that , so thats why i gotta set the WeaponIcon and WeaponName from WeaponUpgrades to the WeaponSO icon and name but since the weaponUpgrades field is an array , im not sure on how to go with this , tried a foreach but clearly didnt work , even a for loop but i realized it was stupid so im a bit stuck icl

cedar bone
#

How do I get the GameObject of a clone of a prefab, cause when I use the following code, it references the prefab and not the clone.

teal viper
mint remnant
#

instead of Object make it a GameObject

cinder crag
teal viper
#

Then what do you do want instead?

#

If you can't explain with just text, then maybe take a screenshot or a video that backups your text explanation

cedar bone
#

even though it has an animator

#

and its not referencing the actual animator

#

its referencing the prefab

#

wait

#

i think ik why

cinder crag
teal viper
teal viper
mint remnant
# cedar bone I tried but I get this error

That's not an error, it's warning. But aside from that I don't know how it ties into the cardVariant. If you want the instantiated GameObject then use a GameObject for hte type, or cast it to one when you go to use it

teal viper
cedar bone
#

and documentation says Instantiate() returns an Object

teal viper
#

Otherwise you'll need to keep track of data index in your actual weapons, so that you can remap the weapon index to the data index.

mint remnant
cinder crag
teal viper
cedar bone
#

and its not giving an error

teal viper
cedar bone
cinder crag
mint remnant
# cedar bone except this

Hover over Instantiate, see what it says it returns and what eah paramater is that it takes in. you are passing it a canvas it seems

teal viper
cedar bone
#

to hover over it?

mint remnant
#

usually called Intellisense

cedar bone
#

how'd you find out im on a mac? 😭

mint remnant
#

I'm preceptive

cedar bone
#

oh wait

#

yeah its pretty obvious

mint remnant
#

Note that even thought the documentation does say Object for the return type and the prefab type, their own examples don't use Object, they use the inherited types of Object, such as GameObject

cedar bone
mint remnant
#

Well it's technically correct, it returns an Object, but if you want to use all the inherited methods you're going to just have to cast it to the type anyways

tawdry ember
#

Anyone in here can help me with some code readign real quick?

mint remnant
tawdry ember
#

!code

eternal falconBOT
tawdry ember
#

'''cs

#

Idk how to use these commands...

rich adder
#

its not a command

#

it says in the message what to do

tawdry ember
#

ITs not a large ammount of code

rich adder
#

just send the class and explain what "isn't working" means in this context

#

what do you expect to Happen vs whats happening

tawdry ember
#

This is what unity is giving me

#

Idk what it means or how to fix it

rich adder
#

yes this is simple syntax error

#

is your IDE underlining it red in the editor?

tawdry ember
#

Ok but i dont see anythign on those lines thats wrong

#

The editor says no errors

rich adder
#

then you should configure that first and foremost

tawdry ember
#

How do I do that?

rich adder
#

check your !ide and click the link

eternal falconBOT
cedar bone
#

but idk why it isnt returning anything

#

also what do u guys reccomend for keeping code tidy

#

cause my project is getting slowely bigger

#

and its getting exponentially harder to manage

rich adder
mint remnant
#

did you put a debuglog after the instantiate call to verify it's not null?

cedar bone
cedar bone
#

its not printing anything

#

i checked if the if statement is running, and it is

#

im guessing if its null, it wont log anything

mint remnant
#

that is not a very productive debug log

#

make the call, assign it to the gameobject then print if the gameobject is null

cedar bone
#

aight

mint remnant
#

though I'm pretty sure it either Instantiates the object or throws an exception

cedar bone
#

this fine?

#

so its not null

#

cuase its not printing anything

mint remnant
#

so put a print above the call, make sure it's even getting called, if not then you have something further up the chain wrong

cedar bone
#

error

mint remnant
#

ok but where is that error from?

#

not this instantiate call, as it doesn't seem it's even getting called

cedar bone
#

this line

rich adder
#

it tells you pretty much that in the error

cedar bone
rich adder
#

well it is supposed to be

cedar bone
rich adder
#

that makes 0 sense

#

cardVarient is the object to clone

#

you can't clone a nothing

cedar bone
#

OOOOH

#

ur right

#

ty ty

#

lemme try it out

mint remnant
#

you cropped out some important details in this image

cedar bone
#

can you not get components from Objects?

#

@mint remnant

vernal bone
cedar bone
#

soz for the @

vernal bone
#

dunno about Object

cedar bone
#

me neither

#

doc is not showing anything about getting the GameObject from an Object

rich adder
#

why are you spawning it as Object

vernal bone
#

what's an Object?

rich adder
#

Object is the root class of all objects

#

Unity has its own version of it

mint remnant
#

Show more of your code like what type is myCardvariant now?

vernal bone
rich adder
#

correct you generally don't need to

cedar bone
#

Instantiate returns an object

rich adder
#

don't use that

mint remnant
#

as suspected, you still haven't changed them to GameObject

vernal bone
# cedar bone

You should use GameObject instead of Object i guess

cedar bone
#

I tried setting myCardVarient to GameObject

#

i got an error

rich adder
#

there is no error

cedar bone
mint remnant
#

well stop reverting to Object

rich adder
#

so if you pass a Object it spawns as Object, etc.

cedar bone
#

thank you guys!

#

it works now

#

and one more quick question, how do I check if an animation has finished playing?

#

I want to make it so the instance gets destroyed after the animation runs

rich adder
#

Animation event

#

or make a timer i suppose. but not as modular

cedar bone
rich adder
#

*function but yeah

cedar bone
#

is this fine?

rich adder
#

no its not

#

read the instructions I sent

mint remnant
#

There's that use of Object again...

rich adder
#

well thats normal for Animation Event

#

but they just added it wrong

mint remnant
#

oh, he crops out details of the image

rich adder
#

"Object" is basically the target here

cedar bone
rich adder
#

but if script is already on same object as animator then it will give you dropdow

rich adder
#

you have to select the object with the animator

#

while the animation window is open

#

then select the animation event there

cedar bone
rich adder
#

yes

cedar bone
#

how do I select it with the animator?

#

my function btw

#

@rich adder

rich adder
cedar bone
#

my animation window is open

rich adder
#

ok select the object with the Animator on it

#

then click the Animation Event in animation window

cedar bone
rich adder
# cedar bone

you still didn't select the gameobject with the animator

#

having the animator window is not the same as select the object with the animator component

cedar bone
#

you mean select it with the animator? or select the object which has the animator?

rich adder
#

hold up . give me a second. Ill show you Ig

cedar bone
#

thing is the animation and the script run from the animation are on two different GameObjects

#

but im gonna move the function

cedar bone
#

so ill try it again

#

Thank you! It works now!

rich adder
queen adder
#

i need help with some really bad lag

#

its been making me want to stop game development altogether because i cannot find the cause

#

please someone help me, the project isnt very big i started a week ago

vernal bone
#

don't ask to ask, just ask damnit

queen adder
#

what

rich adder
#

we cannot tell anything without details..

queen adder
#

ohhh

vernal bone
#

on one can help you if you don't show where the problem lies

#

and what the problem is

queen adder
#

okay anyways, ill be playing the game and if it runs for about a minute it seems randomly it starts lagging VERY BADLY to the point where its not playable

#

nothing is happening though

summer stump
queen adder
#

Yoo

summer stump
queen adder
#

Guys can you help me with some stuf

#

how do i

queen adder
#

liek in entercollision

queen adder
rich adder
queen adder
#

like in Oncollisionenter( collision collisioder)

summer stump
queen adder
queen adder
rich adder
summer stump
rich adder
summer stump
queen adder
#

this is whats causing the lag. which is it though?

half egret
#

Click on the large spiked portion

summer stump
#

Google a youtube guide on how to use the profiler and follow it

queen adder
rich adder
eternal falconBOT
summer stump
#

The hierarchy view is usually far better than the timeline view

rich adder
# queen adder

lookup tutorials on profiler. You have to switch from TImeline to Hierarchy view

summer stump
queen adder
#

so like this i assume

summer stump
#

Yes

queen adder
#

so EditorLoop is making it lag

summer stump
#

No

#

Look up a guide on youtube and follow it

rich adder
#

could be , 276 ms is a lot

summer stump
#

The issue will be in playerloop

summer stump
half egret
#

Yeah that's an insane amount of editor overhead,

summer stump
#

What is going on there

half egret
#

Maybe he has some extension or something

#

That's really killing performance

rich adder
#

to know for sure, make a build and if its no lag you know 100% its the editor

queen adder
summer stump
queen adder
#

in-game

summer stump
#

Do not make scripts named the same thing as unity classes or structs
Rename your class

queen adder
#

ok

half egret
#

Make the built game and connect the profiler to that

static bay
#

Move the frame it's checking around a bit. If it's Editor Loop for everything then ya it's the editor.

queen adder
rich adder
#

something is wrong with your ide

summer stump
#

!ide

eternal falconBOT
queen adder
summer stump
#

I still see collision.cs at the top too

half egret
#

If it's still happening in the built game then it's not the editor

#

Connect the profiler in the built game

queen adder
#

how?

half egret
#

You can autoconnect the profiler

queen adder
#

okay

#

are there hotkeys to show it or is it automatic

static bay
summer stump
half egret
queen adder
summer stump
half egret
#

Check hierarchy but odd that it's vsync...

rich adder
# queen adder what

as mentioned , it doesn't seem your IDE is properly detecting unity classes

queen adder
#

i did all of those

summer stump
queen adder
queen adder
half egret
#

Did you click on the spiked portion

north kiln
# queen adder

Add the GPU profiler module and see if it confirms that

queen adder
summer stump
queen adder
rich adder
north kiln
#

Looks like an additional spelling plugin

#

and not a lack of configuration

queen adder
#

@half egret

#

waitonswapchain is causing the lag

rich adder
#

ah yes cSpell, whatever that is

half egret
#

It’s waiting for the GPU to finish rendering the frame according to QualitySettings.maxQueuedFrames

#

Turn on your GPU profiler

#

Like vertx suggested

queen adder
#

where

#

is that

half egret
#

Scroll down in your profiler

#

Oh wait enabling it is..

north kiln
queen adder
summer stump
north kiln
#

I presume that extension can just add words to the dictionary. Either way that's not the issue

#

the issue is declaring Collision again manually, and everything else is a distraction

rich adder
#

yea actually you are right.
assumed they did remove the Collision class but apparently did not

queen adder
summer stump
half egret
summer stump
#

Ah, no. Last ss shows that is not the case
Ah, they DID. It is lowercase now

@queen adder rename the class to something COMPLETELY different than collision.
Set the parameter type back to Collision (capital c)

queen adder
#

how enable?? i pressed it

north kiln
# queen adder

You definitely did more recording after adding the module?

queen adder
#

what??

half egret
#

Did you play the game some more after enabling

north kiln
#

Record more profiling data now

queen adder
#

do i need to rebuild

north kiln
#

You need to record more profiling data if you haven't done so after enabling the module

static bay
#

aka let the game play a bit more

queen adder
#

i dont understand😭

summer stump
queen adder
#

i pressed play

#

yes

#

but not in editor

summer stump
#

Ok, look at the profiler again

queen adder
#

i did it in build

#

what

summer stump
#

Before the edit I misread your typo

queen adder
#

ah okay

#

i am very confused, do i play in the build? or the editor?

north kiln
#

are you profiling a build?

half egret
#

Ideally the build, as that's where you'll get data without the editor overhead.

queen adder
#

okay i just open the build and it will start recording, correct?

half egret
#

You'll have to make sure autoconnect profiler is ticked

rich adder
#

iirc you need to build as Dev Build too

half egret
#

Yeah it dooesn't let you autoconnect unless dev build is active

queen adder
#

its not recording

#

yeah its a development build

summer stump
#

I was focusing on crazygaming, did the build have the lag?

queen adder
#

yes

#

everything lag

north kiln
#

To do GPU profiling in a build you have to disable Graphics Jobs in the Player Settings

queen adder
#

so whats the fix

#

ive read both discussions

#

and didnt see a clear answer

half egret
#

Do your GPU profiling first, your case might be simpler.

queen adder
#

okay since im actually stupid im very sorry but can someone give me a step by step guide on how to get it to record because it isnt anymore and i dont know what idid

half egret
#

Listen to what vertx said, go to your player settings (Bottom left of build settings), disable graphics jobs under "Other settings"

#

Make sure auto-connect profiling is enabled

#

Then build and run

queen adder
#

rebuild, and test?

#

great

#

thanks

rain hull
#

is it better to use transform translate or addforce for the player controller?

static bay
queen adder
cold ruin
#

so while learning how script draggable item, i'm kind of struggles with the item keep snapping back to the start after i dragged it to where i wanted to, does anyone know what am i doing wrong ? (I also did exactly what the turtorial asked me to)

rain hull
summer stump
half egret
# queen adder

Click the GPU usage->select the spiked region, check hierarchy

queen adder
half egret
#

Are you using GPU instancing?

#

And/or assigning static objects appropriately

queen adder
#

i didnt bake lighting

#

so i wouldnt have make any objects static

half egret
#

If you don't want them to be static, make sure materials that are shared by multiple objects of the same type have GPU instancing enabled

half egret
#

Not sure, can't say for sure. What we do know is that your mesh rendering is taking an obscene amount of time

teal viper
#

For starters, that spike doesn't seem to be regular, so you should be thinking of what in the game causes it.

queen adder
#

there is nothing going on in game!! its a box!!

teal viper
#

Most of the time it seems to be 60 fps

half egret
#

Wait, is this just the Unity box?

queen adder
#

wait

half egret
#

How many materials are on this box

queen adder
#

this is the box

#

its several cube gameobjects

#

not a flipped normal cube

teal viper
#

You should check what's going on when this happens:

#

Comparing the profiler data with the regular frames might be useful too

queen adder
half egret
#

Click the material for your box

queen adder
#

i didnt mean to seem angry but i feel like a idiot

half egret
#

Enable GPU instancing

#

Ideally

#

Since they're static

#

All those objects should be static

teal viper
queen adder
#

nope

#

lags regardless

teal viper
#

Or this repeats at certain intervals?

half egret
#

If you mark all the cubes as static, that would be better

#

See if that helps

#

You're currently doing 2 draw calls PER cube

#

When you can make it 2 draw calls for ALL cubes

teal viper
north kiln
#

Also I'd look at the very first frame it goes wild in the profiler

queen adder
half egret
queen adder
half egret
#

follow dlich's and vertx's instructions if that didn't help

queen adder
#

still lags

half egret
#

Next thing I'm predicting is that it's something to do with the player model..

#

Which will be shown in the video, I hope.

queen adder
#

soo laggy cant even open profiler

half egret
#

Okay so there ARE other things in the scene

queen adder
#

yeah like a bunch of other cubes

half egret
#

Do you spawn anything via script?

queen adder
#

nope

mint remnant
#

does it have to be individual cubes are can you make a mesh and just texture it to look like many cubes?

half egret
#

Are ALL the cubes marked as static?

queen adder
#

yep

half egret
#

Click on the stats button in your game-view, and record your batches.

#

See if your batches rise when the lag starts

teal viper
#
  1. I'd make sure there are no suspicious messages in the console at the time the issue happens.
  2. It's either something happening in the game(some code running, spawning more object for example)
  3. Or it could be that something else is tanking your GPU at that timing.
queen adder
#

not rising

#

but you can see fps

teal viper
#

To test the last theory, check the task manager to see what's using the GPU the most.

queen adder
#

i only see cpu on task manager

half egret
#

In the performance tab?

queen adder
#

mb

#

i got it

teal viper
#

It should be in the main tab as well. Where the processes are.

half egret
#

I don't think task manager groups by GPU usage in the main processes tab, default at least.

teal viper
#

It does for me. Is it not enabled by default?šŸ¤”

half egret
#

Not for me, odd!

#

Had to right click->add GPU

queen adder
#

its just not lagging now

#

what happened

#

task manager cancelled out the lag

half egret
#

Did you save the scene or anything

queen adder
#

nope

half egret
#

Maybe the static stuff took a bit to... take hold

#

Close task manager and see if we have schrodingers GPU bottleneck šŸ˜›

teal viper
#

Maybe someone's using your GPU for crypto farming šŸ˜›

queen adder
#

i dont download programs, and i make my own png for textures

#

so i dont think id have a virus

teal viper
#

Well, either way, it seems to not be something unity specific

queen adder
#

no more taskmanager, and no more lag

mint remnant
#

attach a special note to the game: must have task manager running while playing

queen adder
#

no idea what happened

half egret
#

Build the game and see if it lags

queen adder
#

okay

#

this is how im feeling right now since the lag dissapeared

#

until its built...

half egret
#

Getting a 400ms decrease in CPU/GPU time is any optimizers wet dream

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

public class NewBehaviourScript : MonoBehaviour
{
    void OnCollisionEnter(Collision collisionInfo){

        Debug.Log(collisionInfo.name);
    }

}
queen adder
half egret
#

Check task manager now

#

Check usage

#

With the lag active

#

Sort by GPU usage in processes

#

And if nothing stands out, also check your GPU under performance

#

See if your VRAM or whatever is bottlenecking

queen adder
half egret
#

And in the processes tab?

queen adder
#

i donthave gpu

half egret
#

Right click the status bar->click GPU

#

You'll be able to sort by GPU usage

queen adder
#

me when game development

half egret
#

Odd, honestly..
If you close out the built game and try to play it again in editor, is the lag still gone?

teal viper
#

Is that showing that much usage when it's not lagging?

queen adder
#

thats while lagging

queen adder
teal viper
queen adder
#

this is also while lagging but this time in editor

#

this is while not lagging (in editor)

rich adder
teal viper
#

The GPU usage definitely goes up during the lag

queen adder
#

i dont know how to see disk

rich adder
languid spire
# queen adder What

you have made a class called Collision which is causing the problem, rename or remove it

teal viper
queen adder
#

its writing 77.4 MB/s

teal viper
#

Yes, I see that. The question is what is that for? Assuming that's during play mode.

queen adder
#

we have been trying to find that out for 2 hours

teal viper
#

The writing to disk??

queen adder
#

what is that

#

no i dont have a disk port in my laptop

teal viper
#

You're not reading correctly.

half egret
#

I was thinking that the increase of writing to disk could be the log files, but 78MB/s of log files is pretty crazy

queen adder
#

okay i give up gamedev guys!! thanks for the help!!!

half egret
#

Profiler data maybe, if it's active?

teal viper
#

If you can share the project I can have a look on my pc, but I bet it's something with your environment(potentially malware).

half egret
teal viper
half egret
#

But what exactly it's waiting on is not very clear

queen adder
#

@rich adder thank you

#

i fixed it

teal viper
half egret
teal viper
#

Maybe they're running an LLM in the background or something. Hahah

#

Or it's cryptocurrency mining malware.

half egret
#

Did you make this project entirely yourself? @queen adder šŸ˜…

queen adder
#

yes

half egret
#

Here's a quick and dirty method if you want

#

Run the game

#

When it starts lagging, disable batches of cubes in your hierarchy

#

The render.mesh/shadows taking so much GPU time points to some mesh issue but it's hard to tell without the project in somebody's hands

#

I do have to hop off now unfortunately, I hope dlich can help with testing the project out!

#

@teal viper i would definitely run it sandboxed first šŸ˜

#

Oh did you enable GPU instancing on your cube materials?

#

(And also do they all use the same material?)

#

wait oh wait

#

I just realized those cubes aren't prefabs

queen adder
#

im going to bed

half egret
#

If you have the time... you can try prefab-ifying one cube object and re-using that. Make sure that GPU instancing is enabled for the material on the object you use for the cube. Since the static flag didn't work, I have my doubts this will, but it's worth a shot.

queen adder
#

ill resolve this in the morning

half egret
#

Sleep is the best solver.

#

Also.. in case I forget.. try disabling all lighting to see if that helps at all

topaz mortar
#
if (this is not Equippable)
{
    return;
}```
Equippable is a class, does this work as I expect it should?
rich adder
#

is it a regular class ?

#

dont think unity MB likes is not

topaz mortar
rich adder
#

nvm should be fine i think

#

i was thinking of is not null sorry

#

is not should work afaik

topaz mortar
#

could just do if (!(this is Equippable)) but is not is more readable imo

ruby python
#

Mornin' all,

Would someone mind having a quick look at my raycast code please? I really don't understand where I'm going wrong.

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

I'm using LayerMasks to differentiate between different 'clickable' objects in my scene, but for some reason when debugging, the raycast returns true no matter what object I point at.

It all seems to be set up correctly etc. But I'm obviously missing something. šŸ˜•

topaz mortar
#

it is, just never used it before so wanted to make sure I'm not doing something stupid

rich adder
#

oh yeah is is good to go along with the not

#

You can store result variable to is

 void A(A a)
  {
      if(a is B b)
      {
          b.Hello();
      }
  }```
topaz mortar
languid spire
rich adder
languid spire
#

fair, I tend to use as if I want the cast and is if I don't

rich adder
#

amazing revelation tbh

pallid nymph
languid spire
#

is is faster because it's a simple type check without a cast attempt

pallid nymph
#

I mean, not only not, but it's slower 😮

#

it does maybe depend on the circumstances, but yeah, you can check some benchmarks in the link above, was not what I expected

languid spire
#

if you do

if (a is B b)

you are actually doing an is and an as so will be slower than either is or as seperately

pallid nymph
#

that should be pretty much the same as as with a different syntax

#

and the benchmark linked above confirms it

#

but if (a is B)
is actually twice as SLOW 😮

#

(specifically tested with an object a = "something" and if (a is string)

#

ah, no, I read their code now, it's just stupid šŸ˜„

#

so, yeah, I'd assume is is pretty similar in performance to as but of course it does make sense to use is if you only need the check and not the value

languid spire
#

think about it, as has to do all the work that is does AND perform the cast, so there is no way it cannot be slower

prime cobalt
#

Is there any reason why this wouldn't work and teleport the player? The respawn message is displayed but the player doesn't teleport.

pallid nymph
#

sure, sure, I just think the is part is the heavy part of that... but in any case it doesn't matter, because different use-cases

languid spire
pallid nymph
languid spire
prime cobalt
pallid nymph
languid spire
#

yes, you cannot have ChartacterController and Rigidbody on the same object

prime cobalt
#

Oh that did it SuiFacepalm had no idea. thanks

languid spire
pallid nymph
#

of course it's not, come on, they're not stupid

languid spire
#

bet

pallid nymph
#

yep

languid spire
#

rember this is relatively new syntax, it was bolted onto existing code

pallid nymph
#

you can see the IL code in the link I posted above... it's not exactly the same for is B b and as B, but it's almost the same and the isinst check happens once

cedar bone
#

When i try setting the values of variables in the inpsector that references other GameObjects, it keep saying Type mismatch (this applies to Canvas and CardAnim). However when I do the same to an instance of a prefab, it works fine.
Prefab:

#

Instance:

languid spire
#

you cannot assign scene objects to a prefab

cedar bone
#

so I have to do it through script?

languid spire
#

yes

glacial pivot
#

Hey I'm making an example mod for game "ultrakill", and this is my first mod
Is there a way I can turn "else if(Input.GetKey(KeyCode.something))" into a switch statement?

rich adder
glacial pivot
#

idk, is there a way to make it work?

rich adder
#

also applying deltaTime to addForce is wrong

#

moving rigidbody in update is even more

#

you should worry about fixing that if anything..

languid spire
long jacinth
#
if(isFacingRight)
        {   
            gameObject.transform.eulerAngles = new Vector3(0, gameObject.transform.eulerAngles.y + 180, 0);
            shootBullet.direction = 1f;
        }
        else
        {
            gameObject.transform.eulerAngles = new Vector3(0, gameObject.transform.eulerAngles.y - 180, 0);
            shootBullet.direction = -1f;
        }```
#

tryinig to make my character flip wtih this simple script

#

i want to flip the character so everything else flips with him

languid spire
long jacinth
#

oh

#

it looks like i might never learn

#

rotations

#

they are so complex

languid spire
#

don't be surprised, most people never do

long jacinth
#

u mean quiters?

languid spire
#

no, I mean Quaternion math is very complex to understand

long jacinth
#

i will understand it at some point

languid spire
#

I wish you luck, I still struggle at times

long jacinth
#

or maybe not

vernal bone
long jacinth
#

also my player is always rotating like a tornado

languid spire
#

tbh transform.eulerAngles should just not have a get accessor

long jacinth
#

it works perfectly now thanks guys

#

i mean it kinda does i still need to set up the camera and stuff

#

how do i stop the camera from rotating with the player

languid spire
long jacinth
#

cinemachine

languid spire
long jacinth
#

oh

long jacinth
#

also my bullet is trigger

#

how do i make it so when it collides whith a wall it breaks

#

its a trigger bec it passes through the player so if it wasnt a trigger the player would be pushed and the bullet would get destroyed

willow scroll
long jacinth
willow scroll
long jacinth
#

i want it to only pass through player

willow scroll
#

Should the collision still happen?

languid spire
long jacinth
#

how?

languid spire
long jacinth
#

i always look there

#

wat theres a search function?

#

website not unity

winter tinsel
#

first person camera works

#

controls, kinda work

#

how do i get the camera and controls to work in sync

#

w makes the character go where hes looking i mean

#

move code on character

#

mouselook

queen adder
#

yo uhh guys, what public variable should i make so that i can drag a script into it, like

Public OtherSCript Script;

Script.variable_from_that_script = edit_to_My_choice

#

something like this if u get my point

#

Public class, scriptable object or what

languid spire
#

if you have

public class MyClass { }

then you would use

public MyClass myClass;

to expose a reference to the inspector

winter tinsel
mossy crest
#

any reason not to put CurrentHealth and _uiDocument in the same block? and if so which is better between the class block and Start()

strong wren
languid spire
#

what would be the point of having _uidocment only visible to the Start method ?

mossy crest
#

I see, so variables are only usable in the {} block they're in

languid spire
#

yes, it's called scope

mossy crest
#

This is what it says on the tutorial but they might fix it later

languid spire
#

absolutely pointless

strong wren
#

Well it depends on what they end up doing with it

mossy crest
#

Ok, it looks like the current implementation is just to show the health that's at the very start of the game

ruby python
#

Braindead moment, if I have an object that usually stays inactive in the hierarchy, which method do I use to run a script once every time it's activated?

languid spire
#

OnEnable

ruby python
#

Thankies.

crude summit
#

For a 2d side scroller, imagine you have coins to collect. Player plays the same level with some changes to obstacles when they finish the level(Level restarts). On level one player will have 10 coins to collect, on two 5. The spawn position for level 1 will be determined using where we placed some empty objects at, same goes for level 2 as well. But if player only collects 3 out of the 10 coins on level one, the non collected 7 coins should remain in their position when level 2 loads(Level 2 will also load coins for level 2, so 7+5= 12). How do I store these values?

languid spire
crude summit
#

atwhatcost Im not actually a programmer, not sure what that means

languid spire
crude summit
#

Ohh okay, got it

#

So If there are non collected coins in scene DDOL, right?

languid spire
#

exactly, they can chose to do it themselves by subscribing to the OnBeforeSceneLoad event

mossy crest
#

aren't singletons bad practise?

#

or is it the only way to make a UI controller

quartz nimbus
#

Hi. so I have these two lines of code but every time I trigger respawn by pressing R every thing works smoothly than it just freezes this is after the player is killed/turned into a null (followed a tutorial they said it was easier to turn it into a null if you have a better way please indulge me) but when ever I press respawn before the player gets killed the everything works fine and no freezing

sceneOne


public class RespawnPlayer : MonoBehaviour

{

public void Update()

{

if (Input.GetKeyDown(KeyCode.R))

{

SceneManager.LoadScene(3);

Debug.Log("Player has become null and is now respawning");

}

}

}

and

Respawn Scene


public class SceneRespawn : MonoBehaviour

{

void Start()

{

SceneManager.LoadScene(2);

}

}

tranquil barn
#

it might be a dumb question but im following a tutorial and i have a question why does it show error when i try to define the horizontalinput value where i defined the float variable ?

tranquil barn
ripe shard
languid spire
tranquil barn
tranquil barn
languid spire
tranquil barn
languid spire
#

exactly

tranquil barn
#

ahhhhhh okayyy thanks for the help :))

#

im very new to coding and unity dont mind my dumb self šŸ˜…

languid spire
tranquil barn
mossy crest
#

Why use this instead of just accessing the UIController directly?

#

It's used to access the static methods and stuff

#

All the fields and stuff are private by default so

languid spire
mossy crest
#

why not just make everything static though?

#

if its a singleton class

languid spire
#

because if everything was static you would not be able to set values in the inspector

mossy crest
#

oh ok

#

line 63 is UIController.Instance.SetHealthValue(Health / (float)MaxHealth);

#

uicontroller exists, instance exists, SetHealthValue exists, Health exists, MaxHealth exists

languid spire
#

so instance is null

mossy crest
languid spire
#

yes, and does this code run BEFORE the other code you posted?

mossy crest
#

yes, that's awake, so it runs before the game starts

languid spire
#

not quite true

mossy crest
#

the ChangeHealth is used during the game, when you walk into damage

#

nevermind!

#

unity visual bug!

#

the compiler error disappeared when i clicked play

languid spire
#

what compiler error? what you posted is a runtime error

mossy crest
#

oh

#

didn't know that

languid spire
#

I know, you need to stop jumping to incorrect conclusions

mossy crest
#

previously it said "fix all compiler errors" so i assumed the red mark meant compiler errors

languid spire
#

Nope, you cannot enter play mode if you have compiler errors, if you can enter playmode any errors are runtime errors

mossy crest
#

yeah, i knew something was up as soon as it let me run

slate badge
#

how do i make a static public variable also be shown within unity's editor?

#

Where it can be shown here

mossy crest
eternal needle
mossy crest
#

which makes sense, because each script component is an instance of the class, not the class itself

eager spindle
#

you can make a scriptable object and a manager that has a static reference to this scriptable object

eager spindle
mossy crest
#

yeah that would make more sense

slate badge
eager spindle
#

then add stuff to the singleton

slate badge
#

Sorry to ask but what is a singleton

eager spindle
#

only one object can be made for that class

#

e.g. I have a DialogueManager script, and only one object will have this script

slate badge
#

How do i reference an object's component (like rigidbody or transform) without drag and dropping?

eager spindle
#

GetComponent

slate badge
#

I knew I forgot something so obvious

#

Thanks\

eager spindle
#

a quick beginners guide to GetComponent

Call this on a GameObject to get a specified component

Animator animator = GetComponent<Animator>();

Don't call GetComponent every frame.

 void Update() {
  GetComponent<Animator>().Play("Walk"); // this is TERRIBLE practice!
}

To get the component of another GameObject(this example uses OnTriggerEnter):

void OnTriggerEnter(Collider other) {
  Animator animator = other.gameObject.GetComponent<Animator>();
}

Additionally, be careful of null references. Not every object has the component you're looking for so be diligent

slate badge
#

Thanks

willow scroll
eager spindle
#

yea I just wanted to demonstrate that its better to call it on a gameobject

willow scroll
#

It's not better to call it on a GameObject

#

It's just longer

slate badge
#

"The name 'playerref' does not exist in the current context", this error popped up when I tried to use the component referred

eager spindle
#

we dont know what your code looks like

slate badge
#

oh sorry

eager spindle
#

it means PlayerRef isnt a variable

#

did you declare it earlier?

slate badge
#

The top code is within Update() btw

willow scroll
#

The variable should be created outside of the method, and only changed there

slate badge
#

So do I add the playerref declaration into the update method?

willow scroll
#

According to what you're trying to achieve

eager spindle
#

declare playerref in your class(outside ontriggerenter), then set playerref in ontriggerenter

willow scroll
#

Not sure how you're going to reference other this way

strong wren
#

OnTrigger is only appropriate if you are planning to enter a trigger collider of the object.

slate badge
#

Why can this object only accept the player's transform component when it is in the hierachy but not when it's in the assets folder? I just want that everytime this object spawns, this variable is already connected

cosmic dagger
languid spire
slender nymph
cosmic dagger
queen adder
#
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.Rendering;

public class NewBehaviourScript : MonoBehaviour
{

    public Transform position;
    public Vector3 Spawnpoint;
    void OnCollisionEnter(Collision collisionInfo){

        Debug.Log("you just hit the" + collisionInfo.collider.name);
            
        
        if (collisionInfo.collider.tag == "Obstacle"){
            FindObjectOfType<CubeMovement.Collider_check = true;

            FindObjectOfType<GamemanagerScript>().EndGame();
        }

    }

}
slate badge
#

Can anyon explain what do I replace MoveToTargetExample with? Is it transform?

#

A bit confused

languid spire
#

that is not even C# @queen adder

winter tinsel
#

trying to make a first person controller, it works fine, goes in the direction that i look at but i cant go diagonally?

#

is this a wrong way of doing it?

#

wait i figured it out

cosmic dagger
winter tinsel
#

im setting it to only that direction

winter tinsel
languid spire
#

+= instead of =

winter tinsel
#

right

#

so it adds up

languid spire
#

that is what + generally does, yes

winter tinsel
#

my brain stopped working for a split secdon

wooden aurora
#

hey guys can i have a question?

winter tinsel
#

im done so yea

languid spire
#

sure, how many fives make 5

winter tinsel
#

the number

#

or the quantity

languid spire
cosmic dagger
winter tinsel
languid spire
winter tinsel
#

i have 2 questions but ill let ultimate fusion go first

cosmic dagger
wooden aurora
cosmic dagger
winter tinsel
winter tinsel
#

theres no public before rigidbody2d

#

does that have anything to do with it?

languid spire
eternal falconBOT
cosmic dagger
#

Uh oh, is the bot broken?

#

There it is!

cosmic dagger
winter tinsel
wooden aurora
cosmic dagger
languid spire
wooden aurora
cosmic dagger
languid spire
#

configure your ide first before asking more questions

eternal falconBOT
winter tinsel
# wooden aurora this one?

yes, do either public or private, public just means its visible and configurable in the inspector in unity

wooden aurora
#

the purple one

cosmic dagger
cosmic dagger
cosmic dagger
wooden aurora
#

umm i used to use vs code to coding the blue one and when i write those codes in the blue one its work šŸ’€

#

I have alr done all of that

wooden aurora
#

Its finally work

#

Tysm

cosmic dagger
#

No prob, I'll send the invoice later . . .

chilly cedar
#

Hello šŸ‘‹

Can someone help me understand why my cube keeps going up seemingly infinitely after W is pressed? Thank you šŸ™‚

rare basin
#

because you keep adding the force

summer stump
chilly cedar
summer stump
chilly cedar
#

Nevermind I fixed it šŸ™‚

chilly cedar
hushed hinge
summer stump
# hushed hinge https://stackoverflow.com/questions/78804205/how-can-i-make-the-counter-from-the...

You should reword that to be more clear. It is almost gibberish.

As you have been told, use generic names.
"How can I increase my counter and have it persist across scenes and runtime"
Absolutely no reason to show the counter (where you write 0/15) or use the word muon or anything like that

Also, they will likely give you the same answers we have. Use singletons in ddol and file writing like playerprefs (they may recommend json or binary instead though)

rocky canyon
#

ohhh no..

summer stump
#

If you think we can be harsh, well just prepare yourself for stack overflow....

rocky canyon
#

stack overflow will be savage

fair steeple
#

Hey, is there an advantage over using an abstract state machines vs. an enum one?

rocky canyon
#

scaleability

willow scroll
summer stump
rocky canyon
#

i mean what could possibly still being going on?

#

yesterday u had ur triggers working & you had a singleton instance to call

#

just add DDOL to the singleton gameobjct

#

and you'll have ur score thru all scenes

willow scroll
#

@hushed hinge If it's about making the counter persistent, I remember explaining you this more than 2 months ago #1237752727564582952 message
Time flies

rocky canyon
pallid nymph
polar acorn
pallid nymph
#

no need to be negative, guys šŸ˜›

rocky canyon
polar acorn
fair steeple
rocky canyon
#

yes, if its small use enums

willow scroll
pallid nymph
#

my personal rule is "use the simplest thing that handles this week's requirements" šŸ˜„ (yes, I did just come up with it, but it gives the main idea)

rocky canyon
#

refactor tommorrow "f*ck you past self"

summer stump
rocky canyon
#

i just realized the extent of it

pallid nymph
#

refactoring is much easier than planning for unknown futures... I've tried that a few times and it ends up in sadness šŸ˜„

rocky canyon
#

eventually ur hindsight grows

rocky canyon
#

at this point i would recommend starting from scratch

#

its only a trigger and a score counter..

#

hell i'll make a unitypackage and send it to him ** Let me Know if You Want a Unity Package Linedol **

willow scroll
queen adder
rocky canyon
rocky canyon
#

i always have issues w/ state changed OnStateEnter.. OnStateExit type of stuf

willow scroll
rocky canyon
#

enums are easier for me.. b/c i can just put that stuff in teh switch statement before starting any loops or anything

summer stump
rocky canyon
#

clean

willow scroll
#

Well, I still feel like it's too much, because of how little code each class has

public class PlayerBuildDraw : PlayerBuildToggleBase
{
    public PlayerBuildDraw(PlayerBuilder target, EventKeyBindings selectBindigns)
        : base(target, selectBindigns) { }

    public PlayerBuildDraw(PlayerBuilder target, EventKeyBindings selectBindigns,
EventKeyBindings modifyBindings)
        : base(target, selectBindigns, modifyBindings) { }

    public override PlayerBuildType GetBuildType() => PlayerBuildType.Draw;

    public override bool ExecuteModify() => 
        Player.TryAddTileWorld(Target.WorldMousePosition);
}
rocky canyon
summer stump
hollow forum
#

is there a way of checking if a collider is triggered

rocky canyon
#

OnTriggerEnter?

swift canopy
#

i am trying to make a system for keeping track of rpg-style character stats, as well as making a character creator/editor with a GUI. I am feeling seriously bogged down and stuck. would anyone with more experience be willing to look at what I have and critique, give me advice and point me in the right direction?

#

im sure youll tell me im doing it all wrong and what i have is a complete mess

#

which would be fine

sacred loom
#

what does you use canvas or ui toolkit ?

swift canopy
#

canvas

sacred loom
#

did you need this in world or only in screen. for your creator you can use ui toolkit

swift canopy
#

well i was envisioning a character "editor" which is also just what you use in-game when just viewing character status or leveling up whatever

#

is ui toolkit easier?

#

im sure my approach is wrong somehow but its driving me nuts

#

im still getting a feel for how much should be handled by Unity vs C#

cosmic quail
swift canopy
#

i am not

#

are you saying it would be more familiar to a web dev

sacred loom
cosmic quail
#

but i'd just use the default ui

sacred loom
#

you dont must be a web developer

#

its like wpf or other xaml frameworks

hollow forum
#

how can i fix the variables in unity not updating when i change the values of the variables in the script

languid spire
summer stump
swift elbow
willow scroll
hushed hinge
spiral glen
#

how would I go about changing the texture2D of a gameobject via script?

mint remnant
#

make a public array of textures for inspector, populate the textures into the inspector then in code where you set the texture, pass in the index of hte array that you want it to use

fair steeple
#

Hey, is there a reason why none of these variables show up in the inspector?

#

It compiles and runs the states just fine

languid spire
#

probably because MovingState and IdleState are not serializable

fair steeple
#

Can I make them serializable?

languid spire
#

sure, add the attribute

summer stump
fair steeple
#

Like that?